Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support to Ruby 2.6 #821

Merged
merged 5 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: lint_gems.rb
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: ['2.0', 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, head]
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', 'head']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 3 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.0
TargetRubyVersion: 2.6
DisabledByDefault: true
SuggestExtensions: false
Exclude:
- spec/sandbox/**/*
- spec/fixtures/**/*
- vendor/bundle/**/**

# Enforce Ruby 1.8-compatible hash syntax
Style/HashSyntax:
EnforcedStyle: hash_rockets
EnforcedStyle: ruby19

# No spaces inside hash literals
Layout/SpaceInsideHashLiteralBraces:
Expand Down
51 changes: 0 additions & 51 deletions .rubocop_todo.yml

This file was deleted.

7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ gem "rake"
group :development do
gem "pry"
gem "pry-byebug"
gem "rubocop", "~> 1.30"
end

group :test do
gem "childlabor"
gem 'coveralls_reborn', '~> 0.23.1', :require => false if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
gem "coveralls_reborn", "~> 0.23.1", require: false
gem "rspec", ">= 3.2"
gem "rspec-mocks", ">= 3"
gem "simplecov", ">= 0.13"
gem "webmock", '~> 3.14.0' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.4.0")
gem "webmock", '>= 3.14' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.0")
gem "rexml", '3.2.4' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1.0")
gem "webmock", ">= 3.14"
end

gemspec
14 changes: 7 additions & 7 deletions lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def command_help(shell, command_name)

if command.long_description
shell.say "Description:"
shell.print_wrapped(command.long_description, :indent => 2)
shell.print_wrapped(command.long_description, indent: 2)
else
shell.say command.description
end
Expand All @@ -283,7 +283,7 @@ def help(shell, subcommand = false)
shell.say "Commands:"
end

shell.print_table(list, :indent => 2, :truncate => true)
shell.print_table(list, indent: 2, truncate: true)
shell.say
class_options_help(shell)
print_exclusive_options(shell)
Expand Down Expand Up @@ -318,7 +318,7 @@ def subcommand(subcommand, subcommand_class)

define_method(subcommand) do |*args|
args, opts = Thor::Arguments.split(args)
invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}]
invoke_args = [args, opts, {invoked_via_subcommand: true, class_options: options}]
invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
invoke subcommand_class, *invoke_args
end
Expand Down Expand Up @@ -459,7 +459,7 @@ def print_exclusive_options(shell, command = nil) # :nodoc:
opts += class_exclusive_option_names
unless opts.empty?
shell.say "Exclusive Options:"
shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, :indent => 2 )
shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 )
shell.say
end
end
Expand All @@ -470,7 +470,7 @@ def print_at_least_one_required_options(shell, command = nil) # :nodoc:
opts += class_at_least_one_option_names
unless opts.empty?
shell.say "Required At Least One:"
shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, :indent => 2 )
shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 )
shell.say
end
end
Expand Down Expand Up @@ -539,8 +539,8 @@ def create_command(meth) #:nodoc:

if @usage && @desc
base_class = @hide ? Thor::HiddenCommand : Thor::Command
relations = {:exclusive_option_names => method_exclusive_option_names,
:at_least_one_option_names => method_at_least_one_option_names}
relations = {exclusive_option_names: method_exclusive_option_names,
at_least_one_option_names: method_at_least_one_option_names}
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options, relations)
@usage, @desc, @long_desc, @method_options, @hide = nil
@method_exclusive_option_names, @method_at_least_one_option_names = nil
Expand Down
29 changes: 14 additions & 15 deletions lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def source_paths_for_search
# Add runtime options that help actions execution.
#
def add_runtime_options!
class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
:desc => "Overwrite files that already exist"
class_option :force, type: :boolean, aliases: "-f", group: :runtime,
desc: "Overwrite files that already exist"

class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
:desc => "Run but do not make any changes"
class_option :pretend, type: :boolean, aliases: "-p", group: :runtime,
desc: "Run but do not make any changes"

class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
:desc => "Suppress status output"
class_option :quiet, type: :boolean, aliases: "-q", group: :runtime,
desc: "Suppress status output"

class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
:desc => "Skip files that already exist"
class_option :skip, type: :boolean, aliases: "-s", group: :runtime,
desc: "Skip files that already exist"
end
end

Expand Down Expand Up @@ -113,9 +113,9 @@ def destination_root=(root)
#
def relative_to_original_destination_root(path, remove_dot = true)
root = @destination_stack[0]
if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ''].include?(path[root.size..root.size])
if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ""].include?(path[root.size..root.size])
path = path.dup
path[0...root.size] = '.'
path[0...root.size] = "."
remove_dot ? (path[2..-1] || "") : path
else
path
Expand Down Expand Up @@ -223,8 +223,7 @@ def apply(path, config = {})

contents = if is_uri
require "open-uri"
# for ruby 2.1-2.4
URI.send(:open, path, "Accept" => "application/x-thor-template", &:read)
URI.open(path, "Accept" => "application/x-thor-template", &:read)
else
File.open(path, &:read)
end
Expand Down Expand Up @@ -285,7 +284,7 @@ def run(command, config = {})
#
def run_ruby_script(command, config = {})
return unless behavior == :invoke
run command, config.merge(:with => Thor::Util.ruby_command)
run command, config.merge(with: Thor::Util.ruby_command)
end

# Run a thor command. A hash of options can be given and it's converted to
Expand Down Expand Up @@ -316,15 +315,15 @@ def thor(command, *args)
args.push Thor::Options.to_switches(config)
command = args.join(" ").strip

run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
run command, with: :thor, verbose: verbose, pretend: pretend, capture: capture
end

protected

# Allow current root to be shared between invocations.
#
def _shared_configuration #:nodoc:
super.merge!(:destination_root => destination_root)
super.merge!(destination_root: destination_root)
end

def _cleanup_options_and_set(options, key) #:nodoc:
Expand Down
2 changes: 1 addition & 1 deletion lib/thor/actions/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Directory < EmptyDirectory #:nodoc:
def initialize(base, source, destination = nil, config = {}, &block)
@source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first)
@block = block
super(base, destination, {:recursive => true}.merge(config))
super(base, destination, {recursive: true}.merge(config))
end

def invoke!
Expand Down
2 changes: 1 addition & 1 deletion lib/thor/actions/empty_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EmptyDirectory #:nodoc:
#
def initialize(base, destination, config = {})
@base = base
@config = {:verbose => true}.merge(config)
@config = {verbose: true}.merge(config)
self.destination = destination
end

Expand Down
7 changes: 1 addition & 6 deletions lib/thor/actions/file_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ def template(source, *args, &block)
context = config.delete(:context) || instance_eval("binding")

create_file destination, nil, config do
match = ERB.version.match(/(\d+\.\d+\.\d+)/)
capturable_erb = if match && match[1] >= "2.2.0" # Ruby 2.6+
CapturableERB.new(::File.binread(source), :trim_mode => "-", :eoutvar => "@output_buffer")
else
CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer")
end
capturable_erb = CapturableERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer")
content = capturable_erb.tap do |erb|
erb.filename = source
end.result(context)
Expand Down
4 changes: 2 additions & 2 deletions lib/thor/actions/inject_into_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Actions
# gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
# end
#
WARNINGS = { unchanged_no_flag: 'File unchanged! Either the supplied flag value not found or the content has already been inserted!' }
WARNINGS = {unchanged_no_flag: "File unchanged! Either the supplied flag value not found or the content has already been inserted!"}

def insert_into_file(destination, *args, &block)
data = block_given? ? block : args.shift
Expand All @@ -37,7 +37,7 @@ class InjectIntoFile < EmptyDirectory #:nodoc:
attr_reader :replacement, :flag, :behavior

def initialize(base, destination, data, config)
super(base, destination, {:verbose => true}.merge(config))
super(base, destination, {verbose: true}.merge(config))

@behavior, @flag = if @config.key?(:after)
[:after, @config.delete(:after)]
Expand Down
10 changes: 5 additions & 5 deletions lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Thor

class << self
def deprecation_warning(message) #:nodoc:
unless ENV['THOR_SILENCE_DEPRECATION']
unless ENV["THOR_SILENCE_DEPRECATION"]
warn "Deprecation warning: #{message}\n" +
'You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.'
"You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION."
end
end
end
Expand Down Expand Up @@ -79,7 +79,7 @@ def initialize(args = [], local_options = {}, config = {})
# Give a relation of options.
# After parsing, Thor::Options check whether right relations are kept
relations = if current_command.nil?
{:exclusive_option_names => [], :at_least_one_option_names => []}
{exclusive_option_names: [], at_least_one_option_names: []}
else
current_command.options_relation
end
Expand Down Expand Up @@ -664,7 +664,7 @@ def print_options(shell, options, group_name = nil)
end

shell.say(group_name ? "#{group_name} options:" : "Options:")
shell.print_table(list, :indent => 2)
shell.print_table(list, indent: 2)
shell.say ""
end

Expand All @@ -681,7 +681,7 @@ def is_thor_reserved_word?(word, type) #:nodoc:
# options<Hash>:: Described in both class_option and method_option.
# scope<Hash>:: Options hash that is being built up
def build_option(name, options, scope) #:nodoc:
scope[name] = Thor::Option.new(name, {:check_default_type => check_default_type}.merge!(options))
scope[name] = Thor::Option.new(name, {check_default_type: check_default_type}.merge!(options))
end

# Receives a hash of options, parse them and add to the scope. This is a
Expand Down
35 changes: 12 additions & 23 deletions lib/thor/error.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
class Thor
Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName
# In order to support versions of Ruby that don't have keyword
# arguments, we need our own spell checker class that doesn't take key
# words. Even though this code wouldn't be hit because of the check
# above, it's still necessary because the interpreter would otherwise be
# unable to parse the file.
class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc:
def initialize(dictionary)
@dictionary = dictionary
end
end

Module.new do
def to_s
super + DidYouMean.formatter.message_for(corrections)
end

def corrections
@corrections ||= self.class.const_get(:SpellChecker).new(self).corrections
end
end
end
Module.new do
def to_s
super + DidYouMean.formatter.message_for(corrections)
end

def corrections
@corrections ||= self.class.const_get(:SpellChecker).new(self).corrections
end
end
end

# Thor::Error is raised when it's caused by wrong usage of thor classes. Those
# errors have their backtrace suppressed and are nicely shown to the user.
Expand All @@ -45,7 +34,7 @@ def corrections
end

def spell_checker
NoKwargSpellChecker.new(error.all_commands)
DidYouMean::SpellChecker.new(dictionary: error.all_commands)
end
end

Expand Down Expand Up @@ -87,7 +76,7 @@ def corrections
end

def spell_checker
@spell_checker ||= NoKwargSpellChecker.new(error.switches)
@spell_checker ||= DidYouMean::SpellChecker.new(dictionary: error.switches)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/thor/invocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def invoke_with_padding(*args)

# Configuration values that are shared between invocations.
def _shared_configuration #:nodoc:
{:invocations => @_invocations}
{invocations: @_invocations}
end

# This method simply retrieves the class and command to be invoked.
Expand Down
Loading