rubocop 0.75.1 → 0.80.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -4
  4. data/config/default.yml +374 -335
  5. data/lib/rubocop.rb +53 -32
  6. data/lib/rubocop/ast/builder.rb +43 -41
  7. data/lib/rubocop/ast/node.rb +5 -13
  8. data/lib/rubocop/ast/node/block_node.rb +2 -0
  9. data/lib/rubocop/ast/node/def_node.rb +11 -0
  10. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  11. data/lib/rubocop/ast/node/regexp_node.rb +2 -4
  12. data/lib/rubocop/ast/node/return_node.rb +24 -0
  13. data/lib/rubocop/ast/traversal.rb +20 -3
  14. data/lib/rubocop/cli.rb +11 -227
  15. data/lib/rubocop/cli/command.rb +21 -0
  16. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  17. data/lib/rubocop/cli/command/base.rb +33 -0
  18. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  19. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  20. data/lib/rubocop/cli/command/show_cops.rb +80 -0
  21. data/lib/rubocop/cli/command/version.rb +17 -0
  22. data/lib/rubocop/cli/environment.rb +21 -0
  23. data/lib/rubocop/comment_config.rb +8 -3
  24. data/lib/rubocop/config.rb +8 -1
  25. data/lib/rubocop/config_loader.rb +20 -20
  26. data/lib/rubocop/config_loader_resolver.rb +2 -1
  27. data/lib/rubocop/config_obsoletion.rb +73 -10
  28. data/lib/rubocop/config_validator.rb +77 -110
  29. data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
  30. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  31. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  32. data/lib/rubocop/cop/commissioner.rb +15 -7
  33. data/lib/rubocop/cop/cop.rb +31 -6
  34. data/lib/rubocop/cop/corrector.rb +8 -7
  35. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  36. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  37. data/lib/rubocop/cop/generator.rb +3 -4
  38. data/lib/rubocop/cop/generator/configuration_injector.rb +2 -2
  39. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  40. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  41. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  42. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  43. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
  44. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  45. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  46. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  47. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  48. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  49. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
  50. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  51. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
  52. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  53. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +16 -8
  54. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
  55. data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
  56. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  57. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +68 -112
  58. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  59. data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
  60. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
  61. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  62. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  63. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  64. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  65. data/lib/rubocop/cop/layout/space_around_operators.rb +50 -7
  66. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  67. data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
  68. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  69. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  70. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
  71. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  72. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  73. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  74. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  75. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  76. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  77. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  78. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  79. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  80. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  81. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  82. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  83. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
  84. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +18 -15
  85. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  86. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
  87. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  88. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  89. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  90. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  91. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  92. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  93. data/lib/rubocop/cop/lint/useless_setter_call.rb +5 -1
  94. data/lib/rubocop/cop/lint/void.rb +4 -4
  95. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  96. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  97. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  98. data/lib/rubocop/cop/migration/department_name.rb +30 -2
  99. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  100. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
  101. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
  102. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  103. data/lib/rubocop/cop/mixin/hash_transform_method.rb +172 -0
  104. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  105. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  106. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  107. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  108. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
  109. data/lib/rubocop/cop/mixin/trailing_comma.rb +16 -18
  110. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  111. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  112. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  113. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  114. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +4 -4
  115. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  116. data/lib/rubocop/cop/offense.rb +11 -0
  117. data/lib/rubocop/cop/registry.rb +8 -3
  118. data/lib/rubocop/cop/style/alias.rb +1 -1
  119. data/lib/rubocop/cop/style/array_join.rb +1 -1
  120. data/lib/rubocop/cop/style/attr.rb +10 -2
  121. data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
  122. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  123. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  124. data/lib/rubocop/cop/style/copyright.rb +11 -7
  125. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  126. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  127. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  128. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  129. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  130. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  131. data/lib/rubocop/cop/style/format_string.rb +10 -7
  132. data/lib/rubocop/cop/style/format_string_token.rb +2 -0
  133. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +99 -11
  134. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  135. data/lib/rubocop/cop/style/hash_each_methods.rb +87 -0
  136. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  137. data/lib/rubocop/cop/style/hash_transform_keys.rb +79 -0
  138. data/lib/rubocop/cop/style/hash_transform_values.rb +79 -0
  139. data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
  140. data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
  141. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  142. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  143. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  144. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
  145. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
  146. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  147. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  148. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  149. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  150. data/lib/rubocop/cop/style/multiline_when_then.rb +6 -2
  151. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  152. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  153. data/lib/rubocop/cop/style/next.rb +5 -5
  154. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  155. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  156. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
  157. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  158. data/lib/rubocop/cop/style/or_assignment.rb +3 -2
  159. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  160. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  161. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  162. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  163. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  164. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  165. data/lib/rubocop/cop/style/redundant_return.rb +27 -29
  166. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
  167. data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
  168. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  169. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  170. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  171. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  172. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +0 -22
  173. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  174. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  175. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  176. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  177. data/lib/rubocop/cop/team.rb +5 -0
  178. data/lib/rubocop/cop/util.rb +1 -1
  179. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  180. data/lib/rubocop/cop/variable_force.rb +11 -6
  181. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  182. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
  183. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  184. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  185. data/lib/rubocop/formatter/junit_formatter.rb +63 -0
  186. data/lib/rubocop/formatter/tap_formatter.rb +1 -3
  187. data/lib/rubocop/node_pattern.rb +100 -12
  188. data/lib/rubocop/options.rb +17 -11
  189. data/lib/rubocop/processed_source.rb +1 -1
  190. data/lib/rubocop/rake_task.rb +1 -0
  191. data/lib/rubocop/result_cache.rb +24 -8
  192. data/lib/rubocop/rspec/shared_contexts.rb +5 -0
  193. data/lib/rubocop/runner.rb +50 -29
  194. data/lib/rubocop/target_finder.rb +12 -6
  195. data/lib/rubocop/target_ruby.rb +151 -0
  196. data/lib/rubocop/version.rb +1 -1
  197. metadata +69 -35
  198. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
  199. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # A subcommand in the CLI.
7
+ class Base
8
+ attr_reader :env
9
+
10
+ @subclasses = []
11
+
12
+ class << self
13
+ attr_accessor :command_name
14
+
15
+ def inherited(subclass)
16
+ @subclasses << subclass
17
+ end
18
+
19
+ def by_command_name(name)
20
+ @subclasses.detect { |s| s.command_name == name }
21
+ end
22
+ end
23
+
24
+ def initialize(env)
25
+ @env = env
26
+ @options = env.options
27
+ @config_store = env.config_store
28
+ @paths = env.paths
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Run all the selected cops and report the result.
7
+ class ExecuteRunner < Base
8
+ include Formatter::TextUtil
9
+
10
+ self.command_name = :execute_runner
11
+
12
+ def run
13
+ execute_runner(@paths)
14
+ end
15
+
16
+ private
17
+
18
+ def execute_runner(paths)
19
+ runner = Runner.new(@options, @config_store)
20
+
21
+ all_passed = runner.run(paths)
22
+ display_warning_summary(runner.warnings)
23
+ display_error_summary(runner.errors)
24
+ maybe_print_corrected_source
25
+
26
+ all_pass_or_excluded = all_passed || @options[:auto_gen_config]
27
+
28
+ if runner.aborting?
29
+ STATUS_INTERRUPTED
30
+ elsif all_pass_or_excluded && runner.errors.empty?
31
+ STATUS_SUCCESS
32
+ else
33
+ STATUS_OFFENSES
34
+ end
35
+ end
36
+
37
+ def display_warning_summary(warnings)
38
+ return if warnings.empty?
39
+
40
+ warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
41
+
42
+ warnings.each { |warning| warn warning }
43
+ end
44
+
45
+ def display_error_summary(errors)
46
+ return if errors.empty?
47
+
48
+ warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
49
+
50
+ errors.each { |error| warn error }
51
+
52
+ warn <<~WARNING
53
+ Errors are usually caused by RuboCop bugs.
54
+ Please, report your problems to RuboCop's issue tracker.
55
+ #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
56
+
57
+ Mention the following information in the issue report:
58
+ #{RuboCop::Version.version(true)}
59
+ WARNING
60
+ end
61
+
62
+ def maybe_print_corrected_source
63
+ # If we are asked to autocorrect source code read from stdin, the only
64
+ # reasonable place to write it is to stdout
65
+ # Unfortunately, we also write other information to stdout
66
+ # So a delimiter is needed for tools to easily identify where the
67
+ # autocorrected source begins
68
+ return unless @options[:stdin] && @options[:auto_correct]
69
+
70
+ puts '=' * 20
71
+ print @options[:stdin]
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Generate a .rubocop.yml file in the current directory.
7
+ class InitDotfile < Base
8
+ DOTFILE = ConfigLoader::DOTFILE
9
+
10
+ self.command_name = :init
11
+
12
+ def run
13
+ path = File.expand_path(DOTFILE)
14
+
15
+ if File.exist?(DOTFILE)
16
+ warn Rainbow("#{DOTFILE} already exists at #{path}").red
17
+
18
+ STATUS_ERROR
19
+ else
20
+ description = <<~DESC
21
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
22
+ # configuration file. It makes it possible to enable/disable
23
+ # certain cops (checks) and to alter their behavior if they accept
24
+ # any parameters. The file can be placed either in your home
25
+ # directory or in some project directory.
26
+ #
27
+ # RuboCop will start looking for the configuration file in the directory
28
+ # where the inspected file is and continue its way up to the root directory.
29
+ #
30
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
31
+ DESC
32
+
33
+ File.open(DOTFILE, 'w') do |f|
34
+ f.write(description)
35
+ end
36
+
37
+ puts "Writing new #{DOTFILE} to #{path}"
38
+
39
+ STATUS_SUCCESS
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Shows the given cops, or all cops by default, and their configurations
7
+ # for the current directory.
8
+ class ShowCops < Base
9
+ self.command_name = :show_cops
10
+
11
+ def initialize(env)
12
+ super
13
+
14
+ # Load the configs so the require()s are done for custom cops
15
+ @config = @config_store.for(Dir.pwd)
16
+ end
17
+
18
+ def run
19
+ print_available_cops
20
+ end
21
+
22
+ private
23
+
24
+ def print_available_cops
25
+ registry = Cop::Cop.registry
26
+ show_all = @options[:show_cops].empty?
27
+
28
+ if show_all
29
+ puts "# Available cops (#{registry.length}) " \
30
+ "+ config for #{Dir.pwd}: "
31
+ end
32
+
33
+ registry.departments.sort!.each do |department|
34
+ print_cops_of_department(registry, department, show_all)
35
+ end
36
+ end
37
+
38
+ def print_cops_of_department(registry, department, show_all)
39
+ selected_cops = if show_all
40
+ cops_of_department(registry, department)
41
+ else
42
+ selected_cops_of_department(registry, department)
43
+ end
44
+
45
+ if show_all
46
+ puts "# Department '#{department}' (#{selected_cops.length}):"
47
+ end
48
+
49
+ print_cop_details(selected_cops)
50
+ end
51
+
52
+ def print_cop_details(cops)
53
+ cops.each do |cop|
54
+ if cop.new(@config).support_autocorrect?
55
+ puts '# Supports --auto-correct'
56
+ end
57
+ puts "#{cop.cop_name}:"
58
+ puts config_lines(cop)
59
+ puts
60
+ end
61
+ end
62
+
63
+ def selected_cops_of_department(cops, department)
64
+ cops_of_department(cops, department).select do |cop|
65
+ @options[:show_cops].include?(cop.cop_name)
66
+ end
67
+ end
68
+
69
+ def cops_of_department(cops, department)
70
+ cops.with_department(department).sort!
71
+ end
72
+
73
+ def config_lines(cop)
74
+ cnf = @config.for_cop(cop)
75
+ cnf.to_yaml.lines.to_a.drop(1).map { |line| ' ' + line }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Display version.
7
+ class Version < Base
8
+ self.command_name = :version
9
+
10
+ def run
11
+ puts RuboCop::Version.version(false) if @options[:version]
12
+ puts RuboCop::Version.version(true) if @options[:verbose_version]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ # Execution environment for a CLI command.
6
+ class Environment
7
+ attr_reader :options, :config_store, :paths
8
+
9
+ def initialize(options, config_store, paths)
10
+ @options = options
11
+ @config_store = config_store
12
+ @paths = paths
13
+ end
14
+
15
+ # Run a command in this environment.
16
+ def run(name)
17
+ Command.run(self, name)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # This class parses the special `rubocop:disable` comments in a source
5
5
  # and provides a way to check if each cop is enabled at arbitrary line.
6
6
  class CommentConfig
7
- UNNEEDED_DISABLE = 'Lint/UnneededCopDisableDirective'
7
+ REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
8
8
 
9
9
  COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)'
10
10
  COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
@@ -113,7 +113,8 @@ module RuboCop
113
113
  def each_mentioned_cop
114
114
  each_directive do |comment, cop_names, disabled|
115
115
  comment_line_number = comment.loc.expression.line
116
- single_line = !comment_only_line?(comment_line_number)
116
+ single_line = !comment_only_line?(comment_line_number) ||
117
+ directive_on_comment_line?(comment)
117
118
 
118
119
  cop_names.each do |cop_name|
119
120
  yield qualified_cop_name(cop_name), disabled, comment_line_number,
@@ -122,6 +123,10 @@ module RuboCop
122
123
  end
123
124
  end
124
125
 
126
+ def directive_on_comment_line?(comment)
127
+ comment.text[1..-1].match(COMMENT_DIRECTIVE_REGEXP)
128
+ end
129
+
125
130
  def each_directive
126
131
  return if processed_source.comments.nil?
127
132
 
@@ -152,7 +157,7 @@ module RuboCop
152
157
  end
153
158
 
154
159
  def all_cop_names
155
- @all_cop_names ||= Cop::Cop.registry.names - [UNNEEDED_DISABLE]
160
+ @all_cop_names ||= Cop::Cop.registry.names - [REDUNDANT_DISABLE]
156
161
  end
157
162
 
158
163
  def comment_only_line?(line_number)
@@ -53,6 +53,13 @@ module RuboCop
53
53
  @signature ||= Digest::SHA1.hexdigest(to_s)
54
54
  end
55
55
 
56
+ # True if this is a config file that is shipped with RuboCop
57
+ def internal?
58
+ base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
59
+ 'config'))
60
+ File.expand_path(loaded_path).start_with?(base_config_path)
61
+ end
62
+
56
63
  def make_excludes_absolute
57
64
  each_key do |key|
58
65
  @validator.validate_section_presence(key)
@@ -108,7 +115,7 @@ module RuboCop
108
115
  relative_file_path = path_relative_to_config(file)
109
116
 
110
117
  # Optimization to quickly decide if the given file is hidden (on the top
111
- # level) and can not be matched by any pattern.
118
+ # level) and cannot be matched by any pattern.
112
119
  is_hidden = relative_file_path.start_with?('.') &&
113
120
  !relative_file_path.start_with?('..')
114
121
  return false if is_hidden && !possibly_include_hidden?
@@ -46,7 +46,7 @@ module RuboCop
46
46
 
47
47
  add_missing_namespaces(path, hash)
48
48
 
49
- resolver.resolve_inheritance_from_gems(hash, hash.delete('inherit_gem'))
49
+ resolver.resolve_inheritance_from_gems(hash)
50
50
  resolver.resolve_inheritance(path, hash, file, debug?)
51
51
 
52
52
  hash.delete('inherit_from')
@@ -91,7 +91,9 @@ module RuboCop
91
91
  else
92
92
  add_excludes_from_files(config, config_file)
93
93
  end
94
- merge_with_default(config, config_file)
94
+ merge_with_default(config, config_file).tap do |merged_config|
95
+ warn_on_pending_cops(merged_config)
96
+ end
95
97
  end
96
98
 
97
99
  def add_excludes_from_files(config, config_file)
@@ -114,6 +116,22 @@ module RuboCop
114
116
  end
115
117
  end
116
118
 
119
+ def warn_on_pending_cops(config)
120
+ pending_cops = config.keys.select do |key|
121
+ config[key]['Enabled'] == 'pending'
122
+ end
123
+
124
+ return if pending_cops.none?
125
+
126
+ warn Rainbow('The following cops were added to RuboCop, but are not ' \
127
+ 'configured. Please set Enabled to either `true` or ' \
128
+ '`false` in your `.rubocop.yml` file:').yellow
129
+
130
+ pending_cops.each do |cop|
131
+ warn Rainbow(" - #{cop}").yellow
132
+ end
133
+ end
134
+
117
135
  # Merges the given configuration with the default one. If
118
136
  # AllCops:DisabledByDefault is true, it changes the Enabled params so
119
137
  # that only cops from user configuration are enabled.
@@ -199,8 +217,6 @@ module RuboCop
199
217
  raise(TypeError, "Malformed configuration in #{absolute_path}")
200
218
  end
201
219
 
202
- check_cop_config_value(hash)
203
-
204
220
  hash
205
221
  end
206
222
 
@@ -222,22 +238,6 @@ module RuboCop
222
238
  end
223
239
  end
224
240
 
225
- def check_cop_config_value(hash, parent = nil)
226
- hash.each do |key, value|
227
- check_cop_config_value(value, key) if value.is_a?(Hash)
228
-
229
- next unless %w[Enabled
230
- Safe
231
- SafeAutoCorrect
232
- AutoCorrect].include?(key) && value.is_a?(String)
233
-
234
- abort(
235
- "Property #{Rainbow(key).yellow} of cop #{Rainbow(parent).yellow}" \
236
- " is supposed to be a boolean and #{Rainbow(value).yellow} is not."
237
- )
238
- end
239
- end
240
-
241
241
  # Read the specified file, or exit with a friendly, concise message on
242
242
  # stderr. Care is taken to use the standard OS exit code for a "file not
243
243
  # found" error.
@@ -35,7 +35,8 @@ module RuboCop
35
35
  end
36
36
  end
37
37
 
38
- def resolve_inheritance_from_gems(hash, gems)
38
+ def resolve_inheritance_from_gems(hash)
39
+ gems = hash.delete('inherit_gem')
39
40
  (gems || {}).each_pair do |gem_name, config_path|
40
41
  if gem_name == 'rubocop'
41
42
  raise ArgumentError,
@@ -4,13 +4,39 @@ module RuboCop
4
4
  # This class handles obsolete configuration.
5
5
  class ConfigObsoletion
6
6
  RENAMED_COPS = {
7
- 'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
8
- 'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
7
+ 'Layout/AlignArguments' => 'Layout/ArgumentAlignment',
8
+ 'Layout/AlignArray' => 'Layout/ArrayAlignment',
9
+ 'Layout/AlignHash' => 'Layout/HashAlignment',
10
+ 'Layout/AlignParameters' => 'Layout/ParameterAlignment',
11
+ 'Layout/IndentArray' => 'Layout/FirstArrayElementIndentation',
12
+ 'Layout/IndentAssignment' => 'Layout/AssignmentIndentation',
13
+ 'Layout/IndentFirstArgument' => 'Layout/FirstArgumentIndentation',
14
+ 'Layout/IndentFirstArrayElement' => 'Layout/FirstArrayElementIndentation',
15
+ 'Layout/IndentFirstHashElement' => 'Layout/FirstHashElementIndentation',
16
+ 'Layout/IndentFirstParameter' => 'Layout/FirstParameterIndentation',
17
+ 'Layout/IndentHash' => 'Layout/FirstHashElementIndentation',
18
+ 'Layout/IndentHeredoc' => 'Layout/HeredocIndentation',
19
+ 'Layout/LeadingBlankLines' => 'Layout/LeadingEmptyLines',
20
+ 'Layout/TrailingBlankLines' => 'Layout/TrailingEmptyLines',
21
+ 'Lint/DuplicatedKey' => 'Lint/DuplicateHashKey',
22
+ 'Lint/HandleExceptions' => 'Lint/SuppressedException',
23
+ 'Lint/MultipleCompare' => 'Lint/MultipleComparison',
24
+ 'Lint/StringConversionInInterpolation' => 'Lint/RedundantStringCoercion',
25
+ 'Lint/UnneededCopDisableDirective' => 'Lint/RedundantCopDisableDirective',
26
+ 'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
27
+ 'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
28
+ 'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
29
+ 'Naming/UncommunicativeBlockParamName' => 'Naming/BlockParameterName',
30
+ 'Naming/UncommunicativeMethodParamName' => 'Naming/MethodParameterName',
9
31
  'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
32
+ 'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
10
33
  'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
11
- 'Layout/FirstParameterIndentation' => 'Layout/IndentFirstArgument',
12
- 'Layout/IndentArray' => 'Layout/IndentFirstArrayElement',
13
- 'Layout/IndentHash' => 'Layout/IndentFirstHashElement'
34
+ 'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
35
+ 'Style/UnneededCapitalW' => 'Style/RedundantCapitalW',
36
+ 'Style/UnneededCondition' => 'Style/RedundantCondition',
37
+ 'Style/UnneededInterpolation' => 'Style/RedundantInterpolation',
38
+ 'Style/UnneededPercentQ' => 'Style/RedundantPercentQ',
39
+ 'Style/UnneededSort' => 'Style/RedundantSort'
14
40
  }.map do |old_name, new_name|
15
41
  [old_name, "The `#{old_name}` cop has been renamed to `#{new_name}`."]
16
42
  end
@@ -22,7 +48,7 @@ module RuboCop
22
48
  Style/VariableName Style/VariableNumber
23
49
  Style/AccessorMethodName Style/AsciiIdentifiers],
24
50
  'Layout' => %w[Lint/BlockAlignment Lint/EndAlignment
25
- Lint/DefEndAlignment],
51
+ Lint/DefEndAlignment Metrics/LineLength],
26
52
  'Lint' => 'Style/FlipFlop'
27
53
  }.map do |new_department, old_names|
28
54
  Array(old_names).map do |old_name|
@@ -32,9 +58,10 @@ module RuboCop
32
58
  end
33
59
 
34
60
  REMOVED_COPS = {
35
- 'Rails/DefaultScope' => nil,
36
61
  'Layout/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
37
62
  'Layout/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
63
+ 'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError',
64
+ 'Rails/DefaultScope' => nil,
38
65
  'Style/SpaceAfterControlKeyword' => 'Layout/SpaceAroundKeyword',
39
66
  'Style/SpaceBeforeModifierKeyword' => 'Layout/SpaceAroundKeyword',
40
67
  'Style/TrailingComma' => 'Style/TrailingCommaInArguments, ' \
@@ -43,7 +70,7 @@ module RuboCop
43
70
  'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
44
71
  'and/or ' \
45
72
  'Style/TrailingCommaInHashLiteral',
46
- 'Lint/RescueWithoutErrorClass' => 'Style/RescueStandardError'
73
+ 'Style/BracesAroundHashParameters' => nil
47
74
  }.map do |old_name, other_cops|
48
75
  if other_cops
49
76
  more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
@@ -88,13 +115,13 @@ module RuboCop
88
115
  cops: 'Style/IfUnlessModifier',
89
116
  parameters: 'MaxLineLength',
90
117
  alternative: '`Style/IfUnlessModifier: MaxLineLength` has been ' \
91
- 'removed. Use `Metrics/LineLength: Max` instead'
118
+ 'removed. Use `Layout/LineLength: Max` instead'
92
119
  },
93
120
  {
94
121
  cops: 'Style/WhileUntilModifier',
95
122
  parameters: 'MaxLineLength',
96
123
  alternative: '`Style/WhileUntilModifier: MaxLineLength` has been ' \
97
- 'removed. Use `Metrics/LineLength: Max` instead'
124
+ 'removed. Use `Layout/LineLength: Max` instead'
98
125
  },
99
126
  {
100
127
  cops: 'AllCops',
@@ -131,6 +158,42 @@ module RuboCop
131
158
  parameters: 'SafeMode',
132
159
  alternative: '`SafeMode` has been removed. ' \
133
160
  'Use `SafeAutoCorrect` instead.'
161
+ },
162
+ {
163
+ cops: 'Bundler/GemComment',
164
+ parameters: 'Whitelist',
165
+ alternative: '`Whitelist` has been renamed to `IgnoredGems`.'
166
+ },
167
+ {
168
+ cops: %w[
169
+ Lint/SafeNavigationChain Lint/SafeNavigationConsistency
170
+ Style/NestedParenthesizedCalls Style/SafeNavigation
171
+ Style/TrivialAccessors
172
+ ],
173
+ parameters: 'Whitelist',
174
+ alternative: '`Whitelist` has been renamed to `AllowedMethods`.'
175
+ },
176
+ {
177
+ cops: 'Style/IpAddresses',
178
+ parameters: 'Whitelist',
179
+ alternative: '`Whitelist` has been renamed to `AllowedAddresses`.'
180
+ },
181
+ {
182
+ cops: 'Naming/HeredocDelimiterNaming',
183
+ parameters: 'Blacklist',
184
+ alternative: '`Blacklist` has been renamed to `ForbiddenDelimiters`.'
185
+ },
186
+ {
187
+ cops: 'Naming/PredicateName',
188
+ parameters: 'NamePrefixBlacklist',
189
+ alternative: '`NamePrefixBlacklist` has been renamed to ' \
190
+ '`ForbiddenPrefixes`.'
191
+ },
192
+ {
193
+ cops: 'Naming/PredicateName',
194
+ parameters: 'NameWhitelist',
195
+ alternative: '`NameWhitelist` has been renamed to ' \
196
+ '`AllowedMethods`.'
134
197
  }
135
198
  ].freeze
136
199