rubocop 1.71.0 → 1.71.2

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 (139) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  3. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  4. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  5. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
  6. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
  7. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
  8. data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
  9. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +1 -0
  10. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  11. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  13. data/lib/rubocop/cop/layout/class_structure.rb +2 -2
  14. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  15. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  16. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
  17. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  18. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  19. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  20. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
  21. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  22. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -5
  23. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
  24. data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
  25. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  26. data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
  27. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  28. data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
  29. data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
  30. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  31. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
  32. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
  33. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
  34. data/lib/rubocop/cop/lint/constant_reassignment.rb +2 -6
  35. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  36. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
  37. data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
  38. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  39. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  40. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  41. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  42. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -3
  43. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  44. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  45. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -1
  46. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
  47. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  48. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
  49. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  50. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  51. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
  52. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
  53. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  54. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
  55. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
  56. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  57. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
  58. data/lib/rubocop/cop/lint/void.rb +2 -7
  59. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  60. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  61. data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -5
  62. data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
  63. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
  64. data/lib/rubocop/cop/mixin/hash_subset.rb +19 -1
  65. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  66. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +22 -8
  67. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  68. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  69. data/lib/rubocop/cop/naming/block_forwarding.rb +18 -14
  70. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
  71. data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -4
  72. data/lib/rubocop/cop/style/arguments_forwarding.rb +38 -19
  73. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  74. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  75. data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
  76. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  77. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
  78. data/lib/rubocop/cop/style/conditional_assignment.rb +3 -3
  79. data/lib/rubocop/cop/style/documentation.rb +1 -1
  80. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  81. data/lib/rubocop/cop/style/each_with_object.rb +2 -3
  82. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  83. data/lib/rubocop/cop/style/explicit_block_argument.rb +15 -2
  84. data/lib/rubocop/cop/style/hash_each_methods.rb +2 -5
  85. data/lib/rubocop/cop/style/hash_except.rb +15 -0
  86. data/lib/rubocop/cop/style/hash_slice.rb +15 -0
  87. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  88. data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
  89. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
  90. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  91. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
  92. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  93. data/lib/rubocop/cop/style/inverse_methods.rb +6 -6
  94. data/lib/rubocop/cop/style/it_assignment.rb +1 -1
  95. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  96. data/lib/rubocop/cop/style/map_into_array.rb +1 -1
  97. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  98. data/lib/rubocop/cop/style/map_to_set.rb +1 -1
  99. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +10 -13
  100. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
  101. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  102. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  103. data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
  104. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
  105. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  106. data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
  107. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
  108. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  109. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  110. data/lib/rubocop/cop/style/proc.rb +1 -2
  111. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  112. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  113. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
  114. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  115. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  116. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  117. data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -6
  118. data/lib/rubocop/cop/style/redundant_self_assignment.rb +12 -27
  119. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  120. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
  121. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  122. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  123. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  124. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  125. data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -1
  126. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  127. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  128. data/lib/rubocop/cop/style/super_arguments.rb +4 -4
  129. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  130. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  131. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  132. data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
  133. data/lib/rubocop/cop/util.rb +2 -2
  134. data/lib/rubocop/cop/variable_force/variable.rb +14 -2
  135. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
  136. data/lib/rubocop/rspec/support.rb +1 -2
  137. data/lib/rubocop/version.rb +1 -1
  138. metadata +9 -6
  139. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
@@ -50,7 +50,7 @@ module RuboCop
50
50
  def ignore_syntax?(node)
51
51
  return false unless (parent = node.parent)
52
52
 
53
- parent.while_post_type? || parent.until_post_type? || parent.match_with_lvasgn_type? ||
53
+ parent.type?(:while_post, :until_post, :match_with_lvasgn) ||
54
54
  like_method_argument_parentheses?(parent) || multiline_control_flow_statements?(node)
55
55
  end
56
56
 
@@ -72,7 +72,7 @@ module RuboCop
72
72
  ancestor = node.ancestors.first
73
73
  return false unless ancestor
74
74
 
75
- !ancestor.begin_type? && !ancestor.def_type? && !ancestor.block_type?
75
+ !ancestor.type?(:begin, :def, :any_block)
76
76
  end
77
77
 
78
78
  def allowed_ternary?(node)
@@ -89,7 +89,7 @@ module RuboCop
89
89
  end
90
90
 
91
91
  def like_method_argument_parentheses?(node)
92
- return false if !node.send_type? && !node.super_type? && !node.yield_type?
92
+ return false unless node.type?(:send, :super, :yield)
93
93
 
94
94
  node.arguments.one? && !node.parenthesized? &&
95
95
  !node.arithmetic_operation? && node.first_argument.begin_type?
@@ -99,7 +99,7 @@ module RuboCop
99
99
  return false unless (parent = node.parent)
100
100
  return false if parent.single_line?
101
101
 
102
- parent.return_type? || parent.next_type? || parent.break_type?
102
+ parent.type?(:return, :next, :break)
103
103
  end
104
104
 
105
105
  def empty_parentheses?(node)
@@ -279,9 +279,9 @@ module RuboCop
279
279
  end
280
280
 
281
281
  def do_end_block_in_method_chain?(begin_node, node)
282
- return false unless (block = node.each_descendant(:block, :numblock).first)
282
+ return false unless (block = node.each_descendant(:any_block).first)
283
283
 
284
- block.keywords? && begin_node.each_ancestor(:send, :csend).any?
284
+ block.keywords? && begin_node.each_ancestor(:call).any?
285
285
  end
286
286
  end
287
287
  end
@@ -21,12 +21,8 @@ module RuboCop
21
21
  # args += foo
22
22
  # hash.merge!(other)
23
23
  #
24
- # # bad
25
- # self.foo = foo.concat(ary)
26
- #
27
24
  # # good
28
25
  # foo.concat(ary)
29
- # self.foo += ary
30
26
  #
31
27
  class RedundantSelfAssignment < Base
32
28
  include RangeHelp
@@ -49,6 +45,16 @@ module RuboCop
49
45
  gvasgn: :gvar
50
46
  }.freeze
51
47
 
48
+ # @!method redundant_self_assignment?
49
+ def_node_matcher :redundant_self_assignment?, <<~PATTERN
50
+ (call
51
+ %1 _
52
+ (call
53
+ (call
54
+ %1 %2) #method_returning_self?
55
+ ...))
56
+ PATTERN
57
+
52
58
  # rubocop:disable Metrics/AbcSize
53
59
  def on_lvasgn(node)
54
60
  return unless (rhs = node.rhs)
@@ -85,31 +91,10 @@ module RuboCop
85
91
  METHODS_RETURNING_SELF.include?(method_name)
86
92
  end
87
93
 
88
- # @!method redundant_self_assignment?(node, method_name)
89
- def_node_matcher :redundant_self_assignment?, <<~PATTERN
90
- (send
91
- (self) _
92
- (call
93
- (send
94
- {(self) nil?} %1) #method_returning_self?
95
- ...))
96
- PATTERN
97
-
98
- # @!method redundant_nonself_assignment?(node, receiver, method_name)
99
- def_node_matcher :redundant_nonself_assignment?, <<~PATTERN
100
- (call
101
- %1 _
102
- (call
103
- (call
104
- %1 %2) #method_returning_self?
105
- ...))
106
- PATTERN
107
-
108
94
  def redundant_assignment?(node)
109
- receiver_name = node.method_name.to_s[0...-1].to_sym
95
+ receiver_name = node.method_name.to_s.delete_suffix('=').to_sym
110
96
 
111
- redundant_self_assignment?(node, receiver_name) ||
112
- redundant_nonself_assignment?(node, node.receiver, receiver_name)
97
+ redundant_self_assignment?(node, node.receiver, receiver_name)
113
98
  end
114
99
 
115
100
  def correction_range(node)
@@ -93,9 +93,9 @@ module RuboCop
93
93
  (call $(call _ $:sort_by _) ${:last :first})
94
94
  (send $(send _ $:sort_by _) ${:[] :at :slice} {(int 0) (int -1)})
95
95
 
96
- (call ({block numblock} $(call _ ${:sort_by :sort}) ...) ${:last :first})
96
+ (call (any_block $(call _ ${:sort_by :sort}) ...) ${:last :first})
97
97
  (call
98
- ({block numblock} $(call _ ${:sort_by :sort}) ...)
98
+ (any_block $(call _ ${:sort_by :sort}) ...)
99
99
  ${:[] :at :slice} {(int 0) (int -1)}
100
100
  )
101
101
  }
@@ -41,7 +41,7 @@ module RuboCop
41
41
  MSG = 'Redundant escape of %<char>s inside string literal.'
42
42
 
43
43
  def on_str(node)
44
- return if node.parent&.regexp_type? || node.parent&.xstr_type? || node.character_literal?
44
+ return if node.parent&.type?(:regexp, :xstr) || node.character_literal?
45
45
 
46
46
  str_contents_range = str_contents_range(node)
47
47
 
@@ -147,7 +147,7 @@ module RuboCop
147
147
  end
148
148
 
149
149
  def heredoc?(node)
150
- (node.str_type? || node.dstr_type?) && node.heredoc?
150
+ node.type?(:str, :dstr) && node.heredoc?
151
151
  end
152
152
 
153
153
  def delimiter?(node, char)
@@ -83,7 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def scoped_node?(node)
86
- node.def_type? || node.defs_type? || node.lambda?
86
+ node.type?(:def, :defs) || node.lambda?
87
87
  end
88
88
 
89
89
  # @!method chained_send?(node)
@@ -312,7 +312,7 @@ module RuboCop
312
312
  end
313
313
 
314
314
  def chain_length(method_chain, method)
315
- method.each_ancestor(:send, :csend).inject(0) do |total, ancestor|
315
+ method.each_ancestor(:call).inject(0) do |total, ancestor|
316
316
  break total + 1 if ancestor == method_chain
317
317
 
318
318
  total + 1
@@ -164,7 +164,7 @@ module RuboCop
164
164
 
165
165
  ast = processed_source.ast
166
166
  @range_nodes = ast.range_type? ? [ast] : []
167
- @range_nodes.concat(ast.each_descendant(:irange, :erange).to_a)
167
+ @range_nodes.concat(ast.each_descendant(:range).to_a)
168
168
  end
169
169
  end
170
170
  end
@@ -68,7 +68,7 @@ module RuboCop
68
68
  return false if body_node.parent.assignment_method? ||
69
69
  NOT_SUPPORTED_ENDLESS_METHOD_BODY_TYPES.include?(body_node.type)
70
70
 
71
- !(body_node.begin_type? || body_node.kwbegin_type?)
71
+ !body_node.type?(:begin, :kwbegin)
72
72
  end
73
73
 
74
74
  def correct_to_multiline(corrector, node)
@@ -156,7 +156,7 @@ module RuboCop
156
156
  # Handle `send` and `block` nodes that need to be wrapped in parens
157
157
  # FIXME: autocorrection prevents syntax errors by wrapping the entire node in parens,
158
158
  # but wrapping the argument list would be a more ergonomic correction.
159
- node_to_check = condition&.block_type? ? condition.send_node : condition
159
+ node_to_check = condition&.any_block_type? ? condition.send_node : condition
160
160
  return unless wrap_condition?(node_to_check)
161
161
 
162
162
  if condition.call_type?
@@ -132,7 +132,7 @@ module RuboCop
132
132
  end
133
133
 
134
134
  def heredoc?(node)
135
- return false unless node.str_type? || node.dstr_type?
135
+ return false unless node.type?(:str, :dstr)
136
136
 
137
137
  node.heredoc?
138
138
  end
@@ -69,7 +69,7 @@ module RuboCop
69
69
  end
70
70
 
71
71
  def all_string_literals?(nodes)
72
- nodes.all? { |n| n.str_type? || n.dstr_type? }
72
+ nodes.all? { |n| n.type?(:str, :dstr) }
73
73
  end
74
74
 
75
75
  def detect_quote_styles(node)
@@ -98,7 +98,7 @@ module RuboCop
98
98
  # When defining dynamic methods, implicitly calling `super` is not possible.
99
99
  # Since there is a possibility of delegation to `define_method`,
100
100
  # `super` used within the block is always allowed.
101
- break if node.block_type? && !block_sends_to_super?(super_node, node)
101
+ break if node.any_block_type? && !block_sends_to_super?(super_node, node)
102
102
 
103
103
  break node if DEF_TYPES.include?(node.type)
104
104
  end
@@ -136,13 +136,13 @@ module RuboCop
136
136
  # Checks if the send node of a block is the given super node,
137
137
  # or a method chain containing it.
138
138
  return false unless parent_node
139
- return false unless parent_node.type?(:block, :numblock)
139
+ return false unless parent_node.any_block_type?
140
140
 
141
141
  parent_node.send_node.each_node(:super).any?(super_node)
142
142
  end
143
143
 
144
144
  def positional_arg_same?(def_arg, super_arg)
145
- return false unless def_arg.arg_type? || def_arg.optarg_type?
145
+ return false unless def_arg.type?(:arg, :optarg)
146
146
  return false unless super_arg.lvar_type?
147
147
 
148
148
  def_arg.name == super_arg.children.first
@@ -159,7 +159,7 @@ module RuboCop
159
159
  end
160
160
 
161
161
  def keyword_arg_same?(def_arg, super_arg)
162
- return false unless def_arg.kwarg_type? || def_arg.kwoptarg_type?
162
+ return false unless def_arg.type?(:kwarg, :kwoptarg)
163
163
  return false unless (pair_node = super_arg).pair_type?
164
164
  return false unless (sym_node = pair_node.key).sym_type?
165
165
  return false unless (lvar_node = pair_node.value).lvar_type?
@@ -232,7 +232,7 @@ module RuboCop
232
232
  end
233
233
 
234
234
  def node_with_args?(node)
235
- node.call_type? || node.defined_type?
235
+ node.type?(:call, :defined?)
236
236
  end
237
237
  end
238
238
  end
@@ -77,7 +77,7 @@ module RuboCop
77
77
 
78
78
  # @!method define_method_block?(node)
79
79
  def_node_matcher :define_method_block?, <<~PATTERN
80
- ({block numblock} (send _ :define_method _) ...)
80
+ (any_block (send _ :define_method _) ...)
81
81
  PATTERN
82
82
  end
83
83
  end
@@ -24,7 +24,6 @@ module RuboCop
24
24
  # # good
25
25
  # x += 1 until x > 10
26
26
  #
27
- # @example
28
27
  # # bad
29
28
  # x += 100 while x < 500 # a long comment that makes code too long if it were a single line
30
29
  #
@@ -72,7 +72,7 @@ module RuboCop
72
72
  end
73
73
 
74
74
  def constant_portion?(node)
75
- node.numeric_type? || node.const_type?
75
+ node.type?(:numeric, :const)
76
76
  end
77
77
 
78
78
  def supported_operators
@@ -74,9 +74,9 @@ module RuboCop
74
74
 
75
75
  def args_begin(node)
76
76
  loc = node.loc
77
- selector = if node.super_type? || node.yield_type?
77
+ selector = if node.type?(:super, :yield)
78
78
  loc.keyword
79
- elsif node.def_type? || node.defs_type?
79
+ elsif node.type?(:def, :defs)
80
80
  loc.name
81
81
  else
82
82
  loc.selector
@@ -6,6 +6,8 @@ module RuboCop
6
6
  # A Variable represents existence of a local variable.
7
7
  # This holds a variable declaration node and some states of the variable.
8
8
  class Variable
9
+ extend NodePattern::Macros
10
+
9
11
  VARIABLE_DECLARATION_TYPES = (VARIABLE_ASSIGNMENT_TYPES + ARGUMENT_DECLARATION_TYPES).freeze
10
12
 
11
13
  attr_reader :name, :declaration_node, :scope, :assignments, :references, :captured_by_block
@@ -31,11 +33,21 @@ module RuboCop
31
33
  def assign(node)
32
34
  assignment = Assignment.new(node, self)
33
35
 
34
- @assignments.last&.reassigned! unless captured_by_block?
36
+ mark_last_as_reassigned!(assignment)
35
37
 
36
38
  @assignments << assignment
37
39
  end
38
40
 
41
+ def mark_last_as_reassigned!(assignment)
42
+ return if captured_by_block?
43
+ return if candidate_condition?(assignment.node.parent)
44
+
45
+ @assignments.last&.reassigned!
46
+ end
47
+
48
+ # @!method candidate_condition?(node)
49
+ def_node_matcher :candidate_condition?, '[{if case case_match when}]'
50
+
39
51
  def referenced?
40
52
  !@references.empty?
41
53
  end
@@ -72,7 +84,7 @@ module RuboCop
72
84
  parent = parent.parent if parent&.begin_type?
73
85
  return false if parent.nil?
74
86
 
75
- (parent.if_type? || parent.while_type? || parent.until_type?) && parent.modifier_form?
87
+ parent.type?(:if, :while, :until) && parent.modifier_form?
76
88
  end
77
89
 
78
90
  def capture_with_block!
@@ -100,7 +100,7 @@ module RuboCop
100
100
 
101
101
  # Only block scope allows referencing outer scope variables.
102
102
  node = scope.node
103
- return nil unless node.block_type? || node.numblock_type?
103
+ return nil unless node.any_block_type?
104
104
  end
105
105
 
106
106
  nil
@@ -113,14 +113,14 @@ module RuboCop
113
113
  def accessible_variables
114
114
  scope_stack.reverse_each.with_object([]) do |scope, variables|
115
115
  variables.concat(scope.variables.values)
116
- break variables unless scope.node.block_type? || scope.node.numblock_type?
116
+ break variables unless scope.node.any_block_type?
117
117
  end
118
118
  end
119
119
 
120
120
  private
121
121
 
122
122
  def mark_variable_as_captured_by_block_if_so(variable)
123
- return unless current_scope.node.block_type? || current_scope.node.numblock_type?
123
+ return unless current_scope.node.any_block_type?
124
124
  return if variable.scope == current_scope
125
125
 
126
126
  variable.capture_with_block!
@@ -4,13 +4,12 @@
4
4
 
5
5
  require_relative 'cop_helper'
6
6
  require_relative 'expect_offense'
7
- require_relative 'host_environment_simulation_helper'
8
7
  require_relative 'parallel_formatter'
9
8
  require_relative 'shared_contexts'
10
9
 
11
10
  RSpec.configure do |config|
12
11
  config.include CopHelper
13
- config.include HostEnvironmentSimulatorHelper
12
+ config.include RuboCop::RSpec::ExpectOffense
14
13
  config.include_context 'config', :config
15
14
  config.include_context 'isolated environment', :isolated_environment
16
15
  config.include_context 'isolated bundler', :isolated_bundler
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.71.0'
6
+ STRING = '1.71.2'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.71.0
4
+ version: 1.71.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-01-22 00:00:00.000000000 Z
12
+ date: 2025-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -113,7 +113,7 @@ dependencies:
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 1.36.2
116
+ version: 1.38.0
117
117
  - - "<"
118
118
  - !ruby/object:Gem::Version
119
119
  version: '2.0'
@@ -123,7 +123,7 @@ dependencies:
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: 1.36.2
126
+ version: 1.38.0
127
127
  - - "<"
128
128
  - !ruby/object:Gem::Version
129
129
  version: '2.0'
@@ -279,6 +279,10 @@ files:
279
279
  - lib/rubocop/cop/internal_affairs/node_destructuring.rb
280
280
  - lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb
281
281
  - lib/rubocop/cop/internal_affairs/node_matcher_directive.rb
282
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups.rb
283
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb
284
+ - lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb
285
+ - lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb
282
286
  - lib/rubocop/cop/internal_affairs/node_type_predicate.rb
283
287
  - lib/rubocop/cop/internal_affairs/numblock_handler.rb
284
288
  - lib/rubocop/cop/internal_affairs/offense_location_keyword.rb
@@ -1009,7 +1013,6 @@ files:
1009
1013
  - lib/rubocop/result_cache.rb
1010
1014
  - lib/rubocop/rspec/cop_helper.rb
1011
1015
  - lib/rubocop/rspec/expect_offense.rb
1012
- - lib/rubocop/rspec/host_environment_simulation_helper.rb
1013
1016
  - lib/rubocop/rspec/parallel_formatter.rb
1014
1017
  - lib/rubocop/rspec/shared_contexts.rb
1015
1018
  - lib/rubocop/rspec/support.rb
@@ -1046,7 +1049,7 @@ licenses:
1046
1049
  - MIT
1047
1050
  metadata:
1048
1051
  homepage_uri: https://rubocop.org/
1049
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.0
1052
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.71.2
1050
1053
  source_code_uri: https://github.com/rubocop/rubocop/
1051
1054
  documentation_uri: https://docs.rubocop.org/rubocop/1.71/
1052
1055
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # RuboCop can be run in contexts where unexpected other libraries are included,
4
- # which may interfere with its normal behavior. In order to test those
5
- # situations, it may be necessary to require another library for the duration
6
- # of one spec
7
- module HostEnvironmentSimulatorHelper
8
- def in_its_own_process_with(*files)
9
- if ::Process.respond_to?(:fork)
10
- pid = ::Process.fork do
11
- # Need to write coverage result under different name
12
- if defined?(SimpleCov)
13
- SimpleCov.command_name "rspec-fork-#{Process.pid}"
14
- SimpleCov.pid = Process.pid
15
- end
16
-
17
- files.each { |file| require file }
18
- yield
19
- end
20
- ::Process.wait(pid)
21
-
22
- # assert that the block did not fail
23
- expect($CHILD_STATUS).to be_success
24
- else
25
- warn 'Process.fork is not available.'
26
- end
27
- end
28
- end