rubocop 0.78.0 → 0.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +4 -4
  4. data/config/default.yml +158 -48
  5. data/lib/rubocop.rb +19 -4
  6. data/lib/rubocop/ast/builder.rb +45 -42
  7. data/lib/rubocop/ast/node.rb +12 -19
  8. data/lib/rubocop/ast/node/array_node.rb +13 -0
  9. data/lib/rubocop/ast/node/block_node.rb +5 -1
  10. data/lib/rubocop/ast/node/case_match_node.rb +56 -0
  11. data/lib/rubocop/ast/node/def_node.rb +11 -0
  12. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  13. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +8 -0
  14. data/lib/rubocop/ast/node/regexp_node.rb +2 -4
  15. data/lib/rubocop/ast/traversal.rb +29 -10
  16. data/lib/rubocop/cli.rb +10 -4
  17. data/lib/rubocop/cli/command/show_cops.rb +11 -4
  18. data/lib/rubocop/comment_config.rb +6 -1
  19. data/lib/rubocop/config.rb +36 -10
  20. data/lib/rubocop/config_loader.rb +42 -33
  21. data/lib/rubocop/config_loader_resolver.rb +1 -1
  22. data/lib/rubocop/config_obsoletion.rb +4 -1
  23. data/lib/rubocop/config_validator.rb +66 -92
  24. data/lib/rubocop/cop/autocorrect_logic.rb +6 -3
  25. data/lib/rubocop/cop/badge.rb +5 -5
  26. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  27. data/lib/rubocop/cop/corrector.rb +48 -24
  28. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
  29. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
  30. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
  31. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
  32. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  33. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  34. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
  35. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  36. data/lib/rubocop/cop/generator.rb +3 -4
  37. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  38. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
  39. data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
  40. data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
  41. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  42. data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
  43. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  44. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  45. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +16 -10
  46. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  47. data/lib/rubocop/cop/layout/hash_alignment.rb +8 -4
  48. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  49. data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
  50. data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
  51. data/lib/rubocop/cop/layout/leading_comment_space.rb +34 -3
  52. data/lib/rubocop/cop/layout/line_length.rb +32 -3
  53. data/lib/rubocop/cop/layout/multiline_block_layout.rb +15 -6
  54. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
  55. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  56. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
  57. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +133 -0
  58. data/lib/rubocop/cop/layout/space_around_operators.rb +19 -1
  59. data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -2
  60. data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
  61. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  62. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  63. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
  64. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
  65. data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
  66. data/lib/rubocop/cop/lint/debugger.rb +2 -2
  67. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  68. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  69. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  70. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
  71. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  72. data/lib/rubocop/cop/lint/loop.rb +6 -4
  73. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
  74. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  75. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  76. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  77. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
  78. data/lib/rubocop/cop/lint/raise_exception.rb +75 -0
  79. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -1
  80. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +12 -7
  81. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  82. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  83. data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
  84. data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -22
  85. data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
  86. data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
  87. data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
  88. data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -0
  89. data/lib/rubocop/cop/migration/department_name.rb +47 -6
  90. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
  91. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
  92. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
  93. data/lib/rubocop/cop/mixin/hash_transform_method.rb +171 -0
  94. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
  95. data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
  96. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -3
  97. data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -10
  98. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  99. data/lib/rubocop/cop/naming/constant_name.rb +2 -1
  100. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  101. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  102. data/lib/rubocop/cop/naming/method_name.rb +30 -0
  103. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  104. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  105. data/lib/rubocop/cop/registry.rb +15 -3
  106. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
  107. data/lib/rubocop/cop/style/alias.rb +4 -4
  108. data/lib/rubocop/cop/style/and_or.rb +5 -6
  109. data/lib/rubocop/cop/style/array_join.rb +1 -1
  110. data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
  111. data/lib/rubocop/cop/style/case_equality.rb +24 -1
  112. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  113. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  114. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
  115. data/lib/rubocop/cop/style/copyright.rb +1 -1
  116. data/lib/rubocop/cop/style/dir.rb +1 -1
  117. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
  118. data/lib/rubocop/cop/style/documentation.rb +43 -5
  119. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
  120. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  121. data/lib/rubocop/cop/style/each_with_object.rb +3 -3
  122. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  123. data/lib/rubocop/cop/style/end_block.rb +6 -0
  124. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  125. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  126. data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
  127. data/lib/rubocop/cop/style/format_string.rb +2 -2
  128. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
  129. data/lib/rubocop/cop/style/hash_each_methods.rb +89 -0
  130. data/lib/rubocop/cop/style/hash_syntax.rb +3 -5
  131. data/lib/rubocop/cop/style/hash_transform_keys.rb +83 -0
  132. data/lib/rubocop/cop/style/hash_transform_values.rb +80 -0
  133. data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
  134. data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
  135. data/lib/rubocop/cop/style/lambda.rb +3 -2
  136. data/lib/rubocop/cop/style/lambda_call.rb +2 -2
  137. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
  138. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
  139. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  140. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  141. data/lib/rubocop/cop/style/module_function.rb +58 -12
  142. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  143. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  144. data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
  145. data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
  146. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -4
  147. data/lib/rubocop/cop/style/next.rb +2 -2
  148. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  149. data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
  150. data/lib/rubocop/cop/style/not.rb +1 -1
  151. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  152. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  153. data/lib/rubocop/cop/style/numeric_predicate.rb +5 -4
  154. data/lib/rubocop/cop/style/one_line_conditional.rb +4 -3
  155. data/lib/rubocop/cop/style/or_assignment.rb +4 -3
  156. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  157. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  158. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  159. data/lib/rubocop/cop/style/proc.rb +1 -1
  160. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  161. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  162. data/lib/rubocop/cop/style/redundant_condition.rb +18 -6
  163. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  164. data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
  165. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  166. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  167. data/lib/rubocop/cop/style/redundant_return.rb +5 -7
  168. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  169. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  170. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  171. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  172. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  173. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  174. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  175. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
  176. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
  177. data/lib/rubocop/cop/style/symbol_array.rb +3 -3
  178. data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
  179. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
  180. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +35 -22
  181. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
  182. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +88 -0
  183. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
  184. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  185. data/lib/rubocop/cop/style/unpack_first.rb +0 -4
  186. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  187. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  188. data/lib/rubocop/cop/style/word_array.rb +1 -1
  189. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  190. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
  191. data/lib/rubocop/cop/variable_force.rb +4 -1
  192. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  193. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  194. data/lib/rubocop/formatter/junit_formatter.rb +74 -0
  195. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  196. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  197. data/lib/rubocop/node_pattern.rb +96 -10
  198. data/lib/rubocop/options.rb +7 -1
  199. data/lib/rubocop/processed_source.rb +1 -4
  200. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  201. data/lib/rubocop/rspec/expect_offense.rb +1 -1
  202. data/lib/rubocop/rspec/shared_contexts.rb +5 -4
  203. data/lib/rubocop/runner.rb +1 -1
  204. data/lib/rubocop/target_ruby.rb +151 -0
  205. data/lib/rubocop/version.rb +1 -1
  206. metadata +39 -12
  207. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  208. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
  209. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
@@ -37,12 +37,14 @@ require_relative 'rubocop/ast/node/args_node'
37
37
  require_relative 'rubocop/ast/node/array_node'
38
38
  require_relative 'rubocop/ast/node/block_node'
39
39
  require_relative 'rubocop/ast/node/break_node'
40
+ require_relative 'rubocop/ast/node/case_match_node'
40
41
  require_relative 'rubocop/ast/node/case_node'
41
42
  require_relative 'rubocop/ast/node/class_node'
42
43
  require_relative 'rubocop/ast/node/def_node'
43
44
  require_relative 'rubocop/ast/node/defined_node'
44
45
  require_relative 'rubocop/ast/node/ensure_node'
45
46
  require_relative 'rubocop/ast/node/for_node'
47
+ require_relative 'rubocop/ast/node/forward_args_node'
46
48
  require_relative 'rubocop/ast/node/float_node'
47
49
  require_relative 'rubocop/ast/node/hash_node'
48
50
  require_relative 'rubocop/ast/node/if_node'
@@ -119,6 +121,7 @@ require_relative 'rubocop/cop/mixin/enforce_superclass'
119
121
  require_relative 'rubocop/cop/mixin/first_element_line_break'
120
122
  require_relative 'rubocop/cop/mixin/frozen_string_literal'
121
123
  require_relative 'rubocop/cop/mixin/hash_alignment_styles'
124
+ require_relative 'rubocop/cop/mixin/hash_transform_method'
122
125
  require_relative 'rubocop/cop/mixin/ignored_pattern'
123
126
  require_relative 'rubocop/cop/mixin/ignored_methods'
124
127
  require_relative 'rubocop/cop/mixin/integer_node'
@@ -232,6 +235,7 @@ require_relative 'rubocop/cop/layout/hash_alignment'
232
235
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
233
236
  require_relative 'rubocop/cop/layout/heredoc_indentation'
234
237
  require_relative 'rubocop/cop/layout/indentation_consistency'
238
+ require_relative 'rubocop/cop/layout/indentation_style'
235
239
  require_relative 'rubocop/cop/layout/indentation_width'
236
240
  require_relative 'rubocop/cop/layout/initial_indentation'
237
241
  require_relative 'rubocop/cop/layout/leading_comment_space'
@@ -258,6 +262,7 @@ require_relative 'rubocop/cop/layout/space_after_semicolon'
258
262
  require_relative 'rubocop/cop/layout/space_around_block_parameters'
259
263
  require_relative 'rubocop/cop/layout/space_around_equals_in_parameter_default'
260
264
  require_relative 'rubocop/cop/layout/space_around_keyword'
265
+ require_relative 'rubocop/cop/layout/space_around_method_call_operator'
261
266
  require_relative 'rubocop/cop/layout/space_around_operators'
262
267
  require_relative 'rubocop/cop/layout/space_before_block_braces'
263
268
  require_relative 'rubocop/cop/layout/space_before_comma'
@@ -274,7 +279,6 @@ require_relative 'rubocop/cop/layout/space_inside_percent_literal_delimiters'
274
279
  require_relative 'rubocop/cop/layout/space_inside_range_literal'
275
280
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
276
281
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
277
- require_relative 'rubocop/cop/layout/tab'
278
282
  require_relative 'rubocop/cop/layout/trailing_empty_lines'
279
283
  require_relative 'rubocop/cop/layout/trailing_whitespace'
280
284
 
@@ -297,7 +301,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
297
301
  require_relative 'rubocop/cop/lint/empty_expression'
298
302
  require_relative 'rubocop/cop/lint/empty_interpolation'
299
303
  require_relative 'rubocop/cop/lint/empty_when'
300
- require_relative 'rubocop/cop/lint/end_in_method'
301
304
  require_relative 'rubocop/cop/lint/ensure_return'
302
305
  require_relative 'rubocop/cop/lint/erb_new_arguments'
303
306
  require_relative 'rubocop/cop/lint/flip_flop'
@@ -323,6 +326,7 @@ require_relative 'rubocop/cop/lint/ordered_magic_comments'
323
326
  require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
324
327
  require_relative 'rubocop/cop/lint/percent_string_array'
325
328
  require_relative 'rubocop/cop/lint/percent_symbol_array'
329
+ require_relative 'rubocop/cop/lint/raise_exception'
326
330
  require_relative 'rubocop/cop/lint/rand_one'
327
331
  require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
328
332
  require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
@@ -344,6 +348,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
344
348
  require_relative 'rubocop/cop/lint/shadowed_argument'
345
349
  require_relative 'rubocop/cop/lint/shadowed_exception'
346
350
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
351
+ require_relative 'rubocop/cop/lint/struct_new_override'
347
352
  require_relative 'rubocop/cop/lint/suppressed_exception'
348
353
  require_relative 'rubocop/cop/lint/syntax'
349
354
  require_relative 'rubocop/cop/lint/to_json'
@@ -401,7 +406,6 @@ require_relative 'rubocop/cop/style/bare_percent_literals'
401
406
  require_relative 'rubocop/cop/style/begin_block'
402
407
  require_relative 'rubocop/cop/style/block_comments'
403
408
  require_relative 'rubocop/cop/style/block_delimiters'
404
- require_relative 'rubocop/cop/style/braces_around_hash_parameters'
405
409
  require_relative 'rubocop/cop/style/case_equality'
406
410
  require_relative 'rubocop/cop/style/character_literal'
407
411
  require_relative 'rubocop/cop/style/class_and_module_children'
@@ -420,6 +424,7 @@ require_relative 'rubocop/cop/style/copyright'
420
424
  require_relative 'rubocop/cop/style/date_time'
421
425
  require_relative 'rubocop/cop/style/def_with_parentheses'
422
426
  require_relative 'rubocop/cop/style/dir'
427
+ require_relative 'rubocop/cop/style/disable_cops_within_source_code_directive'
423
428
  require_relative 'rubocop/cop/style/documentation_method'
424
429
  require_relative 'rubocop/cop/style/documentation'
425
430
  require_relative 'rubocop/cop/style/double_cop_disable_directive'
@@ -437,6 +442,7 @@ require_relative 'rubocop/cop/style/end_block'
437
442
  require_relative 'rubocop/cop/style/eval_with_location'
438
443
  require_relative 'rubocop/cop/style/even_odd'
439
444
  require_relative 'rubocop/cop/style/expand_path_arguments'
445
+ require_relative 'rubocop/cop/style/exponential_notation'
440
446
  require_relative 'rubocop/cop/style/float_division'
441
447
  require_relative 'rubocop/cop/style/for'
442
448
  require_relative 'rubocop/cop/style/format_string'
@@ -444,7 +450,10 @@ require_relative 'rubocop/cop/style/format_string_token'
444
450
  require_relative 'rubocop/cop/style/frozen_string_literal_comment'
445
451
  require_relative 'rubocop/cop/style/global_vars'
446
452
  require_relative 'rubocop/cop/style/guard_clause'
453
+ require_relative 'rubocop/cop/style/hash_each_methods'
447
454
  require_relative 'rubocop/cop/style/hash_syntax'
455
+ require_relative 'rubocop/cop/style/hash_transform_keys'
456
+ require_relative 'rubocop/cop/style/hash_transform_values'
448
457
  require_relative 'rubocop/cop/style/identical_conditional_branches'
449
458
  require_relative 'rubocop/cop/style/if_inside_else'
450
459
  require_relative 'rubocop/cop/style/if_unless_modifier'
@@ -459,7 +468,11 @@ require_relative 'rubocop/cop/style/lambda'
459
468
  require_relative 'rubocop/cop/style/lambda_call'
460
469
  require_relative 'rubocop/cop/style/line_end_concatenation'
461
470
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
471
+ # rubocop:disable Layout/LineLength
462
472
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
473
+ require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
474
+ require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
475
+ # rubocop:enable Layout/LineLength
463
476
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
464
477
  require_relative 'rubocop/cop/style/method_def_parentheses'
465
478
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -547,6 +560,7 @@ require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
547
560
  require_relative 'rubocop/cop/style/trailing_body_on_module'
548
561
  require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
549
562
  require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
563
+ require_relative 'rubocop/cop/style/trailing_comma_in_block_args'
550
564
  require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
551
565
  require_relative 'rubocop/cop/style/trailing_method_end_statement'
552
566
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
@@ -574,12 +588,12 @@ require_relative 'rubocop/formatter/simple_text_formatter'
574
588
  # relies on simple text
575
589
  require_relative 'rubocop/formatter/clang_style_formatter'
576
590
  require_relative 'rubocop/formatter/disabled_config_formatter'
577
- require_relative 'rubocop/formatter/disabled_lines_formatter'
578
591
  require_relative 'rubocop/formatter/emacs_style_formatter'
579
592
  require_relative 'rubocop/formatter/file_list_formatter'
580
593
  require_relative 'rubocop/formatter/fuubar_style_formatter'
581
594
  require_relative 'rubocop/formatter/html_formatter'
582
595
  require_relative 'rubocop/formatter/json_formatter'
596
+ require_relative 'rubocop/formatter/junit_formatter'
583
597
  require_relative 'rubocop/formatter/offense_count_formatter'
584
598
  require_relative 'rubocop/formatter/progress_formatter'
585
599
  require_relative 'rubocop/formatter/quiet_formatter'
@@ -616,4 +630,5 @@ require_relative 'rubocop/cli/command/show_cops'
616
630
  require_relative 'rubocop/cli/command/version'
617
631
  require_relative 'rubocop/options'
618
632
  require_relative 'rubocop/remote_config'
633
+ require_relative 'rubocop/target_ruby'
619
634
  require_relative 'rubocop/yaml_duplication_checker'
@@ -15,48 +15,51 @@ module RuboCop
15
15
  # root_node = parser.parse(buffer)
16
16
  class Builder < Parser::Builders::Default
17
17
  NODE_MAP = {
18
- and: AndNode,
19
- alias: AliasNode,
20
- args: ArgsNode,
21
- array: ArrayNode,
22
- block: BlockNode,
23
- break: BreakNode,
24
- case: CaseNode,
25
- class: ClassNode,
26
- def: DefNode,
27
- defined?: DefinedNode,
28
- defs: DefNode,
29
- ensure: EnsureNode,
30
- for: ForNode,
31
- float: FloatNode,
32
- hash: HashNode,
33
- if: IfNode,
34
- int: IntNode,
35
- irange: RangeNode,
36
- erange: RangeNode,
37
- kwsplat: KeywordSplatNode,
38
- module: ModuleNode,
39
- or: OrNode,
40
- pair: PairNode,
41
- regexp: RegexpNode,
42
- resbody: ResbodyNode,
43
- retry: RetryNode,
44
- return: ReturnNode,
45
- csend: SendNode,
46
- send: SendNode,
47
- str: StrNode,
48
- dstr: StrNode,
49
- xstr: StrNode,
50
- sclass: SelfClassNode,
51
- super: SuperNode,
52
- zsuper: SuperNode,
53
- sym: SymbolNode,
54
- until: UntilNode,
55
- until_post: UntilNode,
56
- when: WhenNode,
57
- while: WhileNode,
58
- while_post: WhileNode,
59
- yield: YieldNode
18
+ and: AndNode,
19
+ alias: AliasNode,
20
+ args: ArgsNode,
21
+ array: ArrayNode,
22
+ block: BlockNode,
23
+ numblock: BlockNode,
24
+ break: BreakNode,
25
+ case_match: CaseMatchNode,
26
+ case: CaseNode,
27
+ class: ClassNode,
28
+ def: DefNode,
29
+ defined?: DefinedNode,
30
+ defs: DefNode,
31
+ ensure: EnsureNode,
32
+ for: ForNode,
33
+ forward_args: ForwardArgsNode,
34
+ float: FloatNode,
35
+ hash: HashNode,
36
+ if: IfNode,
37
+ int: IntNode,
38
+ irange: RangeNode,
39
+ erange: RangeNode,
40
+ kwsplat: KeywordSplatNode,
41
+ module: ModuleNode,
42
+ or: OrNode,
43
+ pair: PairNode,
44
+ regexp: RegexpNode,
45
+ resbody: ResbodyNode,
46
+ retry: RetryNode,
47
+ return: ReturnNode,
48
+ csend: SendNode,
49
+ send: SendNode,
50
+ str: StrNode,
51
+ dstr: StrNode,
52
+ xstr: StrNode,
53
+ sclass: SelfClassNode,
54
+ super: SuperNode,
55
+ zsuper: SuperNode,
56
+ sym: SymbolNode,
57
+ until: UntilNode,
58
+ until_post: UntilNode,
59
+ when: WhenNode,
60
+ while: WhileNode,
61
+ while_post: WhileNode,
62
+ yield: YieldNode
60
63
  }.freeze
61
64
 
62
65
  # Generates {Node} from the given information.
@@ -98,7 +98,7 @@ module RuboCop
98
98
  @mutable_attributes.frozen?
99
99
  end
100
100
 
101
- protected :parent= # rubocop:disable Style/AccessModifierDeclarations
101
+ protected :parent=
102
102
 
103
103
  # Override `AST::Node#updated` so that `AST::Processor` does not try to
104
104
  # mutate our ASTs. Since we keep references from children to parents and
@@ -116,7 +116,7 @@ module RuboCop
116
116
  #
117
117
  # @return [Integer] the index of the receiver node in its siblings
118
118
  def sibling_index
119
- parent.children.index { |sibling| sibling.equal?(self) }
119
+ parent&.children&.index { |sibling| sibling.equal?(self) }
120
120
  end
121
121
 
122
122
  # Common destructuring method. This can be used to normalize
@@ -141,9 +141,6 @@ module RuboCop
141
141
  # Yield only nodes matching any of the types.
142
142
  # @param [Symbol] type_a a node type
143
143
  # @param [Symbol] type_b a node type
144
- # @overload each_ancestor(types)
145
- # Yield only nodes matching any of types in the array.
146
- # @param [Array<Symbol>] types an array containing node types
147
144
  # @yieldparam [Node] node each ancestor node
148
145
  # @return [self] if a block is given
149
146
  # @return [Enumerator] if no block is given
@@ -178,9 +175,6 @@ module RuboCop
178
175
  # Yield only nodes matching any of the types.
179
176
  # @param [Symbol] type_a a node type
180
177
  # @param [Symbol] type_b a node type
181
- # @overload each_child_node(types)
182
- # Yield only nodes matching any of types in the array.
183
- # @param [Array<Symbol>] types an array containing node types
184
178
  # @yieldparam [Node] node each child node
185
179
  # @return [self] if a block is given
186
180
  # @return [Enumerator] if no block is given
@@ -216,9 +210,6 @@ module RuboCop
216
210
  # Yield only nodes matching any of the types.
217
211
  # @param [Symbol] type_a a node type
218
212
  # @param [Symbol] type_b a node type
219
- # @overload each_descendant(types)
220
- # Yield only nodes matching any of types in the array.
221
- # @param [Array<Symbol>] types an array containing node types
222
213
  # @yieldparam [Node] node each descendant node
223
214
  # @return [self] if a block is given
224
215
  # @return [Enumerator] if no block is given
@@ -254,9 +245,6 @@ module RuboCop
254
245
  # Yield only nodes matching any of the types.
255
246
  # @param [Symbol] type_a a node type
256
247
  # @param [Symbol] type_b a node type
257
- # @overload each_node(types)
258
- # Yield only nodes matching any of types in the array.
259
- # @param [Array<Symbol>] types an array containing node types
260
248
  # @yieldparam [Node] node each node
261
249
  # @return [self] if a block is given
262
250
  # @return [Enumerator] if no block is given
@@ -303,7 +291,7 @@ module RuboCop
303
291
  ## Destructuring
304
292
 
305
293
  def_node_matcher :receiver, <<~PATTERN
306
- {(send $_ ...) (block (send $_ ...) ...)}
294
+ {(send $_ ...) ({block numblock} (send $_ ...) ...)}
307
295
  PATTERN
308
296
 
309
297
  def_node_matcher :str_content, '(str $_)'
@@ -325,9 +313,8 @@ module RuboCop
325
313
  (casgn $_ $_ (send (const nil? {:Class :Module}) :new ...))
326
314
  (casgn $_ $_ (block (send (const nil? {:Class :Module}) :new ...) ...))}
327
315
  PATTERN
328
- # rubocop:disable Style/AccessModifierDeclarations
316
+
329
317
  private :defined_module0
330
- # rubocop:enable Style/AccessModifierDeclarations
331
318
 
332
319
  def defined_module
333
320
  namespace, name = *defined_module0
@@ -481,7 +468,13 @@ module RuboCop
481
468
  irange_type? || erange_type?
482
469
  end
483
470
 
484
- def_node_matcher :guard_clause?, <<~PATTERN
471
+ def guard_clause?
472
+ node = and_type? || or_type? ? rhs : self
473
+
474
+ node.match_guard_clause?
475
+ end
476
+
477
+ def_node_matcher :match_guard_clause?, <<~PATTERN
485
478
  [${(send nil? {:raise :fail} ...) return break next} single_line?]
486
479
  PATTERN
487
480
 
@@ -491,7 +484,7 @@ module RuboCop
491
484
  (send (const nil? :Proc) :new)}
492
485
  PATTERN
493
486
 
494
- def_node_matcher :lambda?, '(block (send nil? :lambda) ...)'
487
+ def_node_matcher :lambda?, '({block numblock} (send nil? :lambda) ...)'
495
488
  def_node_matcher :lambda_or_proc?, '{lambda? proc?}'
496
489
 
497
490
  def_node_matcher :class_constructor?, <<~PATTERN
@@ -18,6 +18,19 @@ module RuboCop
18
18
  each_child_node.to_a
19
19
  end
20
20
 
21
+ # Calls the given block for all values in the `array` literal.
22
+ #
23
+ # @yieldparam [Node] node each node
24
+ # @return [self] if a block is given
25
+ # @return [Enumerator] if no block is given
26
+ def each_value(&block)
27
+ return to_enum(__method__) unless block_given?
28
+
29
+ values.each(&block)
30
+
31
+ self
32
+ end
33
+
21
34
  # Checks whether the `array` literal is delimited by square brackets.
22
35
  #
23
36
  # @return [Boolean] whether the array is enclosed in square brackets
@@ -24,7 +24,11 @@ module RuboCop
24
24
  #
25
25
  # @return [Array<Node>]
26
26
  def arguments
27
- node_parts[1]
27
+ if numblock_type?
28
+ [] # Numbered parameters have no block arguments.
29
+ else
30
+ node_parts[1]
31
+ end
28
32
  end
29
33
 
30
34
  # The body of this block.
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `case_match` nodes. This will be used in place of
6
+ # a plain node when the builder constructs the AST, making its methods
7
+ # available to all `case_match` nodes within RuboCop.
8
+ class CaseMatchNode < Node
9
+ include ConditionalNode
10
+
11
+ # Returns the keyword of the `case` statement as a string.
12
+ #
13
+ # @return [String] the keyword of the `case` statement
14
+ def keyword
15
+ 'case'
16
+ end
17
+
18
+ # Calls the given block for each `in_pattern` node in the `in` statement.
19
+ # If no block is given, an `Enumerator` is returned.
20
+ #
21
+ # @return [self] if a block is given
22
+ # @return [Enumerator] if no block is given
23
+ def each_in_pattern
24
+ return in_pattern_branches.to_enum(__method__) unless block_given?
25
+
26
+ in_pattern_branches.each do |condition|
27
+ yield condition
28
+ end
29
+
30
+ self
31
+ end
32
+
33
+ # Returns an array of all the when branches in the `case` statement.
34
+ #
35
+ # @return [Array<Node>] an array of `in_pattern` nodes
36
+ def in_pattern_branches
37
+ node_parts[1...-1]
38
+ end
39
+
40
+ # Returns the else branch of the `case` statement, if any.
41
+ #
42
+ # @return [Node] the else branch node of the `case` statement
43
+ # @return [nil] if the case statement does not have an else branch.
44
+ def else_branch
45
+ node_parts[-1]
46
+ end
47
+
48
+ # Checks whether this case statement has an `else` branch.
49
+ #
50
+ # @return [Boolean] whether the `case` statement has an `else` branch
51
+ def else?
52
+ !loc.else.nil?
53
+ end
54
+ end
55
+ end
56
+ end
@@ -16,6 +16,17 @@ module RuboCop
16
16
  method?(:initialize) || assignment_method?
17
17
  end
18
18
 
19
+ # Checks whether this method definition node forwards its arguments
20
+ # as per the feature added in Ruby 2.7.
21
+ #
22
+ # @note This is written in a way that may support lead arguments
23
+ # which are rumored to be added in a later version of Ruby.
24
+ #
25
+ # @return [Boolean] whether the `def` node uses argument forwarding
26
+ def argument_forwarding?
27
+ arguments.any?(&:forward_args_type?)
28
+ end
29
+
19
30
  # The name of the defined method as a symbol.
20
31
  #
21
32
  # @return [Symbol] the name of the defined method
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `forward-args` nodes. This will be used in place
6
+ # of a plain node when the builder constructs the AST, making its methods
7
+ # available to all `forward-args` nodes within RuboCop.
8
+ class ForwardArgsNode < Node
9
+ include CollectionNode
10
+
11
+ # Node wraps itself in an array to be compatible with other
12
+ # enumerable argument types.
13
+ def to_a
14
+ [self]
15
+ end
16
+ end
17
+ end
18
+ end