rubocop 0.75.1 → 0.78.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +339 -315
  4. data/lib/rubocop.rb +42 -31
  5. data/lib/rubocop/ast/builder.rb +1 -0
  6. data/lib/rubocop/ast/node.rb +5 -1
  7. data/lib/rubocop/ast/node/block_node.rb +2 -0
  8. data/lib/rubocop/ast/node/return_node.rb +24 -0
  9. data/lib/rubocop/cli.rb +11 -227
  10. data/lib/rubocop/cli/command.rb +21 -0
  11. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  12. data/lib/rubocop/cli/command/base.rb +33 -0
  13. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  14. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  15. data/lib/rubocop/cli/command/show_cops.rb +73 -0
  16. data/lib/rubocop/cli/command/version.rb +17 -0
  17. data/lib/rubocop/cli/environment.rb +21 -0
  18. data/lib/rubocop/comment_config.rb +2 -2
  19. data/lib/rubocop/config.rb +8 -1
  20. data/lib/rubocop/config_loader.rb +1 -1
  21. data/lib/rubocop/config_loader_resolver.rb +2 -1
  22. data/lib/rubocop/config_obsoletion.rb +73 -11
  23. data/lib/rubocop/config_validator.rb +28 -19
  24. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  25. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  26. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  27. data/lib/rubocop/cop/commissioner.rb +15 -7
  28. data/lib/rubocop/cop/cop.rb +31 -6
  29. data/lib/rubocop/cop/corrector.rb +8 -7
  30. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  31. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  32. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  33. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  34. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  35. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  36. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
  37. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  38. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  39. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  40. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  41. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
  42. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  43. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
  44. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  45. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +8 -4
  46. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +5 -5
  47. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  48. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
  49. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  50. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  51. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  52. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  53. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  54. data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
  55. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  56. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  57. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  58. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  59. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  60. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  61. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  62. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  63. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  64. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  65. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  66. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  67. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  68. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  69. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +25 -25
  70. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
  71. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  72. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
  73. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  74. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  75. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  76. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  77. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  78. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  79. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  80. data/lib/rubocop/cop/lint/void.rb +4 -4
  81. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  82. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  83. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  84. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  85. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  86. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  87. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  88. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  89. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  90. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
  91. data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
  92. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  93. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  94. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  95. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +3 -3
  96. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  97. data/lib/rubocop/cop/offense.rb +11 -0
  98. data/lib/rubocop/cop/registry.rb +1 -1
  99. data/lib/rubocop/cop/style/alias.rb +1 -1
  100. data/lib/rubocop/cop/style/array_join.rb +1 -1
  101. data/lib/rubocop/cop/style/attr.rb +10 -2
  102. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
  103. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  104. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  105. data/lib/rubocop/cop/style/copyright.rb +11 -7
  106. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  107. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  108. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  109. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  110. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  111. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  112. data/lib/rubocop/cop/style/format_string.rb +10 -7
  113. data/lib/rubocop/cop/style/format_string_token.rb +2 -0
  114. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
  115. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  116. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  117. data/lib/rubocop/cop/style/if_unless_modifier.rb +45 -3
  118. data/lib/rubocop/cop/style/infinite_loop.rb +5 -4
  119. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  120. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  121. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  122. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  123. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  124. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  125. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
  126. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  127. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  128. data/lib/rubocop/cop/style/next.rb +5 -5
  129. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  130. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  131. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  132. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  133. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  134. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  135. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  136. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  137. data/lib/rubocop/cop/style/redundant_return.rb +27 -29
  138. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
  139. data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
  140. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  141. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  142. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  143. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  144. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  145. data/lib/rubocop/cop/team.rb +5 -0
  146. data/lib/rubocop/cop/util.rb +1 -1
  147. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  148. data/lib/rubocop/cop/variable_force.rb +7 -5
  149. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  150. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
  151. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  152. data/lib/rubocop/formatter/tap_formatter.rb +1 -3
  153. data/lib/rubocop/node_pattern.rb +4 -2
  154. data/lib/rubocop/options.rb +17 -11
  155. data/lib/rubocop/processed_source.rb +1 -1
  156. data/lib/rubocop/rake_task.rb +1 -0
  157. data/lib/rubocop/result_cache.rb +24 -8
  158. data/lib/rubocop/runner.rb +50 -29
  159. data/lib/rubocop/target_finder.rb +12 -6
  160. data/lib/rubocop/version.rb +1 -1
  161. metadata +44 -32
  162. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -55,6 +55,7 @@ require_relative 'rubocop/ast/node/range_node'
55
55
  require_relative 'rubocop/ast/node/regexp_node'
56
56
  require_relative 'rubocop/ast/node/resbody_node'
57
57
  require_relative 'rubocop/ast/node/retry_node'
58
+ require_relative 'rubocop/ast/node/return_node'
58
59
  require_relative 'rubocop/ast/node/self_class_node'
59
60
  require_relative 'rubocop/ast/node/send_node'
60
61
  require_relative 'rubocop/ast/node/str_node'
@@ -117,11 +118,12 @@ require_relative 'rubocop/cop/mixin/end_keyword_alignment'
117
118
  require_relative 'rubocop/cop/mixin/enforce_superclass'
118
119
  require_relative 'rubocop/cop/mixin/first_element_line_break'
119
120
  require_relative 'rubocop/cop/mixin/frozen_string_literal'
120
- require_relative 'rubocop/cop/mixin/hash_alignment'
121
+ require_relative 'rubocop/cop/mixin/hash_alignment_styles'
121
122
  require_relative 'rubocop/cop/mixin/ignored_pattern'
122
123
  require_relative 'rubocop/cop/mixin/ignored_methods'
123
124
  require_relative 'rubocop/cop/mixin/integer_node'
124
125
  require_relative 'rubocop/cop/mixin/interpolation'
126
+ require_relative 'rubocop/cop/mixin/line_length_help'
125
127
  require_relative 'rubocop/cop/mixin/match_range'
126
128
  require_relative 'rubocop/cop/mixin/method_complexity'
127
129
  require_relative 'rubocop/cop/mixin/method_preference'
@@ -141,9 +143,9 @@ require_relative 'rubocop/cop/mixin/percent_array'
141
143
  require_relative 'rubocop/cop/mixin/percent_literal'
142
144
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
143
145
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
146
+ require_relative 'rubocop/cop/mixin/rational_literal'
144
147
  require_relative 'rubocop/cop/mixin/rescue_node'
145
148
  require_relative 'rubocop/cop/mixin/safe_assignment'
146
- require_relative 'rubocop/cop/mixin/safe_mode'
147
149
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
148
150
  require_relative 'rubocop/cop/mixin/space_before_punctuation'
149
151
  require_relative 'rubocop/cop/mixin/surrounding_space'
@@ -188,10 +190,9 @@ require_relative 'rubocop/cop/gemspec/required_ruby_version'
188
190
  require_relative 'rubocop/cop/gemspec/ruby_version_globals_usage'
189
191
 
190
192
  require_relative 'rubocop/cop/layout/access_modifier_indentation'
191
- require_relative 'rubocop/cop/layout/align_arguments'
192
- require_relative 'rubocop/cop/layout/align_array'
193
- require_relative 'rubocop/cop/layout/align_hash'
194
- require_relative 'rubocop/cop/layout/align_parameters'
193
+ require_relative 'rubocop/cop/layout/argument_alignment'
194
+ require_relative 'rubocop/cop/layout/array_alignment'
195
+ require_relative 'rubocop/cop/layout/assignment_indentation'
195
196
  require_relative 'rubocop/cop/layout/block_alignment'
196
197
  require_relative 'rubocop/cop/layout/block_end_newline'
197
198
  require_relative 'rubocop/cop/layout/case_indentation'
@@ -212,29 +213,30 @@ require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
212
213
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
213
214
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
214
215
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
215
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Metrics/LineLength
216
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
216
217
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
217
218
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
218
219
  require_relative 'rubocop/cop/layout/empty_lines'
219
220
  require_relative 'rubocop/cop/layout/end_alignment'
220
221
  require_relative 'rubocop/cop/layout/end_of_line'
221
222
  require_relative 'rubocop/cop/layout/extra_spacing'
223
+ require_relative 'rubocop/cop/layout/first_argument_indentation'
224
+ require_relative 'rubocop/cop/layout/first_array_element_indentation'
222
225
  require_relative 'rubocop/cop/layout/first_array_element_line_break'
226
+ require_relative 'rubocop/cop/layout/first_hash_element_indentation'
223
227
  require_relative 'rubocop/cop/layout/first_hash_element_line_break'
224
228
  require_relative 'rubocop/cop/layout/first_method_argument_line_break'
225
229
  require_relative 'rubocop/cop/layout/first_method_parameter_line_break'
230
+ require_relative 'rubocop/cop/layout/first_parameter_indentation'
231
+ require_relative 'rubocop/cop/layout/hash_alignment'
226
232
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
227
- require_relative 'rubocop/cop/layout/indent_assignment'
233
+ require_relative 'rubocop/cop/layout/heredoc_indentation'
228
234
  require_relative 'rubocop/cop/layout/indentation_consistency'
229
235
  require_relative 'rubocop/cop/layout/indentation_width'
230
- require_relative 'rubocop/cop/layout/indent_first_argument'
231
- require_relative 'rubocop/cop/layout/indent_first_array_element'
232
- require_relative 'rubocop/cop/layout/indent_first_hash_element'
233
- require_relative 'rubocop/cop/layout/indent_first_parameter'
234
- require_relative 'rubocop/cop/layout/indent_heredoc'
235
236
  require_relative 'rubocop/cop/layout/initial_indentation'
236
- require_relative 'rubocop/cop/layout/leading_blank_lines'
237
237
  require_relative 'rubocop/cop/layout/leading_comment_space'
238
+ require_relative 'rubocop/cop/layout/leading_empty_lines'
239
+ require_relative 'rubocop/cop/layout/line_length'
238
240
  require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
239
241
  require_relative 'rubocop/cop/layout/multiline_array_line_breaks'
240
242
  require_relative 'rubocop/cop/layout/multiline_assignment_layout'
@@ -246,6 +248,7 @@ require_relative 'rubocop/cop/layout/multiline_method_call_brace_layout'
246
248
  require_relative 'rubocop/cop/layout/multiline_method_call_indentation'
247
249
  require_relative 'rubocop/cop/layout/multiline_method_definition_brace_layout'
248
250
  require_relative 'rubocop/cop/layout/multiline_operation_indentation'
251
+ require_relative 'rubocop/cop/layout/parameter_alignment'
249
252
  require_relative 'rubocop/cop/layout/rescue_ensure_alignment'
250
253
  require_relative 'rubocop/cop/layout/space_after_colon'
251
254
  require_relative 'rubocop/cop/layout/space_after_comma'
@@ -272,7 +275,7 @@ require_relative 'rubocop/cop/layout/space_inside_range_literal'
272
275
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
273
276
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
274
277
  require_relative 'rubocop/cop/layout/tab'
275
- require_relative 'rubocop/cop/layout/trailing_blank_lines'
278
+ require_relative 'rubocop/cop/layout/trailing_empty_lines'
276
279
  require_relative 'rubocop/cop/layout/trailing_whitespace'
277
280
 
278
281
  require_relative 'rubocop/cop/lint/ambiguous_block_association'
@@ -286,8 +289,8 @@ require_relative 'rubocop/cop/lint/debugger'
286
289
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
287
290
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
288
291
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
292
+ require_relative 'rubocop/cop/lint/duplicate_hash_key'
289
293
  require_relative 'rubocop/cop/lint/duplicate_methods'
290
- require_relative 'rubocop/cop/lint/duplicated_key'
291
294
  require_relative 'rubocop/cop/lint/each_with_object_argument'
292
295
  require_relative 'rubocop/cop/lint/else_layout'
293
296
  require_relative 'rubocop/cop/lint/empty_ensure'
@@ -300,7 +303,6 @@ require_relative 'rubocop/cop/lint/erb_new_arguments'
300
303
  require_relative 'rubocop/cop/lint/flip_flop'
301
304
  require_relative 'rubocop/cop/lint/float_out_of_range'
302
305
  require_relative 'rubocop/cop/lint/format_parameter_mismatch'
303
- require_relative 'rubocop/cop/lint/handle_exceptions'
304
306
  require_relative 'rubocop/cop/lint/heredoc_method_call_position'
305
307
  require_relative 'rubocop/cop/lint/implicit_string_concatenation'
306
308
  require_relative 'rubocop/cop/lint/inherit_exception'
@@ -310,10 +312,11 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
310
312
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
311
313
  require_relative 'rubocop/cop/lint/loop'
312
314
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
313
- require_relative 'rubocop/cop/lint/multiple_compare'
315
+ require_relative 'rubocop/cop/lint/multiple_comparison'
314
316
  require_relative 'rubocop/cop/lint/nested_method_definition'
315
317
  require_relative 'rubocop/cop/lint/nested_percent_literal'
316
318
  require_relative 'rubocop/cop/lint/next_without_accumulator'
319
+ require_relative 'rubocop/cop/lint/non_deterministic_require_order'
317
320
  require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
318
321
  require_relative 'rubocop/cop/lint/number_conversion'
319
322
  require_relative 'rubocop/cop/lint/ordered_magic_comments'
@@ -321,6 +324,11 @@ require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
321
324
  require_relative 'rubocop/cop/lint/percent_string_array'
322
325
  require_relative 'rubocop/cop/lint/percent_symbol_array'
323
326
  require_relative 'rubocop/cop/lint/rand_one'
327
+ require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
328
+ require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
329
+ require_relative 'rubocop/cop/lint/redundant_require_statement'
330
+ require_relative 'rubocop/cop/lint/redundant_splat_expansion'
331
+ require_relative 'rubocop/cop/lint/redundant_string_coercion'
324
332
  require_relative 'rubocop/cop/lint/redundant_with_index'
325
333
  require_relative 'rubocop/cop/lint/redundant_with_object'
326
334
  require_relative 'rubocop/cop/lint/regexp_as_condition'
@@ -336,15 +344,11 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
336
344
  require_relative 'rubocop/cop/lint/shadowed_argument'
337
345
  require_relative 'rubocop/cop/lint/shadowed_exception'
338
346
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
339
- require_relative 'rubocop/cop/lint/string_conversion_in_interpolation'
347
+ require_relative 'rubocop/cop/lint/suppressed_exception'
340
348
  require_relative 'rubocop/cop/lint/syntax'
341
349
  require_relative 'rubocop/cop/lint/to_json'
342
350
  require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
343
351
  require_relative 'rubocop/cop/lint/unified_integer'
344
- require_relative 'rubocop/cop/lint/unneeded_cop_disable_directive'
345
- require_relative 'rubocop/cop/lint/unneeded_cop_enable_directive'
346
- require_relative 'rubocop/cop/lint/unneeded_require_statement'
347
- require_relative 'rubocop/cop/lint/unneeded_splat_expansion'
348
352
  require_relative 'rubocop/cop/lint/unreachable_code'
349
353
  require_relative 'rubocop/cop/lint/unused_block_argument'
350
354
  require_relative 'rubocop/cop/lint/unused_method_argument'
@@ -364,7 +368,6 @@ require_relative 'rubocop/cop/metrics/abc_size'
364
368
  require_relative 'rubocop/cop/metrics/block_length'
365
369
  require_relative 'rubocop/cop/metrics/block_nesting'
366
370
  require_relative 'rubocop/cop/metrics/class_length'
367
- require_relative 'rubocop/cop/metrics/line_length'
368
371
  require_relative 'rubocop/cop/metrics/method_length'
369
372
  require_relative 'rubocop/cop/metrics/module_length'
370
373
  require_relative 'rubocop/cop/metrics/parameter_lists'
@@ -372,6 +375,7 @@ require_relative 'rubocop/cop/metrics/perceived_complexity'
372
375
 
373
376
  require_relative 'rubocop/cop/naming/accessor_method_name'
374
377
  require_relative 'rubocop/cop/naming/ascii_identifiers'
378
+ require_relative 'rubocop/cop/naming/block_parameter_name'
375
379
  require_relative 'rubocop/cop/naming/class_and_module_camel_case'
376
380
  require_relative 'rubocop/cop/naming/constant_name'
377
381
  require_relative 'rubocop/cop/naming/file_name'
@@ -379,11 +383,10 @@ require_relative 'rubocop/cop/naming/heredoc_delimiter_case'
379
383
  require_relative 'rubocop/cop/naming/heredoc_delimiter_naming'
380
384
  require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
381
385
  require_relative 'rubocop/cop/naming/method_name'
386
+ require_relative 'rubocop/cop/naming/method_parameter_name'
382
387
  require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
383
388
  require_relative 'rubocop/cop/naming/predicate_name'
384
389
  require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
385
- require_relative 'rubocop/cop/naming/uncommunicative_block_param_name'
386
- require_relative 'rubocop/cop/naming/uncommunicative_method_param_name'
387
390
  require_relative 'rubocop/cop/naming/variable_name'
388
391
  require_relative 'rubocop/cop/naming/variable_number'
389
392
 
@@ -502,12 +505,17 @@ require_relative 'rubocop/cop/style/proc'
502
505
  require_relative 'rubocop/cop/style/raise_args'
503
506
  require_relative 'rubocop/cop/style/random_with_offset'
504
507
  require_relative 'rubocop/cop/style/redundant_begin'
508
+ require_relative 'rubocop/cop/style/redundant_capital_w'
509
+ require_relative 'rubocop/cop/style/redundant_condition'
505
510
  require_relative 'rubocop/cop/style/redundant_conditional'
506
511
  require_relative 'rubocop/cop/style/redundant_exception'
507
512
  require_relative 'rubocop/cop/style/redundant_freeze'
513
+ require_relative 'rubocop/cop/style/redundant_interpolation'
508
514
  require_relative 'rubocop/cop/style/redundant_parentheses'
515
+ require_relative 'rubocop/cop/style/redundant_percent_q'
509
516
  require_relative 'rubocop/cop/style/redundant_return'
510
517
  require_relative 'rubocop/cop/style/redundant_self'
518
+ require_relative 'rubocop/cop/style/redundant_sort'
511
519
  require_relative 'rubocop/cop/style/redundant_sort_by'
512
520
  require_relative 'rubocop/cop/style/regexp_literal'
513
521
  require_relative 'rubocop/cop/style/rescue_modifier'
@@ -544,11 +552,6 @@ require_relative 'rubocop/cop/style/trailing_method_end_statement'
544
552
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
545
553
  require_relative 'rubocop/cop/style/trivial_accessors'
546
554
  require_relative 'rubocop/cop/style/unless_else'
547
- require_relative 'rubocop/cop/style/unneeded_capital_w'
548
- require_relative 'rubocop/cop/style/unneeded_condition'
549
- require_relative 'rubocop/cop/style/unneeded_interpolation'
550
- require_relative 'rubocop/cop/style/unneeded_percent_q'
551
- require_relative 'rubocop/cop/style/unneeded_sort'
552
555
  require_relative 'rubocop/cop/style/unpack_first'
553
556
  require_relative 'rubocop/cop/style/variable_interpolation'
554
557
  require_relative 'rubocop/cop/style/when_then'
@@ -603,6 +606,14 @@ require_relative 'rubocop/processed_source'
603
606
  require_relative 'rubocop/result_cache'
604
607
  require_relative 'rubocop/runner'
605
608
  require_relative 'rubocop/cli'
609
+ require_relative 'rubocop/cli/command'
610
+ require_relative 'rubocop/cli/environment'
611
+ require_relative 'rubocop/cli/command/base'
612
+ require_relative 'rubocop/cli/command/auto_genenerate_config'
613
+ require_relative 'rubocop/cli/command/execute_runner'
614
+ require_relative 'rubocop/cli/command/init_dotfile'
615
+ require_relative 'rubocop/cli/command/show_cops'
616
+ require_relative 'rubocop/cli/command/version'
606
617
  require_relative 'rubocop/options'
607
618
  require_relative 'rubocop/remote_config'
608
619
  require_relative 'rubocop/yaml_duplication_checker'
@@ -41,6 +41,7 @@ module RuboCop
41
41
  regexp: RegexpNode,
42
42
  resbody: ResbodyNode,
43
43
  retry: RetryNode,
44
+ return: ReturnNode,
44
45
  csend: SendNode,
45
46
  send: SendNode,
46
47
  str: StrNode,
@@ -469,6 +469,10 @@ module RuboCop
469
469
  parent&.send_type? && parent.arguments.include?(self)
470
470
  end
471
471
 
472
+ def boolean_type?
473
+ true_type? || false_type?
474
+ end
475
+
472
476
  def numeric_type?
473
477
  int_type? || float_type?
474
478
  end
@@ -620,7 +624,7 @@ module RuboCop
620
624
  end
621
625
 
622
626
  def parent_module_name_for_block(ancestor)
623
- if ancestor.method_name == :class_eval
627
+ if ancestor.method?(:class_eval)
624
628
  # `class_eval` with no receiver applies to whatever module or class
625
629
  # we are currently in
626
630
  return unless (receiver = ancestor.receiver)
@@ -9,6 +9,8 @@ module RuboCop
9
9
  # A `block` node is essentially a method send with a block. Parser nests
10
10
  # the `send` node inside the `block` node.
11
11
  class BlockNode < Node
12
+ include MethodIdentifierPredicates
13
+
12
14
  VOID_CONTEXT_METHODS = %i[each tap].freeze
13
15
 
14
16
  # The `send` node associated with this block.
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `return` nodes. This will be used in place of a
6
+ # plain node when the builder constructs the AST, making its methods
7
+ # available to all `return` nodes within RuboCop.
8
+ class ReturnNode < Node
9
+ include MethodDispatchNode
10
+ include ParameterizedNode
11
+
12
+ # Returns the arguments of the `return`.
13
+ #
14
+ # @return [Array] The arguments of the `return`.
15
+ def arguments
16
+ if node_parts.one? && node_parts.first.begin_type?
17
+ node_parts.first.children
18
+ else
19
+ node_parts
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,20 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
4
3
  module RuboCop
5
4
  # The CLI is a class responsible of handling all the command line interface
6
5
  # logic.
7
6
  class CLI
8
- include Formatter::TextUtil
9
-
10
- PHASE_1 = 'Phase 1 of 2: run Metrics/LineLength cop'
11
- PHASE_2 = 'Phase 2 of 2: run all cops'
12
-
13
- PHASE_1_OVERRIDDEN = '(skipped because the default Metrics/LineLength:Max' \
14
- ' is overridden)'
15
- PHASE_1_DISABLED = '(skipped because Metrics/LineLength is ' \
16
- 'disabled)'
17
-
18
7
  STATUS_SUCCESS = 0
19
8
  STATUS_OFFENSES = 1
20
9
  STATUS_ERROR = 2
@@ -41,14 +30,15 @@ module RuboCop
41
30
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
42
31
  def run(args = ARGV)
43
32
  @options, paths = Options.new.parse(args)
33
+ @env = Environment.new(@options, @config_store, paths)
44
34
 
45
35
  if @options[:init]
46
- init_dotfile
36
+ run_command(:init)
47
37
  else
48
38
  validate_options_vs_config
49
39
  act_on_options
50
40
  apply_default_formatter
51
- execute_runners(paths)
41
+ execute_runners
52
42
  end
53
43
  rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
54
44
  warn e.message
@@ -71,110 +61,18 @@ module RuboCop
71
61
 
72
62
  private
73
63
 
74
- def execute_runners(paths)
75
- if @options[:auto_gen_config]
76
- reset_config_and_auto_gen_file
77
- line_length_contents = maybe_run_line_length_cop(paths)
78
- run_all_cops_auto_gen_config(line_length_contents, paths)
79
- else
80
- execute_runner(paths)
81
- end
82
- end
83
-
84
- def maybe_run_line_length_cop(paths)
85
- if !line_length_enabled?(@config_store.for(Dir.pwd))
86
- puts Rainbow("#{PHASE_1} #{PHASE_1_DISABLED}").yellow
87
- ''
88
- elsif !same_max_line_length?(
89
- @config_store.for(Dir.pwd), ConfigLoader.default_configuration
90
- )
91
- puts Rainbow("#{PHASE_1} #{PHASE_1_OVERRIDDEN}").yellow
92
- ''
93
- else
94
- run_line_length_cop_auto_gen_config(paths)
95
- end
96
- end
97
-
98
- def line_length_enabled?(config)
99
- line_length_cop(config)['Enabled']
100
- end
101
-
102
- def same_max_line_length?(config1, config2)
103
- max_line_length(config1) == max_line_length(config2)
104
- end
105
-
106
- def max_line_length(config)
107
- line_length_cop(config)['Max']
108
- end
109
-
110
- def line_length_cop(config)
111
- config.for_cop('Metrics/LineLength')
64
+ def run_command(name)
65
+ @env.run(name)
112
66
  end
113
67
 
114
- # Do an initial run with only Metrics/LineLength so that cops that depend
115
- # on Metrics/LineLength:Max get the correct value for that parameter.
116
- def run_line_length_cop_auto_gen_config(paths)
117
- puts Rainbow(PHASE_1).yellow
118
- @options[:only] = ['Metrics/LineLength']
119
- execute_runner(paths)
120
- @options.delete(:only)
121
- @config_store = ConfigStore.new
122
- # Save the todo configuration of the LineLength cop.
123
- IO.read(ConfigLoader::AUTO_GENERATED_FILE)
124
- .lines
125
- .drop_while { |line| line.start_with?('#') }
126
- .join
127
- end
128
-
129
- def run_all_cops_auto_gen_config(line_length_contents, paths)
130
- puts Rainbow(PHASE_2).yellow
131
- result = execute_runner(paths)
132
- # This run was made with the current maximum length allowed, so append
133
- # the saved setting for LineLength.
134
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'a') do |f|
135
- f.write(line_length_contents)
136
- end
137
- result
138
- end
139
-
140
- def init_dotfile
141
- path = File.expand_path(ConfigLoader::DOTFILE)
142
-
143
- if File.exist?(ConfigLoader::DOTFILE)
144
- warn Rainbow("#{ConfigLoader::DOTFILE} already exists at #{path}").red
145
-
146
- STATUS_ERROR
68
+ def execute_runners
69
+ if @options[:auto_gen_config]
70
+ run_command(:auto_gen_config)
147
71
  else
148
- description = <<~DESC
149
- # The behavior of RuboCop can be controlled via the .rubocop.yml
150
- # configuration file. It makes it possible to enable/disable
151
- # certain cops (checks) and to alter their behavior if they accept
152
- # any parameters. The file can be placed either in your home
153
- # directory or in some project directory.
154
- #
155
- # RuboCop will start looking for the configuration file in the directory
156
- # where the inspected file is and continue its way up to the root directory.
157
- #
158
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
159
- DESC
160
-
161
- File.open(ConfigLoader::DOTFILE, 'w') do |f|
162
- f.write(description)
163
- end
164
-
165
- puts "Writing new #{ConfigLoader::DOTFILE} to #{path}"
166
-
167
- STATUS_SUCCESS
72
+ run_command(:execute_runner)
168
73
  end
169
74
  end
170
75
 
171
- def reset_config_and_auto_gen_file
172
- @config_store = ConfigStore.new
173
- @config_store.options_config = @options[:config] if @options[:config]
174
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'w') {}
175
- ConfigLoader.add_inheritance_from_auto_generated_file
176
- end
177
-
178
76
  def validate_options_vs_config
179
77
  if @options[:parallel] &&
180
78
  !@config_store.for(Dir.pwd).for_all_cops['UseCache']
@@ -204,31 +102,11 @@ module RuboCop
204
102
  end
205
103
  end
206
104
 
207
- def execute_runner(paths)
208
- runner = Runner.new(@options, @config_store)
209
-
210
- all_passed = runner.run(paths)
211
- display_warning_summary(runner.warnings)
212
- display_error_summary(runner.errors)
213
- maybe_print_corrected_source
214
-
215
- all_pass_or_excluded = all_passed || @options[:auto_gen_config]
216
-
217
- if runner.aborting?
218
- STATUS_INTERRUPTED
219
- elsif all_pass_or_excluded && runner.errors.empty?
220
- STATUS_SUCCESS
221
- else
222
- STATUS_OFFENSES
223
- end
224
- end
225
-
226
105
  def handle_exiting_options
227
106
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
228
107
 
229
- puts RuboCop::Version.version(false) if @options[:version]
230
- puts RuboCop::Version.version(true) if @options[:verbose_version]
231
- print_available_cops if @options[:show_cops]
108
+ run_command(:version) if @options[:version] || @options[:verbose_version]
109
+ run_command(:show_cops) if @options[:show_cops]
232
110
  raise Finished
233
111
  end
234
112
 
@@ -244,100 +122,6 @@ module RuboCop
244
122
  end
245
123
  [[formatter, @options[:output_path]]]
246
124
  end
247
-
248
- return unless @options[:auto_gen_config]
249
-
250
- @options[:formatters] << [Formatter::DisabledConfigFormatter,
251
- ConfigLoader::AUTO_GENERATED_FILE]
252
- end
253
-
254
- def print_available_cops
255
- # Load the configs so the require()s are done for custom cops
256
- @config_store.for(Dir.pwd)
257
- registry = Cop::Cop.registry
258
- show_all = @options[:show_cops].empty?
259
-
260
- if show_all
261
- puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: "
262
- end
263
-
264
- registry.departments.sort!.each do |department|
265
- print_cops_of_department(registry, department, show_all)
266
- end
267
- end
268
-
269
- def print_cops_of_department(registry, department, show_all)
270
- selected_cops = if show_all
271
- cops_of_department(registry, department)
272
- else
273
- selected_cops_of_department(registry, department)
274
- end
275
-
276
- puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
277
-
278
- print_cop_details(selected_cops)
279
- end
280
-
281
- def print_cop_details(cops)
282
- cops.each do |cop|
283
- puts '# Supports --auto-correct' if cop.new.support_autocorrect?
284
- puts "#{cop.cop_name}:"
285
- puts config_lines(cop)
286
- puts
287
- end
288
- end
289
-
290
- def selected_cops_of_department(cops, department)
291
- cops_of_department(cops, department).select do |cop|
292
- @options[:show_cops].include?(cop.cop_name)
293
- end
294
- end
295
-
296
- def cops_of_department(cops, department)
297
- cops.with_department(department).sort!
298
- end
299
-
300
- def config_lines(cop)
301
- cnf = @config_store.for(Dir.pwd).for_cop(cop)
302
- cnf.to_yaml.lines.to_a.drop(1).map { |line| ' ' + line }
303
- end
304
-
305
- def display_warning_summary(warnings)
306
- return if warnings.empty?
307
-
308
- warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
309
-
310
- warnings.each { |warning| warn warning }
311
- end
312
-
313
- def display_error_summary(errors)
314
- return if errors.empty?
315
-
316
- warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
317
-
318
- errors.each { |error| warn error }
319
-
320
- warn <<~WARNING
321
- Errors are usually caused by RuboCop bugs.
322
- Please, report your problems to RuboCop's issue tracker.
323
- #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
324
-
325
- Mention the following information in the issue report:
326
- #{RuboCop::Version.version(true)}
327
- WARNING
328
- end
329
-
330
- def maybe_print_corrected_source
331
- # If we are asked to autocorrect source code read from stdin, the only
332
- # reasonable place to write it is to stdout
333
- # Unfortunately, we also write other information to stdout
334
- # So a delimiter is needed for tools to easily identify where the
335
- # autocorrected source begins
336
- return unless @options[:stdin] && @options[:auto_correct]
337
-
338
- puts '=' * 20
339
- print @options[:stdin]
340
125
  end
341
126
  end
342
127
  end
343
- # rubocop:enable Metrics/ClassLength