Skip to content

Commit 3e2dfe9

Browse files
committed
Update RuboCop
1 parent 264d87c commit 3e2dfe9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+722
-623
lines changed

.rubocop.yml

+131-40
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
11
AllCops:
2-
Includes:
3-
- 'Gemfile'
4-
- 'Thorfile'
5-
- 'thor.gemspec'
6-
7-
# Avoid long parameter lists
8-
ParameterLists:
9-
Max: 5
2+
TargetRubyVersion: 2.2
3+
4+
Metrics/ParameterLists:
5+
Max: 6
106
CountKeywordArgs: true
117

12-
MethodLength:
8+
Metrics/MethodLength:
9+
Max: 25
1310
CountComments: false
11+
12+
Metrics/AbcSize:
13+
Enabled: false
14+
15+
Metrics/ClassLength:
16+
Max: 300
17+
18+
Metrics/ModuleLength:
19+
Max: 300
20+
21+
Metrics/BlockLength:
22+
Max: 30
23+
24+
Metrics/CyclomaticComplexity:
25+
Max: 12
26+
27+
Metrics/PerceivedComplexity:
1428
Max: 15
1529

16-
# Avoid more than `Max` levels of nesting.
1730
BlockNesting:
1831
Max: 4
1932

20-
# Align with the style guide.
21-
CollectionMethods:
22-
PreferredMethods:
23-
collect: 'map'
24-
inject: 'reduce'
25-
find: 'detect'
26-
find_all: 'select'
27-
28-
# Do not force public/protected/private keyword to be indented at the same
29-
# level as the def keyword. My personal preference is to outdent these keywords
30-
# because I think when scanning code it makes it easier to identify the
31-
# sections of code and visually separate them. When the keyword is at the same
32-
# level I think it sort of blends in with the def keywords and makes it harder
33-
# to scan the code and see where the sections are.
34-
AccessModifierIndentation:
33+
Metrics/LineLength:
3534
Enabled: false
3635

37-
# Limit line length
38-
LineLength:
36+
AccessModifierIndentation:
3937
Enabled: false
4038

41-
# Disable documentation checking until a class needs to be documented once
4239
Documentation:
4340
Enabled: false
4441

@@ -77,17 +74,111 @@ CaseIndentation:
7774
DoubleNegation:
7875
Enabled: false
7976

80-
PercentLiteralDelimiters:
81-
PreferredDelimiters:
82-
'%': ()
83-
'%i': ()
84-
'%q': ()
85-
'%Q': ()
86-
'%r': '{}'
87-
'%s': ()
88-
'%w': '[]'
89-
'%W': '[]'
90-
'%x': ()
91-
9277
StringLiterals:
9378
EnforcedStyle: double_quotes
79+
80+
Style/SymbolLiteral:
81+
Enabled: false
82+
83+
Lint/AssignmentInCondition:
84+
Exclude:
85+
- 'lib/thor/line_editor/readline.rb'
86+
- 'lib/thor/parser/arguments.rb'
87+
88+
Lint/EndAlignment:
89+
Exclude:
90+
- 'lib/thor/actions.rb'
91+
- 'lib/thor/parser/option.rb'
92+
93+
Lint/Eval:
94+
Exclude:
95+
- 'spec/helper.rb'
96+
97+
Lint/HandleExceptions:
98+
Exclude:
99+
- 'lib/thor/line_editor/readline.rb'
100+
101+
Lint/PercentStringArray:
102+
Exclude:
103+
- 'spec/parser/options_spec.rb'
104+
105+
Lint/UnusedMethodArgument:
106+
Exclude:
107+
- 'lib/thor.rb'
108+
- 'lib/thor/base.rb'
109+
- 'lib/thor/command.rb'
110+
- 'lib/thor/parser/arguments.rb'
111+
- 'lib/thor/shell/html.rb'
112+
- 'spec/actions/empty_directory_spec.rb'
113+
114+
Style/AccessorMethodName:
115+
Exclude:
116+
- 'lib/thor/line_editor/basic.rb'
117+
118+
Style/Alias:
119+
Enabled: false
120+
121+
Style/ClassAndModuleChildren:
122+
Exclude:
123+
- 'lib/thor/group.rb'
124+
- 'lib/thor/runner.rb'
125+
- 'spec/shell_spec.rb'
126+
- 'spec/util_spec.rb'
127+
128+
Style/ClassVars:
129+
Exclude:
130+
- 'lib/thor/util.rb'
131+
- 'spec/util_spec.rb'
132+
133+
Style/ConstantName:
134+
Exclude:
135+
- 'spec/line_editor_spec.rb'
136+
137+
Style/GlobalVars:
138+
Exclude:
139+
- 'bin/thor'
140+
- 'lib/thor.rb'
141+
- 'lib/thor/base.rb'
142+
- 'lib/thor/shell/basic.rb'
143+
- 'spec/helper.rb'
144+
- 'spec/rake_compat_spec.rb'
145+
- 'spec/register_spec.rb'
146+
- 'spec/thor_spec.rb'
147+
148+
Style/IndentArray:
149+
EnforcedStyle: consistent
150+
151+
Style/MethodMissing:
152+
Exclude:
153+
- 'lib/thor/core_ext/hash_with_indifferent_access.rb'
154+
- 'lib/thor/runner.rb'
155+
156+
Style/MutableConstant:
157+
Enabled: false
158+
159+
Style/NumericLiteralPrefix:
160+
Exclude:
161+
- 'spec/actions/file_manipulation_spec.rb'
162+
163+
Style/NumericPredicate:
164+
Exclude:
165+
- 'spec/**/*'
166+
- 'lib/thor/parser/option.rb'
167+
168+
Style/PerlBackrefs:
169+
Exclude:
170+
- 'lib/thor/actions/empty_directory.rb'
171+
- 'lib/thor/core_ext/hash_with_indifferent_access.rb'
172+
- 'lib/thor/parser/arguments.rb'
173+
- 'lib/thor/parser/options.rb'
174+
175+
Style/TrailingUnderscoreVariable:
176+
Exclude:
177+
- 'lib/thor/group.rb'
178+
179+
Style/TrailingWhitespace:
180+
Exclude:
181+
- 'spec/shell/basic_spec.rb'
182+
183+
Style/AlignParameters:
184+
Enabled: false

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
before_install:
2+
- gem install bundler
13
bundler_args: --without development
24
language: ruby
35
rvm:

Gemfile

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gem 'rake', '< 11'
4-
gem 'rdoc', '~> 4.2.2' # This is to support Ruby 1.8 and 1.9
3+
gem "rake", "< 11"
4+
gem "rdoc", "~> 4.2.2" # This is to support Ruby 1.8 and 1.9
55

66
group :development do
7-
gem 'guard-rspec'
8-
gem 'pry'
7+
gem "guard-rspec"
8+
gem "pry"
99
platforms :ruby_21 do
10-
gem 'pry-byebug'
10+
gem "pry-byebug"
1111
end
1212
platforms :ruby_19, :ruby_20 do
13-
gem 'pry-debugger'
14-
gem 'pry-stack_explorer'
13+
gem "pry-debugger"
14+
gem "pry-stack_explorer"
1515
end
1616
end
1717

1818
group :test do
19-
gem 'addressable', '~> 2.3.6', :platforms => [:ruby_18]
20-
gem 'childlabor'
21-
gem 'coveralls', '>= 0.5.7'
22-
gem 'json', '< 2' # This is to support Ruby 1.8 and 1.9
23-
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
24-
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
25-
gem 'rspec', '>= 3'
26-
gem 'rspec-mocks', '>= 3'
27-
gem 'rubocop', '>= 0.19', :platforms => [:ruby_20, :ruby_21]
28-
gem 'simplecov', '>= 0.9'
29-
gem 'term-ansicolor', '~> 1.3.2' # This is to support Ruby 1.8 and 1.9
30-
gem 'tins', '< 1.7' # This is to support Ruby 1.8 and 1.9
31-
gem 'webmock', '>= 1.20', '< 2' # This is to support Ruby 1.8 and 1.9.2
19+
gem "addressable", "~> 2.3.6", :platforms => [:ruby_18]
20+
gem "childlabor"
21+
gem "coveralls", ">= 0.5.7"
22+
gem "json", "< 2" # This is to support Ruby 1.8 and 1.9
23+
gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
24+
gem "rest-client", "~> 1.6.0", :platforms => [:jruby, :ruby_18]
25+
gem "rspec", ">= 3"
26+
gem "rspec-mocks", ">= 3"
27+
gem "rubocop", ">= 0.19", :platforms => [:ruby_20, :ruby_21, :ruby_22, :ruby_23]
28+
gem "simplecov", ">= 0.9"
29+
gem "term-ansicolor", "~> 1.3.2" # This is to support Ruby 1.8 and 1.9
30+
gem "tins", "< 1.7" # This is to support Ruby 1.8 and 1.9
31+
gem "webmock", ">= 1.20", "< 2" # This is to support Ruby 1.8 and 1.9.2
3232
end
3333

3434
gemspec

lib/thor.rb

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
require "set"
22
require "thor/base"
33

4-
class Thor # rubocop:disable ClassLength
4+
class Thor
55
class << self
66
# Allows for custom "Command" package naming.
77
#
88
# === Parameters
99
# name<String>
1010
# options<Hash>
1111
#
12-
def package_name(name, options = {})
12+
def package_name(name, _ = {})
1313
@package_name = name.nil? || name == "" ? nil : name
1414
end
1515

@@ -57,7 +57,9 @@ def desc(usage, description, options = {})
5757
command.usage = usage if usage
5858
command.description = description if description
5959
else
60-
@usage, @desc, @hide = usage, description, options[:hide] || false
60+
@usage = usage
61+
@desc = description
62+
@hide = options[:hide] || false
6163
end
6264
end
6365

@@ -235,10 +237,8 @@ def subcommand(subcommand, subcommand_class)
235237

236238
define_method(subcommand) do |*args|
237239
args, opts = Thor::Arguments.split(args)
238-
invoke_args = [args, opts, { :invoked_via_subcommand => true, :class_options => options }]
239-
if opts.delete('--help') or opts.delete("-h")
240-
invoke_args.unshift 'help'
241-
end
240+
invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}]
241+
invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h")
242242
invoke subcommand_class, *invoke_args
243243
end
244244
end
@@ -327,6 +327,7 @@ def stop_on_unknown_option?(command) #:nodoc:
327327
end
328328

329329
protected
330+
330331
def stop_on_unknown_option #:nodoc:
331332
@stop_on_unknown_option ||= Set.new
332333
end
@@ -352,12 +353,14 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
352353
opts.clear
353354
end
354355
else
355-
args, opts = given_args, nil
356+
args = given_args
357+
opts = nil
356358
command = dynamic_command_class.new(meth)
357359
end
358360

359361
opts = given_opts || opts || []
360-
config.merge!(:current_command => command, :command_options => command.options)
362+
config[:current_command] = command
363+
config[:command_options] = command.options
361364

362365
instance = new(args, opts, config)
363366
yield instance if block_given?
@@ -397,8 +400,8 @@ def create_command(meth) #:nodoc:
397400
elsif all_commands[meth] || meth == "method_missing"
398401
true
399402
else
400-
puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " <<
401-
"Call desc if you want this method to be available as command or declare it inside a " <<
403+
puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \
404+
"Call desc if you want this method to be available as command or declare it inside a " \
402405
"no_commands{} block. Invoked from #{caller[1].inspect}."
403406
false
404407
end
@@ -413,11 +416,7 @@ def initialize_added #:nodoc:
413416
# Retrieve the command name from given args.
414417
def retrieve_command_name(args) #:nodoc:
415418
meth = args.first.to_s unless args.empty?
416-
if meth && (map[meth] || meth !~ /^\-/)
417-
args.shift
418-
else
419-
nil
420-
end
419+
args.shift if meth && (map[meth] || meth !~ /^\-/)
421420
end
422421
alias_method :retrieve_task_name, :retrieve_command_name
423422

@@ -429,20 +428,20 @@ def retrieve_command_name(args) #:nodoc:
429428
# +normalize_command_name+ also converts names like +animal-prison+
430429
# into +animal_prison+.
431430
def normalize_command_name(meth) #:nodoc:
432-
return default_command.to_s.gsub("-", "_") unless meth
431+
return default_command.to_s.tr("-", "_") unless meth
433432

434433
possibilities = find_command_possibilities(meth)
435-
if possibilities.size > 1
436-
fail AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]"
437-
elsif possibilities.size < 1
438-
meth = meth || default_command
434+
raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]" if possibilities.size > 1
435+
436+
if possibilities.empty?
437+
meth ||= default_command
439438
elsif map[meth]
440439
meth = map[meth]
441440
else
442441
meth = possibilities.first
443442
end
444443

445-
meth.to_s.gsub("-", "_") # treat foo-bar as foo_bar
444+
meth.to_s.tr("-", "_") # treat foo-bar as foo_bar
446445
end
447446
alias_method :normalize_task_name, :normalize_command_name
448447

0 commit comments

Comments
 (0)