Skip to content

Commit

Permalink
Update RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 26, 2016
1 parent 264d87c commit 3e2dfe9
Show file tree
Hide file tree
Showing 59 changed files with 722 additions and 623 deletions.
171 changes: 131 additions & 40 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
AllCops:
Includes:
- 'Gemfile'
- 'Thorfile'
- 'thor.gemspec'

# Avoid long parameter lists
ParameterLists:
Max: 5
TargetRubyVersion: 2.2

Metrics/ParameterLists:
Max: 6
CountKeywordArgs: true

MethodLength:
Metrics/MethodLength:
Max: 25
CountComments: false

Metrics/AbcSize:
Enabled: false

Metrics/ClassLength:
Max: 300

Metrics/ModuleLength:
Max: 300

Metrics/BlockLength:
Max: 30

Metrics/CyclomaticComplexity:
Max: 12

Metrics/PerceivedComplexity:
Max: 15

# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 4

# Align with the style guide.
CollectionMethods:
PreferredMethods:
collect: 'map'
inject: 'reduce'
find: 'detect'
find_all: 'select'

# Do not force public/protected/private keyword to be indented at the same
# level as the def keyword. My personal preference is to outdent these keywords
# because I think when scanning code it makes it easier to identify the
# sections of code and visually separate them. When the keyword is at the same
# level I think it sort of blends in with the def keywords and makes it harder
# to scan the code and see where the sections are.
AccessModifierIndentation:
Metrics/LineLength:
Enabled: false

# Limit line length
LineLength:
AccessModifierIndentation:
Enabled: false

# Disable documentation checking until a class needs to be documented once
Documentation:
Enabled: false

Expand Down Expand Up @@ -77,17 +74,111 @@ CaseIndentation:
DoubleNegation:
Enabled: false

PercentLiteralDelimiters:
PreferredDelimiters:
'%': ()
'%i': ()
'%q': ()
'%Q': ()
'%r': '{}'
'%s': ()
'%w': '[]'
'%W': '[]'
'%x': ()

StringLiterals:
EnforcedStyle: double_quotes

Style/SymbolLiteral:
Enabled: false

Lint/AssignmentInCondition:
Exclude:
- 'lib/thor/line_editor/readline.rb'
- 'lib/thor/parser/arguments.rb'

Lint/EndAlignment:
Exclude:
- 'lib/thor/actions.rb'
- 'lib/thor/parser/option.rb'

Lint/Eval:
Exclude:
- 'spec/helper.rb'

Lint/HandleExceptions:
Exclude:
- 'lib/thor/line_editor/readline.rb'

Lint/PercentStringArray:
Exclude:
- 'spec/parser/options_spec.rb'

Lint/UnusedMethodArgument:
Exclude:
- 'lib/thor.rb'
- 'lib/thor/base.rb'
- 'lib/thor/command.rb'
- 'lib/thor/parser/arguments.rb'
- 'lib/thor/shell/html.rb'
- 'spec/actions/empty_directory_spec.rb'

Style/AccessorMethodName:
Exclude:
- 'lib/thor/line_editor/basic.rb'

Style/Alias:
Enabled: false

Style/ClassAndModuleChildren:
Exclude:
- 'lib/thor/group.rb'
- 'lib/thor/runner.rb'
- 'spec/shell_spec.rb'
- 'spec/util_spec.rb'

Style/ClassVars:
Exclude:
- 'lib/thor/util.rb'
- 'spec/util_spec.rb'

Style/ConstantName:
Exclude:
- 'spec/line_editor_spec.rb'

Style/GlobalVars:
Exclude:
- 'bin/thor'
- 'lib/thor.rb'
- 'lib/thor/base.rb'
- 'lib/thor/shell/basic.rb'
- 'spec/helper.rb'
- 'spec/rake_compat_spec.rb'
- 'spec/register_spec.rb'
- 'spec/thor_spec.rb'

Style/IndentArray:
EnforcedStyle: consistent

Style/MethodMissing:
Exclude:
- 'lib/thor/core_ext/hash_with_indifferent_access.rb'
- 'lib/thor/runner.rb'

Style/MutableConstant:
Enabled: false

Style/NumericLiteralPrefix:
Exclude:
- 'spec/actions/file_manipulation_spec.rb'

Style/NumericPredicate:
Exclude:
- 'spec/**/*'
- 'lib/thor/parser/option.rb'

Style/PerlBackrefs:
Exclude:
- 'lib/thor/actions/empty_directory.rb'
- 'lib/thor/core_ext/hash_with_indifferent_access.rb'
- 'lib/thor/parser/arguments.rb'
- 'lib/thor/parser/options.rb'

Style/TrailingUnderscoreVariable:
Exclude:
- 'lib/thor/group.rb'

Style/TrailingWhitespace:
Exclude:
- 'spec/shell/basic_spec.rb'

Style/AlignParameters:
Enabled: false
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
before_install:
- gem install bundler
bundler_args: --without development
language: ruby
rvm:
Expand Down
42 changes: 21 additions & 21 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
source 'https://rubygems.org'
source "https://rubygems.org"

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

group :development do
gem 'guard-rspec'
gem 'pry'
gem "guard-rspec"
gem "pry"
platforms :ruby_21 do
gem 'pry-byebug'
gem "pry-byebug"
end
platforms :ruby_19, :ruby_20 do
gem 'pry-debugger'
gem 'pry-stack_explorer'
gem "pry-debugger"
gem "pry-stack_explorer"
end
end

group :test do
gem 'addressable', '~> 2.3.6', :platforms => [:ruby_18]
gem 'childlabor'
gem 'coveralls', '>= 0.5.7'
gem 'json', '< 2' # This is to support Ruby 1.8 and 1.9
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
gem 'rspec', '>= 3'
gem 'rspec-mocks', '>= 3'
gem 'rubocop', '>= 0.19', :platforms => [:ruby_20, :ruby_21]
gem 'simplecov', '>= 0.9'
gem 'term-ansicolor', '~> 1.3.2' # This is to support Ruby 1.8 and 1.9
gem 'tins', '< 1.7' # This is to support Ruby 1.8 and 1.9
gem 'webmock', '>= 1.20', '< 2' # This is to support Ruby 1.8 and 1.9.2
gem "addressable", "~> 2.3.6", :platforms => [:ruby_18]
gem "childlabor"
gem "coveralls", ">= 0.5.7"
gem "json", "< 2" # This is to support Ruby 1.8 and 1.9
gem "mime-types", "~> 1.25", :platforms => [:jruby, :ruby_18]
gem "rest-client", "~> 1.6.0", :platforms => [:jruby, :ruby_18]
gem "rspec", ">= 3"
gem "rspec-mocks", ">= 3"
gem "rubocop", ">= 0.19", :platforms => [:ruby_20, :ruby_21, :ruby_22, :ruby_23]
gem "simplecov", ">= 0.9"
gem "term-ansicolor", "~> 1.3.2" # This is to support Ruby 1.8 and 1.9
gem "tins", "< 1.7" # This is to support Ruby 1.8 and 1.9
gem "webmock", ">= 1.20", "< 2" # This is to support Ruby 1.8 and 1.9.2
end

gemspec
43 changes: 21 additions & 22 deletions lib/thor.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "set"
require "thor/base"

class Thor # rubocop:disable ClassLength
class Thor
class << self
# Allows for custom "Command" package naming.
#
# === Parameters
# name<String>
# options<Hash>
#
def package_name(name, options = {})
def package_name(name, _ = {})
@package_name = name.nil? || name == "" ? nil : name
end

Expand Down Expand Up @@ -57,7 +57,9 @@ def desc(usage, description, options = {})
command.usage = usage if usage
command.description = description if description
else
@usage, @desc, @hide = usage, description, options[:hide] || false
@usage = usage
@desc = description
@hide = options[:hide] || false
end
end

Expand Down Expand Up @@ -235,10 +237,8 @@ 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 }]
if opts.delete('--help') or opts.delete("-h")
invoke_args.unshift 'help'
end
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
end
Expand Down Expand Up @@ -327,6 +327,7 @@ def stop_on_unknown_option?(command) #:nodoc:
end

protected

def stop_on_unknown_option #:nodoc:
@stop_on_unknown_option ||= Set.new
end
Expand All @@ -352,12 +353,14 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
opts.clear
end
else
args, opts = given_args, nil
args = given_args
opts = nil
command = dynamic_command_class.new(meth)
end

opts = given_opts || opts || []
config.merge!(:current_command => command, :command_options => command.options)
config[:current_command] = command
config[:command_options] = command.options

instance = new(args, opts, config)
yield instance if block_given?
Expand Down Expand Up @@ -397,8 +400,8 @@ def create_command(meth) #:nodoc:
elsif all_commands[meth] || meth == "method_missing"
true
else
puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " <<
"Call desc if you want this method to be available as command or declare it inside a " <<
puts "[WARNING] Attempted to create command #{meth.inspect} without usage or description. " \
"Call desc if you want this method to be available as command or declare it inside a " \
"no_commands{} block. Invoked from #{caller[1].inspect}."
false
end
Expand All @@ -413,11 +416,7 @@ def initialize_added #:nodoc:
# Retrieve the command name from given args.
def retrieve_command_name(args) #:nodoc:
meth = args.first.to_s unless args.empty?
if meth && (map[meth] || meth !~ /^\-/)
args.shift
else
nil
end
args.shift if meth && (map[meth] || meth !~ /^\-/)
end
alias_method :retrieve_task_name, :retrieve_command_name

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

possibilities = find_command_possibilities(meth)
if possibilities.size > 1
fail AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]"
elsif possibilities.size < 1
meth = meth || default_command
raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]" if possibilities.size > 1

if possibilities.empty?
meth ||= default_command
elsif map[meth]
meth = map[meth]
else
meth = possibilities.first
end

meth.to_s.gsub("-", "_") # treat foo-bar as foo_bar
meth.to_s.tr("-", "_") # treat foo-bar as foo_bar
end
alias_method :normalize_task_name, :normalize_command_name

Expand Down
Loading

0 comments on commit 3e2dfe9

Please sign in to comment.