rubocop 0.77.0 → 0.81.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +3 -3
  4. data/config/default.yml +136 -60
  5. data/lib/rubocop.rb +20 -4
  6. data/lib/rubocop/ast/builder.rb +45 -42
  7. data/lib/rubocop/ast/node.rb +11 -18
  8. data/lib/rubocop/ast/node/block_node.rb +5 -1
  9. data/lib/rubocop/ast/node/case_match_node.rb +56 -0
  10. data/lib/rubocop/ast/node/def_node.rb +11 -0
  11. data/lib/rubocop/ast/node/forward_args_node.rb +18 -0
  12. data/lib/rubocop/ast/node/regexp_node.rb +2 -4
  13. data/lib/rubocop/ast/traversal.rb +29 -10
  14. data/lib/rubocop/cli/command/auto_genenerate_config.rb +7 -7
  15. data/lib/rubocop/cli/command/show_cops.rb +11 -4
  16. data/lib/rubocop/comment_config.rb +6 -1
  17. data/lib/rubocop/config.rb +28 -10
  18. data/lib/rubocop/config_loader.rb +19 -19
  19. data/lib/rubocop/config_obsoletion.rb +6 -4
  20. data/lib/rubocop/config_validator.rb +55 -95
  21. data/lib/rubocop/cop/autocorrect_logic.rb +7 -4
  22. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  23. data/lib/rubocop/cop/cop.rb +3 -1
  24. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  25. data/lib/rubocop/cop/generator.rb +3 -4
  26. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  27. data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
  28. data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
  29. data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
  30. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  31. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
  32. data/lib/rubocop/cop/layout/hash_alignment.rb +8 -4
  33. data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -4
  34. data/lib/rubocop/cop/layout/leading_comment_space.rb +33 -2
  35. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +35 -79
  36. data/lib/rubocop/cop/layout/multiline_block_layout.rb +14 -5
  37. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +0 -4
  38. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  39. data/lib/rubocop/cop/layout/space_around_operators.rb +49 -6
  40. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  41. data/lib/rubocop/cop/layout/space_before_first_arg.rb +8 -0
  42. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -9
  43. data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
  44. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  45. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  46. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  47. data/lib/rubocop/cop/lint/loop.rb +6 -4
  48. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  49. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  50. data/lib/rubocop/cop/lint/raise_exception.rb +39 -0
  51. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +3 -3
  52. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +13 -8
  53. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  54. data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
  55. data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -22
  56. data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
  57. data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -0
  58. data/lib/rubocop/cop/migration/department_name.rb +47 -6
  59. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  60. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +4 -0
  61. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
  62. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +7 -7
  63. data/lib/rubocop/cop/mixin/hash_transform_method.rb +171 -0
  64. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  65. data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
  66. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  67. data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
  68. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -12
  69. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  70. data/lib/rubocop/cop/naming/method_name.rb +30 -0
  71. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  72. data/lib/rubocop/cop/offense.rb +11 -0
  73. data/lib/rubocop/cop/registry.rb +7 -2
  74. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
  75. data/lib/rubocop/cop/style/attr.rb +8 -0
  76. data/lib/rubocop/cop/style/block_delimiters.rb +60 -1
  77. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  78. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  79. data/lib/rubocop/cop/style/documentation.rb +43 -5
  80. data/lib/rubocop/cop/style/end_block.rb +6 -0
  81. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +89 -11
  82. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  83. data/lib/rubocop/cop/style/hash_each_methods.rb +89 -0
  84. data/lib/rubocop/cop/style/hash_transform_keys.rb +83 -0
  85. data/lib/rubocop/cop/style/hash_transform_values.rb +83 -0
  86. data/lib/rubocop/cop/style/if_unless_modifier.rb +38 -3
  87. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  88. data/lib/rubocop/cop/style/inverse_methods.rb +9 -5
  89. data/lib/rubocop/cop/style/lambda.rb +1 -0
  90. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -205
  91. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +169 -0
  92. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +54 -0
  93. data/lib/rubocop/cop/style/module_function.rb +56 -10
  94. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  95. data/lib/rubocop/cop/style/multiline_when_then.rb +5 -1
  96. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -4
  97. data/lib/rubocop/cop/style/numeric_predicate.rb +4 -3
  98. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
  99. data/lib/rubocop/cop/style/or_assignment.rb +3 -2
  100. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +7 -7
  101. data/lib/rubocop/cop/style/redundant_condition.rb +17 -4
  102. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  103. data/lib/rubocop/cop/style/symbol_array.rb +2 -2
  104. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  105. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +34 -22
  106. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
  107. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +85 -0
  108. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
  109. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  110. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  111. data/lib/rubocop/cop/style/yoda_condition.rb +16 -1
  112. data/lib/rubocop/cop/variable_force.rb +4 -1
  113. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  114. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  115. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  116. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  117. data/lib/rubocop/formatter/junit_formatter.rb +74 -0
  118. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  119. data/lib/rubocop/node_pattern.rb +97 -11
  120. data/lib/rubocop/options.rb +8 -8
  121. data/lib/rubocop/processed_source.rb +1 -1
  122. data/lib/rubocop/result_cache.rb +2 -0
  123. data/lib/rubocop/rspec/shared_contexts.rb +5 -0
  124. data/lib/rubocop/runner.rb +5 -1
  125. data/lib/rubocop/target_ruby.rb +151 -0
  126. data/lib/rubocop/version.rb +1 -1
  127. metadata +38 -10
  128. data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
  129. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +0 -209
@@ -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,10 +121,12 @@ 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'
125
128
  require_relative 'rubocop/cop/mixin/interpolation'
129
+ require_relative 'rubocop/cop/mixin/line_length_help'
126
130
  require_relative 'rubocop/cop/mixin/match_range'
127
131
  require_relative 'rubocop/cop/mixin/method_complexity'
128
132
  require_relative 'rubocop/cop/mixin/method_preference'
@@ -142,6 +146,7 @@ require_relative 'rubocop/cop/mixin/percent_array'
142
146
  require_relative 'rubocop/cop/mixin/percent_literal'
143
147
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
144
148
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
149
+ require_relative 'rubocop/cop/mixin/rational_literal'
145
150
  require_relative 'rubocop/cop/mixin/rescue_node'
146
151
  require_relative 'rubocop/cop/mixin/safe_assignment'
147
152
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
@@ -211,7 +216,7 @@ require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
211
216
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
212
217
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
213
218
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
214
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Metrics/LineLength
219
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
215
220
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
216
221
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
217
222
  require_relative 'rubocop/cop/layout/empty_lines'
@@ -234,6 +239,7 @@ require_relative 'rubocop/cop/layout/indentation_width'
234
239
  require_relative 'rubocop/cop/layout/initial_indentation'
235
240
  require_relative 'rubocop/cop/layout/leading_comment_space'
236
241
  require_relative 'rubocop/cop/layout/leading_empty_lines'
242
+ require_relative 'rubocop/cop/layout/line_length'
237
243
  require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
238
244
  require_relative 'rubocop/cop/layout/multiline_array_line_breaks'
239
245
  require_relative 'rubocop/cop/layout/multiline_assignment_layout'
@@ -294,7 +300,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
294
300
  require_relative 'rubocop/cop/lint/empty_expression'
295
301
  require_relative 'rubocop/cop/lint/empty_interpolation'
296
302
  require_relative 'rubocop/cop/lint/empty_when'
297
- require_relative 'rubocop/cop/lint/end_in_method'
298
303
  require_relative 'rubocop/cop/lint/ensure_return'
299
304
  require_relative 'rubocop/cop/lint/erb_new_arguments'
300
305
  require_relative 'rubocop/cop/lint/flip_flop'
@@ -313,12 +318,14 @@ require_relative 'rubocop/cop/lint/multiple_comparison'
313
318
  require_relative 'rubocop/cop/lint/nested_method_definition'
314
319
  require_relative 'rubocop/cop/lint/nested_percent_literal'
315
320
  require_relative 'rubocop/cop/lint/next_without_accumulator'
321
+ require_relative 'rubocop/cop/lint/non_deterministic_require_order'
316
322
  require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
317
323
  require_relative 'rubocop/cop/lint/number_conversion'
318
324
  require_relative 'rubocop/cop/lint/ordered_magic_comments'
319
325
  require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
320
326
  require_relative 'rubocop/cop/lint/percent_string_array'
321
327
  require_relative 'rubocop/cop/lint/percent_symbol_array'
328
+ require_relative 'rubocop/cop/lint/raise_exception'
322
329
  require_relative 'rubocop/cop/lint/rand_one'
323
330
  require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
324
331
  require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
@@ -340,6 +347,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
340
347
  require_relative 'rubocop/cop/lint/shadowed_argument'
341
348
  require_relative 'rubocop/cop/lint/shadowed_exception'
342
349
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
350
+ require_relative 'rubocop/cop/lint/struct_new_override'
343
351
  require_relative 'rubocop/cop/lint/suppressed_exception'
344
352
  require_relative 'rubocop/cop/lint/syntax'
345
353
  require_relative 'rubocop/cop/lint/to_json'
@@ -364,7 +372,6 @@ require_relative 'rubocop/cop/metrics/abc_size'
364
372
  require_relative 'rubocop/cop/metrics/block_length'
365
373
  require_relative 'rubocop/cop/metrics/block_nesting'
366
374
  require_relative 'rubocop/cop/metrics/class_length'
367
- require_relative 'rubocop/cop/metrics/line_length'
368
375
  require_relative 'rubocop/cop/metrics/method_length'
369
376
  require_relative 'rubocop/cop/metrics/module_length'
370
377
  require_relative 'rubocop/cop/metrics/parameter_lists'
@@ -398,7 +405,6 @@ require_relative 'rubocop/cop/style/bare_percent_literals'
398
405
  require_relative 'rubocop/cop/style/begin_block'
399
406
  require_relative 'rubocop/cop/style/block_comments'
400
407
  require_relative 'rubocop/cop/style/block_delimiters'
401
- require_relative 'rubocop/cop/style/braces_around_hash_parameters'
402
408
  require_relative 'rubocop/cop/style/case_equality'
403
409
  require_relative 'rubocop/cop/style/character_literal'
404
410
  require_relative 'rubocop/cop/style/class_and_module_children'
@@ -441,7 +447,10 @@ require_relative 'rubocop/cop/style/format_string_token'
441
447
  require_relative 'rubocop/cop/style/frozen_string_literal_comment'
442
448
  require_relative 'rubocop/cop/style/global_vars'
443
449
  require_relative 'rubocop/cop/style/guard_clause'
450
+ require_relative 'rubocop/cop/style/hash_each_methods'
444
451
  require_relative 'rubocop/cop/style/hash_syntax'
452
+ require_relative 'rubocop/cop/style/hash_transform_keys'
453
+ require_relative 'rubocop/cop/style/hash_transform_values'
445
454
  require_relative 'rubocop/cop/style/identical_conditional_branches'
446
455
  require_relative 'rubocop/cop/style/if_inside_else'
447
456
  require_relative 'rubocop/cop/style/if_unless_modifier'
@@ -456,7 +465,11 @@ require_relative 'rubocop/cop/style/lambda'
456
465
  require_relative 'rubocop/cop/style/lambda_call'
457
466
  require_relative 'rubocop/cop/style/line_end_concatenation'
458
467
  require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
468
+ # rubocop:disable Layout/LineLength
459
469
  require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
470
+ require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
471
+ require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
472
+ # rubocop:enable Layout/LineLength
460
473
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
461
474
  require_relative 'rubocop/cop/style/method_def_parentheses'
462
475
  require_relative 'rubocop/cop/style/method_missing_super'
@@ -544,6 +557,7 @@ require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
544
557
  require_relative 'rubocop/cop/style/trailing_body_on_module'
545
558
  require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
546
559
  require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
560
+ require_relative 'rubocop/cop/style/trailing_comma_in_block_args'
547
561
  require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
548
562
  require_relative 'rubocop/cop/style/trailing_method_end_statement'
549
563
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
@@ -577,6 +591,7 @@ require_relative 'rubocop/formatter/file_list_formatter'
577
591
  require_relative 'rubocop/formatter/fuubar_style_formatter'
578
592
  require_relative 'rubocop/formatter/html_formatter'
579
593
  require_relative 'rubocop/formatter/json_formatter'
594
+ require_relative 'rubocop/formatter/junit_formatter'
580
595
  require_relative 'rubocop/formatter/offense_count_formatter'
581
596
  require_relative 'rubocop/formatter/progress_formatter'
582
597
  require_relative 'rubocop/formatter/quiet_formatter'
@@ -613,4 +628,5 @@ require_relative 'rubocop/cli/command/show_cops'
613
628
  require_relative 'rubocop/cli/command/version'
614
629
  require_relative 'rubocop/options'
615
630
  require_relative 'rubocop/remote_config'
631
+ require_relative 'rubocop/target_ruby'
616
632
  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
@@ -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
@@ -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
@@ -21,14 +21,12 @@ module RuboCop
21
21
 
22
22
  # @return [RuboCop::AST::Node] a regopt node
23
23
  def regopt
24
- first, second = *self
25
- first.regopt_type? ? first : second
24
+ children.last
26
25
  end
27
26
 
28
27
  # @return [String] a string of regexp content
29
28
  def content
30
- str = children.first
31
- str.str_content || ''
29
+ children.select(&:str_type?).map(&:str_content).join
32
30
  end
33
31
  end
34
32
  end