rubocop 1.89.0 → 1.91.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 (248) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +309 -14
  3. data/config/obsoletion.yml +9 -0
  4. data/exe/rubocop +1 -1
  5. data/lib/rubocop/cached_data.rb +7 -2
  6. data/lib/rubocop/changed_files.rb +112 -0
  7. data/lib/rubocop/cli/command/execute_runner.rb +52 -1
  8. data/lib/rubocop/cli.rb +11 -7
  9. data/lib/rubocop/comment_config/directive_range.rb +34 -0
  10. data/lib/rubocop/comment_config/disable_next.rb +143 -0
  11. data/lib/rubocop/comment_config/push_pop.rb +55 -0
  12. data/lib/rubocop/comment_config.rb +50 -64
  13. data/lib/rubocop/config.rb +33 -5
  14. data/lib/rubocop/config_loader.rb +13 -6
  15. data/lib/rubocop/config_loader_resolver.rb +50 -9
  16. data/lib/rubocop/config_obsoletion/cop_rule.rb +2 -1
  17. data/lib/rubocop/config_obsoletion/removed_cop.rb +8 -0
  18. data/lib/rubocop/config_obsoletion.rb +1 -1
  19. data/lib/rubocop/config_validator.rb +19 -5
  20. data/lib/rubocop/cop/autocorrect_logic.rb +8 -0
  21. data/lib/rubocop/cop/badge.rb +1 -1
  22. data/lib/rubocop/cop/base.rb +49 -5
  23. data/lib/rubocop/cop/corrector.rb +3 -3
  24. data/lib/rubocop/cop/correctors.rb +2 -2
  25. data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
  26. data/lib/rubocop/cop/generator.rb +1 -1
  27. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -2
  28. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -2
  29. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  30. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -0
  31. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  32. data/lib/rubocop/cop/layout/class_structure.rb +102 -26
  33. data/lib/rubocop/cop/layout/comment_indentation.rb +8 -5
  34. data/lib/rubocop/cop/layout/else_alignment.rb +1 -0
  35. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -2
  36. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +63 -5
  37. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +1 -1
  38. data/lib/rubocop/cop/layout/end_alignment.rb +1 -2
  39. data/lib/rubocop/cop/layout/extra_spacing.rb +105 -3
  40. data/lib/rubocop/cop/layout/first_argument_indentation.rb +21 -1
  41. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +17 -4
  42. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +11 -0
  43. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -5
  44. data/lib/rubocop/cop/layout/indentation_width.rb +2 -2
  45. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -2
  46. data/lib/rubocop/cop/layout/line_length.rb +20 -3
  47. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -2
  48. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +5 -5
  49. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -2
  50. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +14 -3
  51. data/lib/rubocop/cop/layout/space_around_operators.rb +12 -1
  52. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
  53. data/lib/rubocop/cop/lint/ambiguous_range.rb +1 -2
  54. data/lib/rubocop/cop/lint/argument_mismatch.rb +99 -0
  55. data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -0
  56. data/lib/rubocop/cop/lint/constant_reassignment.rb +17 -11
  57. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +165 -15
  58. data/lib/rubocop/cop/lint/deprecated_reference.rb +11 -2
  59. data/lib/rubocop/cop/lint/duplicate_methods.rb +113 -15
  60. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  61. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -2
  62. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -2
  63. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -2
  64. data/lib/rubocop/cop/lint/literal_as_condition.rb +11 -8
  65. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +3 -6
  66. data/lib/rubocop/cop/lint/misplaced_magic_comment.rb +185 -0
  67. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +25 -12
  68. data/lib/rubocop/cop/lint/name_typo.rb +53 -6
  69. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  70. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
  71. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +15 -0
  72. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +17 -1
  73. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +122 -29
  74. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +47 -7
  75. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -2
  76. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -2
  77. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -2
  78. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +1 -2
  79. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -2
  80. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -2
  81. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -4
  82. data/lib/rubocop/cop/lint/super_argument_mismatch.rb +179 -0
  83. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +1 -2
  84. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -2
  85. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -2
  86. data/lib/rubocop/cop/lint/unused_private_method.rb +94 -17
  87. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -2
  88. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -2
  89. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +36 -0
  90. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  91. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -2
  92. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +61 -7
  93. data/lib/rubocop/cop/lint/void.rb +1 -2
  94. data/lib/rubocop/cop/lint.rb +3 -0
  95. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -2
  96. data/lib/rubocop/cop/migration/department_name.rb +1 -2
  97. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  98. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
  99. data/lib/rubocop/cop/mixin/comments_help.rb +1 -2
  100. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -2
  101. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +11 -1
  102. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +7 -4
  103. data/lib/rubocop/cop/mixin/hash_subset.rb +1 -2
  104. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
  105. data/lib/rubocop/cop/mixin/indexed_method_arity.rb +94 -0
  106. data/lib/rubocop/cop/mixin/line_length_help.rb +7 -1
  107. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +62 -6
  108. data/lib/rubocop/cop/mixin/range_help.rb +1 -2
  109. data/lib/rubocop/cop/mixin/statement_modifier.rb +13 -7
  110. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  111. data/lib/rubocop/cop/mixin.rb +6 -2
  112. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +16 -0
  113. data/lib/rubocop/cop/naming/block_forwarding.rb +4 -1
  114. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  115. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -4
  116. data/lib/rubocop/cop/naming/method_name.rb +5 -2
  117. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -2
  118. data/lib/rubocop/cop/offense.rb +27 -4
  119. data/lib/rubocop/cop/registry.rb +43 -11
  120. data/lib/rubocop/cop/severity.rb +12 -0
  121. data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -2
  122. data/lib/rubocop/cop/style/accessor_grouping.rb +1 -2
  123. data/lib/rubocop/cop/style/arguments_forwarding.rb +5 -8
  124. data/lib/rubocop/cop/style/array_first_last.rb +1 -2
  125. data/lib/rubocop/cop/style/bitwise_predicate.rb +1 -2
  126. data/lib/rubocop/cop/style/block_delimiters.rb +3 -6
  127. data/lib/rubocop/cop/style/case_like_if.rb +5 -7
  128. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -2
  129. data/lib/rubocop/cop/style/combinable_loops.rb +1 -2
  130. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -2
  131. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -2
  132. data/lib/rubocop/cop/style/constant_visibility.rb +6 -3
  133. data/lib/rubocop/cop/style/copyright.rb +1 -2
  134. data/lib/rubocop/cop/style/data_inheritance.rb +14 -0
  135. data/lib/rubocop/cop/style/directive_scope.rb +304 -0
  136. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +83 -13
  137. data/lib/rubocop/cop/style/documentation_method.rb +1 -9
  138. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  139. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  140. data/lib/rubocop/cop/style/empty_case_condition.rb +1 -2
  141. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  142. data/lib/rubocop/cop/style/empty_method.rb +12 -2
  143. data/lib/rubocop/cop/style/endless_method.rb +31 -12
  144. data/lib/rubocop/cop/style/file_null.rb +2 -2
  145. data/lib/rubocop/cop/style/float_division.rb +10 -16
  146. data/lib/rubocop/cop/style/for.rb +5 -0
  147. data/lib/rubocop/cop/style/format_string_token.rb +1 -2
  148. data/lib/rubocop/cop/style/guard_clause.rb +5 -2
  149. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -2
  150. data/lib/rubocop/cop/style/hash_lookup_method.rb +3 -0
  151. data/lib/rubocop/cop/style/hash_syntax.rb +1 -2
  152. data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -4
  153. data/lib/rubocop/cop/style/if_inside_else.rb +1 -2
  154. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -2
  155. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -2
  156. data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
  157. data/lib/rubocop/cop/style/map_to_hash.rb +1 -2
  158. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
  159. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  160. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -2
  161. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -2
  162. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -2
  163. data/lib/rubocop/cop/style/negative_array_index.rb +2 -4
  164. data/lib/rubocop/cop/style/nested_modifier.rb +9 -4
  165. data/lib/rubocop/cop/style/nil_comparison.rb +36 -9
  166. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  167. data/lib/rubocop/cop/style/non_nil_check.rb +18 -2
  168. data/lib/rubocop/cop/style/not.rb +3 -1
  169. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +11 -1
  170. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  171. data/lib/rubocop/cop/style/operator_method_call.rb +1 -2
  172. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -2
  173. data/lib/rubocop/cop/style/parentheses_around_condition.rb +6 -1
  174. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -2
  175. data/lib/rubocop/cop/style/redundant_condition.rb +6 -8
  176. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +11 -3
  177. data/lib/rubocop/cop/style/redundant_each.rb +1 -2
  178. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  179. data/lib/rubocop/cop/style/redundant_format.rb +2 -4
  180. data/lib/rubocop/cop/style/redundant_parentheses.rb +13 -5
  181. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +1 -2
  182. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +6 -5
  183. data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +6 -6
  184. data/lib/rubocop/cop/style/redundant_return.rb +1 -2
  185. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
  186. data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -2
  187. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -2
  188. data/lib/rubocop/cop/style/safe_navigation.rb +1 -2
  189. data/lib/rubocop/cop/style/sample.rb +11 -6
  190. data/lib/rubocop/cop/style/select_by_regexp.rb +1 -2
  191. data/lib/rubocop/cop/style/semicolon.rb +2 -4
  192. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  193. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -2
  194. data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -2
  195. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  196. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -0
  197. data/lib/rubocop/cop/style/string_concatenation.rb +18 -5
  198. data/lib/rubocop/cop/style/struct_inheritance.rb +14 -0
  199. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  200. data/lib/rubocop/cop/style/symbol_proc.rb +1 -2
  201. data/lib/rubocop/cop/style/time_now.rb +41 -0
  202. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  203. data/lib/rubocop/cop/style/yoda_condition.rb +1 -2
  204. data/lib/rubocop/cop/style.rb +2 -1
  205. data/lib/rubocop/cop/team.rb +11 -3
  206. data/lib/rubocop/cop/util.rb +3 -5
  207. data/lib/rubocop/cop/variable_force/variable.rb +1 -2
  208. data/lib/rubocop/cops_documentation_generator.rb +26 -8
  209. data/lib/rubocop/directive_comment.rb +73 -10
  210. data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -1
  211. data/lib/rubocop/formatter/emacs_style_formatter.rb +3 -1
  212. data/lib/rubocop/formatter/formatter_set.rb +2 -1
  213. data/lib/rubocop/formatter/github_actions_formatter.rb +6 -5
  214. data/lib/rubocop/formatter/html_formatter.rb +2 -4
  215. data/lib/rubocop/formatter/json_formatter.rb +11 -6
  216. data/lib/rubocop/formatter/junit_formatter.rb +26 -9
  217. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -2
  218. data/lib/rubocop/formatter/sarif_formatter.rb +181 -0
  219. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -3
  220. data/lib/rubocop/formatter/tap_formatter.rb +3 -1
  221. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -2
  222. data/lib/rubocop/formatter.rb +1 -0
  223. data/lib/rubocop/lockfile.rb +18 -0
  224. data/lib/rubocop/lsp/diagnostic.rb +4 -8
  225. data/lib/rubocop/lsp/routes.rb +48 -19
  226. data/lib/rubocop/magic_comment.rb +27 -0
  227. data/lib/rubocop/mcp/server.rb +1 -2
  228. data/lib/rubocop/options.rb +69 -7
  229. data/lib/rubocop/path_util.rb +2 -3
  230. data/lib/rubocop/plugin/configuration_integrator.rb +6 -3
  231. data/lib/rubocop/plugin/loader.rb +1 -1
  232. data/lib/rubocop/rake_task.rb +1 -2
  233. data/lib/rubocop/remote_config.rb +4 -4
  234. data/lib/rubocop/result_cache.rb +16 -5
  235. data/lib/rubocop/rspec/expect_offense.rb +2 -4
  236. data/lib/rubocop/rspec/shared_contexts.rb +4 -2
  237. data/lib/rubocop/runner.rb +90 -44
  238. data/lib/rubocop/server/cache.rb +1 -2
  239. data/lib/rubocop/server/cli.rb +2 -4
  240. data/lib/rubocop/server.rb +14 -0
  241. data/lib/rubocop/target_finder.rb +4 -1
  242. data/lib/rubocop/todo_audit.rb +111 -0
  243. data/lib/rubocop/unified_diff.rb +257 -0
  244. data/lib/rubocop/version.rb +3 -5
  245. data/lib/rubocop.rb +7 -1
  246. data/lib/ruby_lsp/rubocop/addon.rb +1 -2
  247. metadata +18 -6
  248. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +0 -46
@@ -316,7 +316,7 @@ module RuboCop
316
316
  end
317
317
 
318
318
  def select_grouped_def_nodes(node)
319
- node.right_siblings.take_while do |sibling|
319
+ node.right_siblings.compact.take_while do |sibling|
320
320
  !(sibling.send_type? && sibling.bare_access_modifier_declaration?)
321
321
  end.select(&:def_type?)
322
322
  end
@@ -347,7 +347,8 @@ module RuboCop
347
347
  end
348
348
 
349
349
  def remove_modifier_node_within_begin(corrector, modifier_node, begin_node)
350
- def_node = begin_node.children[begin_node.children.index(modifier_node) + 1]
350
+ modifier_index = begin_node.children.find_index { |child| child.equal?(modifier_node) }
351
+ def_node = begin_node.children[modifier_index + 1]
351
352
  # Stop the removal range at the first comment that precedes the def, if
352
353
  # any exist. Without this, comments between the modifier and the def are
353
354
  # dropped because they fall inside the removed range.
@@ -100,7 +100,7 @@ module RuboCop
100
100
  comment_line?(processed_source[node.first_line - 2])
101
101
  end
102
102
 
103
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
103
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
104
104
  def groupable_accessor?(node)
105
105
  return true unless (previous_expression = node.left_siblings.last)
106
106
 
@@ -122,7 +122,6 @@ module RuboCop
122
122
  previous_expression.access_modifier? ||
123
123
  node.first_line - previous_expression.last_line > 1 # there is a space between nodes
124
124
  end
125
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
126
125
 
127
126
  def class_send_elements(class_node)
128
127
  class_def = class_node.body
@@ -197,12 +197,12 @@ module RuboCop
197
197
  send_classifications.all? { |_, c, _, _| all_classifications.include?(c) }
198
198
  end
199
199
 
200
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
200
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
201
201
  def add_forward_all_offenses(node, send_classifications, forwardable_args)
202
202
  rest_arg, kwrest_arg, block_arg = *forwardable_args
203
203
  registered_block_arg_offense = false
204
204
 
205
- send_classifications.each do |send_node, c, forward_rest, forward_kwrest, forward_block_arg| # rubocop:disable Layout/LineLength
205
+ send_classifications.each do |send_node, c, forward_rest, forward_kwrest, forward_block_arg| # rubocop:disable Layout/LineLength -- the block parameter list does not wrap
206
206
  if !forward_rest && !forward_kwrest && c != :all_anonymous
207
207
  if allow_anonymous_forwarding_in_block?(forward_block_arg)
208
208
  register_forward_block_arg_offense(!forward_rest, node.arguments, block_arg)
@@ -220,20 +220,19 @@ module RuboCop
220
220
 
221
221
  register_forward_all_offense(node, node.arguments, rest_arg || kwrest_arg)
222
222
  end
223
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
224
223
 
225
224
  def forward_all_first_argument(node)
226
225
  node.arguments.reverse_each.find(&:forwarded_restarg_type?)
227
226
  end
228
227
 
229
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
228
+ # rubocop:disable-next Metrics/AbcSize, Metrics/MethodLength
230
229
  def add_post_ruby_32_offenses(def_node, send_classifications, forwardable_args)
231
230
  return unless use_anonymous_forwarding?
232
231
  return unless all_forwarding_offenses_correctable?(send_classifications)
233
232
 
234
233
  rest_arg, kwrest_arg, block_arg = *forwardable_args
235
234
 
236
- send_classifications.each do |send_node, _c, forward_rest, forward_kwrest, forward_block_arg| # rubocop:disable Layout/LineLength
235
+ send_classifications.each do |send_node, _c, forward_rest, forward_kwrest, forward_block_arg| # rubocop:disable Layout/LineLength -- the block parameter list does not wrap
237
236
  if allow_anonymous_forwarding_in_block?(forward_rest)
238
237
  register_forward_args_offense(def_node.arguments, rest_arg)
239
238
  register_forward_args_offense(send_node, forward_rest)
@@ -250,7 +249,6 @@ module RuboCop
250
249
  end
251
250
  end
252
251
  end
253
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
254
252
 
255
253
  def non_splat_or_block_pass_lvar_references(body)
256
254
  body.each_descendant(:lvar, :lvasgn).filter_map do |lvar|
@@ -473,7 +471,7 @@ module RuboCop
473
471
 
474
472
  private
475
473
 
476
- # rubocop:disable Metrics/CyclomaticComplexity
474
+ # rubocop:disable-next Metrics/CyclomaticComplexity
477
475
  def can_forward_all?
478
476
  return false if any_arg_referenced?
479
477
  return false if ruby_30_or_lower_optarg?
@@ -483,7 +481,6 @@ module RuboCop
483
481
 
484
482
  no_additional_args? || (target_ruby_version >= 3.0 && no_post_splat_args?)
485
483
  end
486
- # rubocop:enable Metrics/CyclomaticComplexity
487
484
 
488
485
  # def foo(a = 41, ...) is a syntax error in 3.0.
489
486
  def ruby_30_or_lower_optarg?
@@ -31,7 +31,7 @@ module RuboCop
31
31
  MSG = 'Use `%<preferred>s`.'
32
32
  RESTRICT_ON_SEND = %i[[]].freeze
33
33
 
34
- # rubocop:disable Metrics/AbcSize
34
+ # rubocop:disable-next Metrics/AbcSize
35
35
  def on_send(node)
36
36
  return unless node.arguments.size == 1 && node.first_argument.int_type?
37
37
 
@@ -49,7 +49,6 @@ module RuboCop
49
49
  corrector.replace(offense_range, preferred_value(node, preferred))
50
50
  end
51
51
  end
52
- # rubocop:enable Metrics/AbcSize
53
52
  alias on_csend on_send
54
53
 
55
54
  private
@@ -70,7 +70,7 @@ module RuboCop
70
70
  (send _ :& _))
71
71
  PATTERN
72
72
 
73
- # rubocop:disable Metrics/AbcSize
73
+ # rubocop:disable-next Metrics/AbcSize
74
74
  def on_send(node)
75
75
  return unless node.receiver&.begin_type?
76
76
  return unless (preferred_method = preferred_method(node))
@@ -88,7 +88,6 @@ module RuboCop
88
88
  corrector.replace(node, preferred)
89
89
  end
90
90
  end
91
- # rubocop:enable Metrics/AbcSize
92
91
 
93
92
  private
94
93
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
3
+ # rubocop:disable-next Metrics/ClassLength
4
4
  module RuboCop
5
5
  module Cop
6
6
  module Style
@@ -344,7 +344,7 @@ module RuboCop
344
344
  node.respond_to?(:block_node) && node.block_node
345
345
  end
346
346
 
347
- # rubocop:disable Metrics/CyclomaticComplexity
347
+ # rubocop:disable-next Metrics/CyclomaticComplexity
348
348
  def get_blocks(node, &block)
349
349
  case node.type
350
350
  when :block, :numblock, :itblock
@@ -368,9 +368,8 @@ module RuboCop
368
368
  node.each_child_node { |child| get_blocks(child, &block) }
369
369
  end
370
370
  end
371
- # rubocop:enable Metrics/CyclomaticComplexity
372
371
 
373
- # rubocop:disable Metrics/CyclomaticComplexity -- inlined special_method checks to avoid double evaluation
372
+ # rubocop:disable-next Metrics/CyclomaticComplexity -- inlined special_method checks to avoid double evaluation
374
373
  def proper_block_style?(node)
375
374
  return true if require_do_end?(node)
376
375
 
@@ -385,7 +384,6 @@ module RuboCop
385
384
  when :always_braces then node.braces?
386
385
  end
387
386
  end
388
- # rubocop:enable Metrics/CyclomaticComplexity
389
387
 
390
388
  def require_do_end?(node)
391
389
  return false if node.braces? || node.multiline?
@@ -507,4 +505,3 @@ module RuboCop
507
505
  end
508
506
  end
509
507
  end
510
- # rubocop:enable Metrics/ClassLength
@@ -98,7 +98,7 @@ module RuboCop
98
98
  node.elsif_conditional? && min_branches_count?(node)
99
99
  end
100
100
 
101
- # rubocop:disable Metrics/MethodLength
101
+ # rubocop:disable-next Metrics/MethodLength
102
102
  def find_target(node)
103
103
  case node.type
104
104
  when :begin
@@ -106,7 +106,7 @@ module RuboCop
106
106
  when :or
107
107
  find_target(node.lhs)
108
108
  when :match_with_lvasgn
109
- lhs, rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring
109
+ lhs, rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring -- `match_with_lvasgn` has no named operand accessors
110
110
  if lhs.regexp_type?
111
111
  rhs
112
112
  elsif rhs.regexp_type?
@@ -116,7 +116,6 @@ module RuboCop
116
116
  find_target_in_send_node(node)
117
117
  end
118
118
  end
119
- # rubocop:enable Metrics/MethodLength
120
119
 
121
120
  def find_target_in_send_node(node)
122
121
  case node.method_name
@@ -172,7 +171,7 @@ module RuboCop
172
171
  return collect_conditions(node.lhs, target, conditions) &&
173
172
  collect_conditions(node.rhs, target, conditions)
174
173
  when :match_with_lvasgn
175
- lhs, rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring
174
+ lhs, rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring -- `match_with_lvasgn` has no named operand accessors
176
175
  condition_from_binary_op(lhs, rhs, target)
177
176
  when :send
178
177
  condition_from_send_node(node, target)
@@ -181,7 +180,7 @@ module RuboCop
181
180
  conditions << condition if condition
182
181
  end
183
182
 
184
- # rubocop:disable Metrics/CyclomaticComplexity
183
+ # rubocop:disable-next Metrics/CyclomaticComplexity
185
184
  def condition_from_send_node(node, target)
186
185
  case node.method_name
187
186
  when :is_a?
@@ -196,7 +195,6 @@ module RuboCop
196
195
  condition_from_include_or_cover_node(node, target)
197
196
  end
198
197
  end
199
- # rubocop:enable Metrics/CyclomaticComplexity
200
198
 
201
199
  def condition_from_equality_node(node, target)
202
200
  condition = condition_from_binary_op(node.receiver, node.first_argument, target)
@@ -260,7 +258,7 @@ module RuboCop
260
258
  def regexp_with_working_captures?(node)
261
259
  case node.type
262
260
  when :match_with_lvasgn
263
- lhs, _rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring
261
+ lhs, _rhs = *node # rubocop:disable InternalAffairs/NodeDestructuring -- `match_with_lvasgn` has no named operand accessors
264
262
  node.loc.selector.source == '=~' && regexp_with_named_captures?(lhs)
265
263
  when :send
266
264
  node.method?(:match) &&
@@ -194,7 +194,7 @@ module RuboCop
194
194
  "#{node.body.children.first.const_name}"
195
195
  end
196
196
 
197
- # rubocop:disable Metrics/AbcSize
197
+ # rubocop:disable-next Metrics/AbcSize
198
198
  def remove_end(corrector, body)
199
199
  remove_begin_pos = if same_line?(body.loc.name, body.loc.end)
200
200
  body.loc.name.end_pos
@@ -206,7 +206,6 @@ module RuboCop
206
206
 
207
207
  corrector.remove(range)
208
208
  end
209
- # rubocop:enable Metrics/AbcSize
210
209
 
211
210
  def unindent(corrector, node)
212
211
  return unless node.body.children.last
@@ -64,7 +64,7 @@ module RuboCop
64
64
 
65
65
  MSG = 'Combine this loop with the previous loop.'
66
66
 
67
- # rubocop:disable Metrics/CyclomaticComplexity
67
+ # rubocop:disable-next Metrics/CyclomaticComplexity
68
68
  def on_block(node)
69
69
  return unless node.parent&.begin_type?
70
70
  return unless collection_looping_method?(node)
@@ -77,7 +77,6 @@ module RuboCop
77
77
  combine_with_left_sibling(corrector, node)
78
78
  end
79
79
  end
80
- # rubocop:enable Metrics/CyclomaticComplexity
81
80
 
82
81
  alias on_numblock on_block
83
82
  alias on_itblock on_block
@@ -30,7 +30,7 @@ module RuboCop
30
30
  'Use `push` with elements as arguments without array brackets instead of `%<current>s`.'
31
31
  RESTRICT_ON_SEND = %i[concat].freeze
32
32
 
33
- # rubocop:disable Metrics
33
+ # rubocop:disable-next Metrics
34
34
  def on_send(node)
35
35
  return if node.arguments.empty?
36
36
  return unless node.arguments.all?(&:array_type?)
@@ -68,7 +68,6 @@ module RuboCop
68
68
  end
69
69
  end
70
70
  end
71
- # rubocop:enable Metrics
72
71
  alias on_csend on_send
73
72
 
74
73
  private
@@ -448,7 +448,7 @@ module RuboCop
448
448
  # Helper module to provide common methods to ConditionalAssignment
449
449
  # correctors
450
450
  module ConditionalCorrectorHelper
451
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
451
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity
452
452
  def remove_whitespace_in_branches(corrector, branch, condition, column)
453
453
  branch.each_node do |child|
454
454
  next if child.source_range.nil?
@@ -468,7 +468,6 @@ module RuboCop
468
468
 
469
469
  corrector.remove_preceding(condition.loc.end, condition.loc.end.column - column)
470
470
  end
471
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
472
471
 
473
472
  def same_line?(node1, node2)
474
473
  RuboCop::Cop::Util.same_line?(node1, node2)
@@ -82,12 +82,16 @@ module RuboCop
82
82
  end
83
83
  end
84
84
 
85
- # rubocop:disable Metrics/AbcSize
85
+ # rubocop:disable-next Metrics/AbcSize, Metrics/CyclomaticComplexity
86
86
  def visibility_declaration?(node)
87
87
  node.parent.each_child_node(:send).any? do |child|
88
88
  next false unless (arguments = visibility_declaration_for(child))
89
89
 
90
- arguments = arguments.first.children.first.to_a if arguments.first&.splat_type?
90
+ if (splat = arguments.first)&.splat_type?
91
+ next true unless splat.children.first.array_type?
92
+
93
+ arguments = splat.children.first.children
94
+ end
91
95
  constant_values = arguments.map do |argument|
92
96
  # `respond_to?(:value)` is too broad: `int`/`float` nodes respond to it
93
97
  # but their value is a `Numeric`, which has no `to_sym` (e.g.
@@ -98,7 +102,6 @@ module RuboCop
98
102
  constant_values.include?(node.name)
99
103
  end
100
104
  end
101
- # rubocop:enable Metrics/AbcSize
102
105
  end
103
106
  end
104
107
  end
@@ -25,7 +25,7 @@ module RuboCop
25
25
  MSG = 'Include a copyright notice matching /%<notice>s/ before any code.'
26
26
  AUTOCORRECT_EMPTY_WARNING = 'An AutocorrectNotice must be defined in your RuboCop config'
27
27
 
28
- # rubocop:disable Metrics/AbcSize
28
+ # rubocop:disable-next Metrics/AbcSize
29
29
  def on_new_investigation
30
30
  return if notice.empty? || notice_found?(processed_source)
31
31
 
@@ -43,7 +43,6 @@ module RuboCop
43
43
  end
44
44
  end
45
45
  end
46
- # rubocop:enable Metrics/AbcSize
47
46
 
48
47
  private
49
48
 
@@ -10,6 +10,10 @@ module RuboCop
10
10
  # Autocorrection is unsafe because it will change the inheritance
11
11
  # tree (e.g. return value of `Module#ancestors`) of the constant.
12
12
  #
13
+ # It is also unsafe because constants that the class body resolves through its
14
+ # ancestors (e.g. one provided by an included module) fall out of scope inside
15
+ # the block.
16
+ #
13
17
  # @example
14
18
  # # bad
15
19
  # class Person < Data.define(:first_name, :last_name)
@@ -42,6 +46,7 @@ module RuboCop
42
46
 
43
47
  def on_class(node)
44
48
  return unless data_define?(node.parent_class)
49
+ return if defines_constants?(node.body)
45
50
 
46
51
  add_offense(node.parent_class) do |corrector|
47
52
  corrector.remove(range_with_surrounding_space(node.loc.keyword, newlines: false))
@@ -59,6 +64,15 @@ module RuboCop
59
64
 
60
65
  private
61
66
 
67
+ # Constants, including nested classes and modules, are scoped to the class when they
68
+ # are defined in a class body, but leak into the enclosing namespace once moved into a
69
+ # `Data.define` block, so such a class cannot be rewritten as an assignment.
70
+ def defines_constants?(class_body)
71
+ return false unless class_body
72
+
73
+ class_body.each_node(:casgn, :class, :module).any?
74
+ end
75
+
62
76
  def correct_parent(parent, corrector)
63
77
  if parent.block_type?
64
78
  # Convert a brace block to `do`, so the class's own `end` closes it