Permalink
Browse files

Correct RuboCop offences

  • Loading branch information...
1 parent 43258fe commit 3e6197fa7ac76d462e7ebd48db11d499c7c64eb4 @sferik sferik committed Dec 14, 2013
Showing with 3,000 additions and 3,046 deletions.
  1. +3 −2 .rubocop.yml
  2. +9 −10 Thorfile
  3. +51 −52 lib/thor.rb
  4. +45 −47 lib/thor/actions.rb
  5. +35 −37 lib/thor/actions/create_file.rb
  6. +1 −2 lib/thor/actions/create_link.rb
  7. +36 −37 lib/thor/actions/directory.rb
  8. +66 −68 lib/thor/actions/empty_directory.rb
  9. +8 −9 lib/thor/actions/file_manipulation.rb
  10. +41 −43 lib/thor/actions/inject_into_file.rb
  11. +175 −176 lib/thor/base.rb
  12. +22 −25 lib/thor/command.rb
  13. +21 −24 lib/thor/core_ext/hash_with_indifferent_access.rb
  14. +1 −3 lib/thor/core_ext/io_binary_read.rb
  15. +6 −8 lib/thor/core_ext/ordered_hash.rb
  16. +2 −2 lib/thor/error.rb
  17. +61 −61 lib/thor/group.rb
  18. +38 −38 lib/thor/invocation.rb
  19. +29 −30 lib/thor/parser/argument.rb
  20. +95 −99 lib/thor/parser/arguments.rb
  21. +25 −25 lib/thor/parser/option.rb
  22. +85 −85 lib/thor/parser/options.rb
  23. +6 −7 lib/thor/rake_compat.rb
  24. +153 −153 lib/thor/runner.rb
  25. +23 −30 lib/thor/shell.rb
  26. +43 −46 lib/thor/shell/basic.rb
  27. +41 −42 lib/thor/shell/color.rb
  28. +43 −44 lib/thor/shell/html.rb
  29. +36 −39 lib/thor/util.rb
  30. +1 −1 lib/thor/version.rb
  31. +53 −54 spec/actions/create_file_spec.rb
  32. +25 −25 spec/actions/create_link_spec.rb
  33. +70 −70 spec/actions/directory_spec.rb
  34. +39 −39 spec/actions/empty_directory_spec.rb
  35. +171 −171 spec/actions/file_manipulation_spec.rb
  36. +47 −47 spec/actions/inject_into_file_spec.rb
  37. +139 −139 spec/actions_spec.rb
  38. +113 −113 spec/base_spec.rb
  39. +33 −34 spec/command_spec.rb
  40. +13 −13 spec/core_ext/hash_with_indifferent_access_spec.rb
  41. +50 −50 spec/core_ext/ordered_hash_spec.rb
  42. +5 −5 spec/exit_condition_spec.rb
  43. +2 −2 spec/fixtures/bundle/execute.rb
  44. +69 −69 spec/group_spec.rb
  45. +10 −10 spec/helper.rb
  46. +42 −42 spec/invocation_spec.rb
  47. +24 −24 spec/parser/argument_spec.rb
  48. +24 −24 spec/parser/arguments_spec.rb
  49. +79 −79 spec/parser/option_spec.rb
  50. +182 −182 spec/parser/options_spec.rb
  51. +22 −22 spec/rake_compat_spec.rb
  52. +46 −46 spec/register_spec.rb
  53. +86 −86 spec/runner_spec.rb
  54. +100 −100 spec/shell/basic_spec.rb
  55. +26 −26 spec/shell/color_spec.rb
  56. +10 −10 spec/shell/html_spec.rb
  57. +13 −13 spec/shell_spec.rb
  58. +10 −10 spec/subcommand_spec.rb
  59. +203 −203 spec/thor_spec.rb
  60. +86 −86 spec/util_spec.rb
  61. +7 −7 thor.gemspec
View
@@ -2,10 +2,11 @@ AllCops:
Includes:
- 'Gemfile'
- 'Thorfile'
+ - 'thor.gemspec'
# Avoid long parameter lists
ParameterLists:
- Max: 3
+ Max: 5
CountKeywordArgs: true
MethodLength:
@@ -14,7 +15,7 @@ MethodLength:
# Avoid more than `Max` levels of nesting.
BlockNesting:
- Max: 3
+ Max: 4
# Align with the style guide.
CollectionMethods:
View
@@ -1,5 +1,4 @@
-# encoding: utf-8
-$:.unshift File.expand_path("../lib", __FILE__)
+$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'bundler'
require 'thor/rake_compat'
@@ -8,23 +7,23 @@ class Default < Thor
include Thor::RakeCompat
Bundler::GemHelper.install_tasks
- desc "build", "Build thor-#{Thor::VERSION}.gem into the pkg directory"
+ desc 'build', "Build thor-#{Thor::VERSION}.gem into the pkg directory"
def build
- Rake::Task["build"].execute
+ Rake::Task['build'].execute
end
- desc "install", "Build and install thor-#{Thor::VERSION}.gem into system gems"
+ desc 'install', "Build and install thor-#{Thor::VERSION}.gem into system gems"
def install
- Rake::Task["install"].execute
+ Rake::Task['install'].execute
end
- desc "release", "Create tag v#{Thor::VERSION} and build and push thor-#{Thor::VERSION}.gem to Rubygems"
+ desc 'release', "Create tag v#{Thor::VERSION} and build and push thor-#{Thor::VERSION}.gem to Rubygems"
def release
- Rake::Task["release"].execute
+ Rake::Task['release'].execute
end
- desc "spec", "Run RSpec code examples"
+ desc 'spec', 'Run RSpec code examples'
def spec
- exec "rspec spec"
+ exec 'rspec spec'
end
end
View
@@ -1,15 +1,15 @@
require 'set'
require 'thor/base'
-class Thor
+class Thor # rubocop:disable ClassLength
class << self
# Allows for custom "Command" package naming.
#
# === Parameters
# name<String>
# options<Hash>
#
- def package_name(name, options={})
+ def package_name(name, options = {})
@package_name = name.nil? || name == '' ? nil : name
end
@@ -18,17 +18,17 @@ def package_name(name, options={})
# ==== Parameters
# meth<Symbol>:: name of the default command
#
- def default_command(meth=nil)
+ def default_command(meth = nil)
@default_command = case meth
- when :none
- 'help'
- when nil
- @default_command || from_superclass(:default_command, 'help')
- else
- meth.to_s
- end
+ when :none
+ 'help'
+ when nil
+ @default_command || from_superclass(:default_command, 'help')
+ else
+ meth.to_s
+ end
end
- alias default_task default_command
+ alias_method :default_task, :default_command
# Registers another Thor subclass as a command.
#
@@ -37,7 +37,7 @@ def default_command(meth=nil)
# command<String>:: Subcommand name to use
# usage<String>:: Short usage for the subcommand
# description<String>:: Description for the subcommand
- def register(klass, subcommand_name, usage, description, options={})
+ def register(klass, subcommand_name, usage, description, options = {})
if klass <= Thor::Group
desc usage, description, options
define_method(subcommand_name) { |*args| invoke(klass, args) }
@@ -54,7 +54,7 @@ def register(klass, subcommand_name, usage, description, options={})
# description<String>
# options<String>
#
- def desc(usage, description, options={})
+ def desc(usage, description, options = {})
if options[:for]
command = find_and_refresh_command(options[:for])
command.usage = usage if usage
@@ -69,7 +69,7 @@ def desc(usage, description, options={})
# ==== Parameters
# long description<String>
#
- def long_desc(long_description, options={})
+ def long_desc(long_description, options = {})
if options[:for]
command = find_and_refresh_command(options[:for])
command.long_description = long_description if long_description
@@ -91,13 +91,13 @@ def long_desc(long_description, options={})
# ==== Parameters
# Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given command.
#
- def map(mappings=nil)
+ def map(mappings = nil)
@map ||= from_superclass(:map, {})
if mappings
mappings.each do |key, value|
if key.respond_to?(:each)
- key.each {|subkey| @map[subkey] = value}
+ key.each { |subkey| @map[subkey] = value }
else
@map[key] = value
end
@@ -114,13 +114,13 @@ def map(mappings=nil)
# is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
# or :required (string). If you give a value, the type of the value is used.
#
- def method_options(options=nil)
+ def method_options(options = nil)
@method_options ||= {}
build_options(options, @method_options) if options
@method_options
end
- alias options method_options
+ alias_method :options, :method_options
# Adds an option to the set of method options. If :for is given as option,
# it allows you to change the options from a previous defined command.
@@ -148,16 +148,16 @@ def method_options(options=nil)
# :banner - String to show on usage notes.
# :hide - If you want to hide this option from the help.
#
- def method_option(name, options={})
+ def method_option(name, options = {})
scope = if options[:for]
- find_and_refresh_command(options[:for]).options
- else
- method_options
- end
+ find_and_refresh_command(options[:for]).options
+ else
+ method_options
+ end
build_option(name, options, scope)
end
- alias option method_option
+ alias_method :option, :method_option
# Prints help information for the given command.
#
@@ -170,18 +170,18 @@ def command_help(shell, command_name)
command = all_commands[meth]
handle_no_command_error(meth) unless command
- shell.say "Usage:"
+ shell.say 'Usage:'
shell.say " #{banner(command)}"
shell.say
class_options_help(shell, nil => command.options.map { |_, o| o })
if command.long_description
- shell.say "Description:"
+ shell.say 'Description:'
shell.print_wrapped(command.long_description, :indent => 2)
else
shell.say command.description
end
end
- alias task_help command_help
+ alias_method :task_help, :command_help
# Prints help information for this class.
#
@@ -193,12 +193,12 @@ def help(shell, subcommand = false)
Thor::Util.thor_classes_in(self).each do |klass|
list += klass.printable_commands(false)
end
- list.sort!{ |a,b| a[0] <=> b[0] }
+ list.sort! { |a, b| a[0] <=> b[0] }
if @package_name
shell.say "#{@package_name} commands:"
else
- shell.say "Commands:"
+ shell.say 'Commands:'
end
shell.print_table(list, :indent => 2, :truncate => true)
@@ -212,34 +212,34 @@ def printable_commands(all = true, subcommand = false)
next if command.hidden?
item = []
item << banner(command, false, subcommand)
- item << (command.description ? "# #{command.description.gsub(/\s+/m,' ')}" : "")
+ item << (command.description ? "# #{command.description.gsub(/\s+/m, ' ')}" : '')
item
end.compact
end
- alias printable_tasks printable_commands
+ alias_method :printable_tasks, :printable_commands
def subcommands
@subcommands ||= from_superclass(:subcommands, [])
end
- alias subtasks subcommands
+ alias_method :subtasks, :subcommands
def subcommand(subcommand, subcommand_class)
- self.subcommands << subcommand.to_s
+ subcommands << subcommand.to_s
subcommand_class.subcommand_help subcommand
define_method(subcommand) do |*args|
args, opts = Thor::Arguments.split(args)
invoke subcommand_class, args, opts, :invoked_via_subcommand => true, :class_options => options
end
end
- alias subtask subcommand
+ alias_method :subtask, :subcommand
# Extend check unknown options to accept a hash of conditions.
#
# === Parameters
# options<Hash>: A hash containing :only and/or :except keys
- def check_unknown_options!(options={})
- @check_unknown_options ||= Hash.new
+ def check_unknown_options!(options = {})
+ @check_unknown_options ||= {}
options.each do |key, value|
if value
@check_unknown_options[key] = Array(value)
@@ -320,7 +320,7 @@ def stop_on_unknown_option?(command) #:nodoc:
protected
# The method responsible for dispatching given the args.
- def dispatch(meth, given_args, given_opts, config) #:nodoc:
+ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
# There is an edge case when dispatching from a subcommand.
# A problem occurs invoking the default command. This case occurs
# when arguments are passed and a default command is defined, and
@@ -331,7 +331,7 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc:
# the command normally. If the first item in given_args is not
# a command then use the default command. The given_args will be
# intact later since dup was used.
- if config[:invoked_via_subcommand] && given_args.size >= 1 && default_command != "help" && given_args.first != default_command
+ if config[:invoked_via_subcommand] && given_args.size >= 1 && default_command != 'help' && given_args.first != default_command
meth ||= retrieve_command_name(given_args.dup)
command = all_commands[normalize_command_name(meth)]
command ||= all_commands[normalize_command_name(default_command)]
@@ -382,16 +382,16 @@ def create_command(meth) #:nodoc:
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
@usage, @desc, @long_desc, @method_options, @hide = nil
true
- elsif self.all_commands[meth] || meth == "method_missing"
+ 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 " <<
+ '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
end
- alias create_task create_command
+ alias_method :create_task, :create_command
def initialize_added #:nodoc:
class_options.merge!(method_options)
@@ -407,7 +407,7 @@ def retrieve_command_name(args) #:nodoc:
nil
end
end
- alias retrieve_task_name retrieve_command_name
+ alias_method :retrieve_task_name, :retrieve_command_name
# receives a (possibly nil) command name and returns a name that is in
# the commands hash. In addition to normalizing aliases, this logic
@@ -421,7 +421,7 @@ def normalize_command_name(meth) #:nodoc:
possibilities = find_command_possibilities(meth)
if possibilities.size > 1
- raise AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]"
+ fail AmbiguousTaskError, "Ambiguous command #{meth} matches [#{possibilities.join(', ')}]"
elsif possibilities.size < 1
meth = meth || default_command
elsif map[meth]
@@ -430,9 +430,9 @@ def normalize_command_name(meth) #:nodoc:
meth = possibilities.first
end
- meth.to_s.gsub('-','_') # treat foo-bar as foo_bar
+ meth.to_s.gsub('-', '_') # treat foo-bar as foo_bar
end
- alias normalize_task_name normalize_command_name
+ alias_method :normalize_task_name, :normalize_command_name
# this is the logic that takes the command name passed in by the user
# and determines whether it is an unambiguous substrings of a command or
@@ -450,23 +450,22 @@ def find_command_possibilities(meth)
possibilities
end
end
- alias find_task_possibilities find_command_possibilities
+ alias_method :find_task_possibilities, :find_command_possibilities
def subcommand_help(cmd)
- desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
- class_eval <<-RUBY
+ desc 'help [COMMAND]', 'Describe subcommands or one specific subcommand'
+ class_eval "
def help(command = nil, subcommand = true); super; end
- RUBY
+"
end
- alias subtask_help subcommand_help
-
+ alias_method :subtask_help, :subcommand_help
end
include Thor::Base
map HELP_MAPPINGS => :help
- desc "help [COMMAND]", "Describe available commands or one specific command"
+ desc 'help [COMMAND]', 'Describe available commands or one specific command'
def help(command = nil, subcommand = false)
command ? self.class.command_help(shell, command) : self.class.help(shell, subcommand)
end
Oops, something went wrong.

0 comments on commit 3e6197f

Please sign in to comment.