rubocop 1.79.2 → 1.87.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 (376) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +185 -20
  5. data/config/obsoletion.yml +9 -0
  6. data/exe/rubocop +1 -8
  7. data/lib/rubocop/cache_config.rb +29 -0
  8. data/lib/rubocop/cli/command/auto_generate_config.rb +30 -4
  9. data/lib/rubocop/cli/command/list_enabled_cops_for.rb +40 -0
  10. data/lib/rubocop/cli/command/lsp.rb +1 -1
  11. data/lib/rubocop/cli/command/mcp.rb +19 -0
  12. data/lib/rubocop/cli/command/show_cops.rb +2 -2
  13. data/lib/rubocop/cli/command/show_docs_url.rb +4 -8
  14. data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
  15. data/lib/rubocop/cli.rb +35 -9
  16. data/lib/rubocop/comment_config.rb +59 -17
  17. data/lib/rubocop/config.rb +14 -10
  18. data/lib/rubocop/config_finder.rb +1 -1
  19. data/lib/rubocop/config_loader.rb +37 -23
  20. data/lib/rubocop/config_loader_resolver.rb +20 -10
  21. data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -2
  22. data/lib/rubocop/config_store.rb +7 -2
  23. data/lib/rubocop/config_validator.rb +1 -1
  24. data/lib/rubocop/cop/autocorrect_logic.rb +10 -5
  25. data/lib/rubocop/cop/base.rb +8 -2
  26. data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
  27. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -2
  28. data/lib/rubocop/cop/correctors/alignment_corrector.rb +26 -7
  29. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
  30. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  31. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -5
  32. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +33 -2
  33. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  34. data/lib/rubocop/cop/correctors.rb +28 -0
  35. data/lib/rubocop/cop/documentation.rb +2 -3
  36. data/lib/rubocop/cop/exclude_limit.rb +31 -5
  37. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  38. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -2
  39. data/lib/rubocop/cop/gemspec/require_mfa.rb +5 -5
  40. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +12 -7
  41. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
  42. data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
  43. data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
  44. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
  45. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +9 -9
  46. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
  47. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
  48. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  49. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
  50. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  51. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -2
  52. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  53. data/lib/rubocop/cop/layout/begin_end_alignment.rb +1 -1
  54. data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
  55. data/lib/rubocop/cop/layout/class_structure.rb +14 -7
  56. data/lib/rubocop/cop/layout/dot_position.rb +2 -2
  57. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +26 -7
  58. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +31 -13
  59. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +2 -2
  60. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -0
  61. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +12 -2
  62. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +16 -2
  63. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +16 -2
  64. data/lib/rubocop/cop/layout/end_alignment.rb +10 -3
  65. data/lib/rubocop/cop/layout/first_argument_indentation.rb +34 -1
  66. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
  67. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +7 -1
  68. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
  69. data/lib/rubocop/cop/layout/hash_alignment.rb +3 -6
  70. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  71. data/lib/rubocop/cop/layout/heredoc_indentation.rb +33 -3
  72. data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
  73. data/lib/rubocop/cop/layout/indentation_width.rb +123 -7
  74. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
  75. data/lib/rubocop/cop/layout/line_length.rb +26 -9
  76. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
  77. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
  78. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
  79. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
  80. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
  81. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +229 -39
  82. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
  83. data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
  84. data/lib/rubocop/cop/layout/redundant_line_break.rb +3 -1
  85. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +13 -3
  86. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
  87. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  88. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  89. data/lib/rubocop/cop/layout/space_around_keyword.rb +4 -2
  90. data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -1
  91. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -8
  92. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  93. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  94. data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -3
  95. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +4 -3
  96. data/lib/rubocop/cop/lint/constant_reassignment.rb +93 -11
  97. data/lib/rubocop/cop/lint/constant_resolution.rb +6 -6
  98. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +14 -8
  99. data/lib/rubocop/cop/lint/data_define_override.rb +63 -0
  100. data/lib/rubocop/cop/lint/debugger.rb +0 -2
  101. data/lib/rubocop/cop/lint/deprecated_constants.rb +1 -1
  102. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
  103. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
  104. data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -12
  105. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  106. data/lib/rubocop/cop/lint/else_layout.rb +19 -0
  107. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  108. data/lib/rubocop/cop/lint/empty_conditional_body.rb +6 -1
  109. data/lib/rubocop/cop/lint/empty_in_pattern.rb +8 -1
  110. data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
  111. data/lib/rubocop/cop/lint/empty_when.rb +8 -1
  112. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  113. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  114. data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
  115. data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -1
  116. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  117. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +18 -9
  118. data/lib/rubocop/cop/lint/multiple_comparison.rb +2 -2
  119. data/lib/rubocop/cop/lint/next_without_accumulator.rb +2 -0
  120. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +4 -0
  121. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +4 -2
  122. data/lib/rubocop/cop/lint/number_conversion.rb +6 -6
  123. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
  124. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -13
  125. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
  126. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +2 -11
  127. data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
  128. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +23 -6
  129. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -2
  130. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +3 -3
  131. data/lib/rubocop/cop/lint/require_relative_self_path.rb +3 -1
  132. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  133. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -0
  134. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
  135. data/lib/rubocop/cop/lint/self_assignment.rb +15 -6
  136. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  137. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  138. data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
  139. data/lib/rubocop/cop/lint/syntax.rb +25 -1
  140. data/lib/rubocop/cop/lint/to_json.rb +12 -16
  141. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -0
  142. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -1
  143. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  144. data/lib/rubocop/cop/lint/unreachable_code.rb +7 -5
  145. data/lib/rubocop/cop/lint/unreachable_pattern_branch.rb +113 -0
  146. data/lib/rubocop/cop/lint/unused_method_argument.rb +10 -0
  147. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  148. data/lib/rubocop/cop/lint/useless_assignment.rb +48 -25
  149. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +4 -4
  150. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +2 -0
  151. data/lib/rubocop/cop/lint/useless_or.rb +15 -2
  152. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +1 -1
  153. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +37 -11
  154. data/lib/rubocop/cop/lint/void.rb +39 -12
  155. data/lib/rubocop/cop/message_annotator.rb +1 -1
  156. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  157. data/lib/rubocop/cop/metrics/block_nesting.rb +23 -0
  158. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  159. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
  160. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +1 -1
  161. data/lib/rubocop/cop/migration/department_name.rb +12 -1
  162. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  163. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +4 -6
  164. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  165. data/lib/rubocop/cop/mixin/configurable_max.rb +6 -5
  166. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  167. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +5 -5
  168. data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
  169. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -60
  170. data/lib/rubocop/cop/mixin/line_length_help.rb +21 -2
  171. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  172. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  173. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  174. data/lib/rubocop/cop/mixin/project_index_help.rb +48 -0
  175. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
  176. data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -6
  177. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -5
  178. data/lib/rubocop/cop/mixin.rb +86 -0
  179. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  180. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  181. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  182. data/lib/rubocop/cop/naming/method_name.rb +5 -3
  183. data/lib/rubocop/cop/naming/predicate_method.rb +32 -8
  184. data/lib/rubocop/cop/naming/predicate_prefix.rb +12 -12
  185. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  186. data/lib/rubocop/cop/offense.rb +17 -1
  187. data/lib/rubocop/cop/registry.rb +62 -38
  188. data/lib/rubocop/cop/security/eval.rb +15 -2
  189. data/lib/rubocop/cop/security/io_methods.rb +1 -1
  190. data/lib/rubocop/cop/security/json_load.rb +33 -11
  191. data/lib/rubocop/cop/style/access_modifier_declarations.rb +15 -4
  192. data/lib/rubocop/cop/style/accessor_grouping.rb +4 -2
  193. data/lib/rubocop/cop/style/alias.rb +14 -2
  194. data/lib/rubocop/cop/style/and_or.rb +1 -0
  195. data/lib/rubocop/cop/style/arguments_forwarding.rb +25 -7
  196. data/lib/rubocop/cop/style/array_intersect.rb +46 -12
  197. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  198. data/lib/rubocop/cop/style/array_join.rb +4 -2
  199. data/lib/rubocop/cop/style/ascii_comments.rb +6 -3
  200. data/lib/rubocop/cop/style/attr.rb +5 -2
  201. data/lib/rubocop/cop/style/bare_percent_literals.rb +4 -3
  202. data/lib/rubocop/cop/style/begin_block.rb +3 -1
  203. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  204. data/lib/rubocop/cop/style/block_delimiters.rb +27 -34
  205. data/lib/rubocop/cop/style/case_equality.rb +15 -13
  206. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  207. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -2
  208. data/lib/rubocop/cop/style/collection_compact.rb +36 -16
  209. data/lib/rubocop/cop/style/colon_method_call.rb +3 -1
  210. data/lib/rubocop/cop/style/concat_array_literals.rb +2 -0
  211. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -18
  212. data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
  213. data/lib/rubocop/cop/style/copyright.rb +22 -11
  214. data/lib/rubocop/cop/style/date_time.rb +2 -2
  215. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  216. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +6 -1
  217. data/lib/rubocop/cop/style/documentation.rb +6 -6
  218. data/lib/rubocop/cop/style/documentation_method.rb +8 -8
  219. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  220. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  221. data/lib/rubocop/cop/style/each_with_object.rb +2 -0
  222. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  223. data/lib/rubocop/cop/style/empty_class_definition.rb +119 -0
  224. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  225. data/lib/rubocop/cop/style/empty_method.rb +0 -6
  226. data/lib/rubocop/cop/style/encoding.rb +7 -1
  227. data/lib/rubocop/cop/style/end_block.rb +3 -1
  228. data/lib/rubocop/cop/style/endless_method.rb +23 -5
  229. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  230. data/lib/rubocop/cop/style/file_open.rb +84 -0
  231. data/lib/rubocop/cop/style/file_write.rb +18 -16
  232. data/lib/rubocop/cop/style/float_division.rb +15 -1
  233. data/lib/rubocop/cop/style/for.rb +3 -0
  234. data/lib/rubocop/cop/style/format_string.rb +4 -3
  235. data/lib/rubocop/cop/style/format_string_token.rb +49 -5
  236. data/lib/rubocop/cop/style/global_vars.rb +5 -2
  237. data/lib/rubocop/cop/style/guard_clause.rb +27 -22
  238. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +27 -9
  239. data/lib/rubocop/cop/style/hash_conversion.rb +1 -1
  240. data/lib/rubocop/cop/style/hash_lookup_method.rb +106 -0
  241. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  242. data/lib/rubocop/cop/style/hash_transform_keys.rb +17 -7
  243. data/lib/rubocop/cop/style/hash_transform_values.rb +17 -7
  244. data/lib/rubocop/cop/style/if_inside_else.rb +16 -7
  245. data/lib/rubocop/cop/style/if_unless_modifier.rb +57 -17
  246. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -12
  247. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +4 -1
  248. data/lib/rubocop/cop/style/if_with_semicolon.rb +7 -5
  249. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  250. data/lib/rubocop/cop/style/inline_comment.rb +4 -1
  251. data/lib/rubocop/cop/style/ip_addresses.rb +1 -2
  252. data/lib/rubocop/cop/style/lambda_call.rb +8 -8
  253. data/lib/rubocop/cop/style/magic_comment_format.rb +3 -3
  254. data/lib/rubocop/cop/style/map_join.rb +123 -0
  255. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +15 -2
  256. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +17 -4
  257. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -4
  258. data/lib/rubocop/cop/style/min_max_comparison.rb +1 -1
  259. data/lib/rubocop/cop/style/module_member_existence_check.rb +110 -0
  260. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  261. data/lib/rubocop/cop/style/multiline_method_signature.rb +2 -4
  262. data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
  263. data/lib/rubocop/cop/style/negative_array_index.rb +220 -0
  264. data/lib/rubocop/cop/style/nil_comparison.rb +11 -10
  265. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  266. data/lib/rubocop/cop/style/non_nil_check.rb +5 -11
  267. data/lib/rubocop/cop/style/not.rb +2 -0
  268. data/lib/rubocop/cop/style/numeric_literals.rb +3 -2
  269. data/lib/rubocop/cop/style/one_class_per_file.rb +115 -0
  270. data/lib/rubocop/cop/style/one_line_conditional.rb +21 -12
  271. data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
  272. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -2
  273. data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
  274. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -0
  275. data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
  276. data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
  277. data/lib/rubocop/cop/style/proc.rb +3 -2
  278. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  279. data/lib/rubocop/cop/style/reduce_to_hash.rb +200 -0
  280. data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
  281. data/lib/rubocop/cop/style/redundant_array_constructor.rb +2 -2
  282. data/lib/rubocop/cop/style/redundant_begin.rb +37 -3
  283. data/lib/rubocop/cop/style/redundant_condition.rb +6 -3
  284. data/lib/rubocop/cop/style/redundant_constant_base.rb +5 -5
  285. data/lib/rubocop/cop/style/redundant_each.rb +3 -3
  286. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  287. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  288. data/lib/rubocop/cop/style/redundant_format.rb +26 -5
  289. data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
  290. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
  291. data/lib/rubocop/cop/style/redundant_line_continuation.rb +16 -0
  292. data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
  293. data/lib/rubocop/cop/style/redundant_parentheses.rb +36 -30
  294. data/lib/rubocop/cop/style/redundant_percent_q.rb +5 -3
  295. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
  296. data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +2 -2
  297. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  298. data/lib/rubocop/cop/style/redundant_return.rb +3 -1
  299. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  300. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +0 -5
  301. data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
  302. data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +114 -0
  303. data/lib/rubocop/cop/style/regexp_literal.rb +31 -2
  304. data/lib/rubocop/cop/style/rescue_modifier.rb +3 -3
  305. data/lib/rubocop/cop/style/reverse_find.rb +51 -0
  306. data/lib/rubocop/cop/style/safe_navigation.rb +25 -8
  307. data/lib/rubocop/cop/style/select_by_kind.rb +158 -0
  308. data/lib/rubocop/cop/style/select_by_range.rb +197 -0
  309. data/lib/rubocop/cop/style/select_by_regexp.rb +51 -21
  310. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  311. data/lib/rubocop/cop/style/semicolon.rb +25 -7
  312. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
  313. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -1
  314. data/lib/rubocop/cop/style/single_line_methods.rb +3 -1
  315. data/lib/rubocop/cop/style/sole_nested_conditional.rb +12 -3
  316. data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
  317. data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
  318. data/lib/rubocop/cop/style/struct_inheritance.rb +13 -0
  319. data/lib/rubocop/cop/style/super_arguments.rb +2 -2
  320. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  321. data/lib/rubocop/cop/style/symbol_proc.rb +7 -6
  322. data/lib/rubocop/cop/style/tally_method.rb +181 -0
  323. data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -2
  324. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  325. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  326. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
  327. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +11 -11
  328. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  329. data/lib/rubocop/cop/style/unless_logical_operators.rb +3 -3
  330. data/lib/rubocop/cop/style/while_until_modifier.rb +16 -0
  331. data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
  332. data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
  333. data/lib/rubocop/cop/team.rb +87 -36
  334. data/lib/rubocop/cop/util.rb +2 -3
  335. data/lib/rubocop/cop/utils/format_string.rb +10 -0
  336. data/lib/rubocop/cop/variable_force/branch.rb +30 -6
  337. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  338. data/lib/rubocop/cop/variable_force.rb +9 -7
  339. data/lib/rubocop/cops_documentation_generator.rb +4 -4
  340. data/lib/rubocop/directive_comment.rb +48 -4
  341. data/lib/rubocop/file_patterns.rb +9 -1
  342. data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
  343. data/lib/rubocop/formatter/disabled_config_formatter.rb +24 -7
  344. data/lib/rubocop/formatter/formatter_set.rb +2 -2
  345. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  346. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
  347. data/lib/rubocop/formatter/tap_formatter.rb +5 -2
  348. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
  349. data/lib/rubocop/formatter.rb +22 -21
  350. data/lib/rubocop/lsp/diagnostic.rb +18 -33
  351. data/lib/rubocop/lsp/disable_comment_edits.rb +135 -0
  352. data/lib/rubocop/lsp/routes.rb +43 -7
  353. data/lib/rubocop/lsp/runtime.rb +13 -4
  354. data/lib/rubocop/lsp/stdin_runner.rb +8 -17
  355. data/lib/rubocop/magic_comment.rb +20 -0
  356. data/lib/rubocop/mcp/server.rb +200 -0
  357. data/lib/rubocop/options.rb +35 -4
  358. data/lib/rubocop/path_util.rb +14 -2
  359. data/lib/rubocop/plugin/loader.rb +1 -1
  360. data/lib/rubocop/project_index_loader.rb +66 -0
  361. data/lib/rubocop/rake_task.rb +1 -1
  362. data/lib/rubocop/remote_config.rb +10 -8
  363. data/lib/rubocop/result_cache.rb +61 -38
  364. data/lib/rubocop/rspec/cop_helper.rb +8 -0
  365. data/lib/rubocop/rspec/shared_contexts.rb +39 -5
  366. data/lib/rubocop/rspec/support.rb +2 -1
  367. data/lib/rubocop/runner.rb +134 -57
  368. data/lib/rubocop/server/cache.rb +6 -29
  369. data/lib/rubocop/server/core.rb +2 -0
  370. data/lib/rubocop/target_finder.rb +17 -10
  371. data/lib/rubocop/target_ruby.rb +31 -14
  372. data/lib/rubocop/version.rb +21 -3
  373. data/lib/rubocop.rb +28 -96
  374. data/lib/ruby_lsp/rubocop/addon.rb +23 -8
  375. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
  376. metadata +38 -9
@@ -14,6 +14,8 @@ module RuboCop
14
14
  private
15
15
 
16
16
  def too_long?(node)
17
+ return false unless max_line_length
18
+
17
19
  lines = processed_source.lines[(node.first_line - 1)...node.last_line]
18
20
  to_single_line(lines.join("\n")).length > max_line_length
19
21
  end
@@ -27,10 +29,6 @@ module RuboCop
27
29
  .gsub(/\s*\\?\n\s*/, ' ') # Any other line break, with or without backslash
28
30
  end
29
31
 
30
- def max_line_length
31
- config.for_cop('Layout/LineLength')['Max']
32
- end
33
-
34
32
  def comment_within?(node)
35
33
  comment_line_numbers = processed_source.comments.map { |comment| comment.loc.line }
36
34
 
@@ -40,9 +38,9 @@ module RuboCop
40
38
  end
41
39
 
42
40
  def safe_to_split?(node)
43
- node.each_descendant(:if, :case, :kwbegin, :any_def).none? &&
41
+ node.each_descendant(:if, :case, :kwbegin, :any_def, :rescue, :ensure).none? &&
44
42
  node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
45
- node.each_descendant(:begin, :sym).none? { |b| !b.single_line? }
43
+ node.each_descendant(:begin, :sym).none?(&:multiline?)
46
44
  end
47
45
  end
48
46
  end
@@ -59,7 +59,7 @@ module RuboCop
59
59
  return node.loc.name if node.casgn_type?
60
60
 
61
61
  if LSP.enabled?
62
- end_range = node.loc.respond_to?(:name) ? node.loc.name : node.loc.begin
62
+ end_range = node.loc?(:name) ? node.loc.name : node.loc.begin
63
63
  node.source_range.begin.join(end_range)
64
64
  else
65
65
  node.source_range
@@ -13,11 +13,12 @@ module RuboCop
13
13
  `max=` is deprecated. Use `exclude_limit <ParameterName>` instead.
14
14
  WARNING
15
15
 
16
- cfg = config_to_allow_offenses
17
- cfg[:exclude_limit] ||= {}
18
- current_max = cfg[:exclude_limit][max_parameter_name]
19
- value = [current_max, value].max if current_max
20
- cfg[:exclude_limit][max_parameter_name] = value
16
+ cop_dir = RuboCop::ExcludeLimit.cop_dir_for(self.class.badge.to_s)
17
+ return unless cop_dir
18
+
19
+ cop_dir.mkpath
20
+ filepath = cop_dir.join(max_parameter_name)
21
+ filepath.write("#{value}\n", mode: 'a')
21
22
  end
22
23
 
23
24
  def max_parameter_name
@@ -19,8 +19,7 @@ module RuboCop
19
19
  def check_end_kw_alignment(node, align_ranges)
20
20
  return if ignored_node?(node)
21
21
 
22
- end_loc = node.loc.end
23
- return if accept_end_kw_alignment?(end_loc)
22
+ return unless (end_loc = node.loc.end)
24
23
 
25
24
  matching = matching_ranges(end_loc, align_ranges)
26
25
 
@@ -57,11 +56,6 @@ module RuboCop
57
56
  add_offense(end_loc, message: msg) { |corrector| autocorrect(corrector, node) }
58
57
  end
59
58
 
60
- def accept_end_kw_alignment?(end_loc)
61
- end_loc.nil? || # Discard modifier forms of if/while/until.
62
- !/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1])
63
- end
64
-
65
59
  def style_parameter_name
66
60
  'EnforcedStyleAlignWith'
67
61
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
 
14
14
  DefNode = Struct.new(:node) do
15
15
  def selector
16
- if node.loc.respond_to?(:selector)
16
+ if node.loc?(:selector)
17
17
  node.loc.selector
18
18
  else
19
19
  node.loc.keyword
@@ -125,7 +125,7 @@ module RuboCop
125
125
  return if dispatch_node.assignment_method?
126
126
  return if dispatch_node.parenthesized?
127
127
  return if dispatch_node.parent && parentheses?(dispatch_node.parent)
128
- return if last_expression?(dispatch_node) && !method_dispatch_as_argument?(dispatch_node)
128
+ return if last_expression?(dispatch_node) && !requires_parentheses_context?(dispatch_node)
129
129
 
130
130
  def_node = node.each_ancestor(:call, :super, :yield).first
131
131
 
@@ -164,11 +164,11 @@ module RuboCop
164
164
  !assignment_node.right_sibling
165
165
  end
166
166
 
167
- def method_dispatch_as_argument?(method_dispatch_node)
168
- parent = method_dispatch_node.parent
167
+ def requires_parentheses_context?(node)
168
+ parent = node.parent
169
169
  return false unless parent
170
170
 
171
- parent.type?(:call, :super, :yield)
171
+ parent.type?(:call, :if, :super, :until, :while, :yield)
172
172
  end
173
173
 
174
174
  def breakdown_value_types_of_hash(hash_node)
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module HashTransformMethod
6
+ # Internal helper class to hold autocorrect data
7
+ Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do
8
+ def self.from_each_with_object(node, match)
9
+ new(match, node, 0, 0)
10
+ end
11
+
12
+ def self.from_hash_brackets_map(node, match)
13
+ new(match, node.children.last, 'Hash['.length, ']'.length)
14
+ end
15
+
16
+ def self.from_map_to_h(node, match)
17
+ if node.parent&.block_type? && node.parent.send_node == node
18
+ strip_trailing_chars = 0
19
+ else
20
+ map_range = node.children.first.source_range
21
+ node_range = node.source_range
22
+ strip_trailing_chars = node_range.end_pos - map_range.end_pos
23
+ end
24
+
25
+ new(match, node.children.first, 0, strip_trailing_chars)
26
+ end
27
+
28
+ def self.from_to_h(node, match)
29
+ new(match, node, 0, 0)
30
+ end
31
+
32
+ def strip_prefix_and_suffix(node, corrector)
33
+ expression = node.source_range
34
+ corrector.remove_leading(expression, leading)
35
+ corrector.remove_trailing(expression, trailing)
36
+ end
37
+
38
+ def set_new_method_name(new_method_name, corrector)
39
+ range = block_node.send_node.loc.selector
40
+ if (send_end = block_node.send_node.loc.end)
41
+ # If there are arguments (only true in the `each_with_object`
42
+ # case)
43
+ range = range.begin.join(send_end)
44
+ end
45
+ corrector.replace(range, new_method_name)
46
+ end
47
+
48
+ def set_new_arg_name(transformed_argname, corrector)
49
+ corrector.replace(block_node.arguments, "|#{transformed_argname}|")
50
+ end
51
+
52
+ def set_new_body_expression(transforming_body_expr, corrector)
53
+ body_source = transforming_body_expr.source
54
+ if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
55
+ body_source = "{ #{body_source} }"
56
+ end
57
+
58
+ corrector.replace(block_node.body, body_source)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'hash_transform_method/autocorrection'
4
+
3
5
  module RuboCop
4
6
  module Cop
5
7
  # Common functionality for Style/HashTransformKeys and
@@ -27,68 +29,16 @@ module RuboCop
27
29
  end
28
30
  end
29
31
 
30
- # Internal helper class to hold autocorrect data
31
- Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do
32
- def self.from_each_with_object(node, match)
33
- new(match, node, 0, 0)
34
- end
35
-
36
- def self.from_hash_brackets_map(node, match)
37
- new(match, node.children.last, 'Hash['.length, ']'.length)
38
- end
39
-
40
- def self.from_map_to_h(node, match)
41
- if node.parent&.block_type? && node.parent.send_node == node
42
- strip_trailing_chars = 0
43
- else
44
- map_range = node.children.first.source_range
45
- node_range = node.source_range
46
- strip_trailing_chars = node_range.end_pos - map_range.end_pos
47
- end
48
-
49
- new(match, node.children.first, 0, strip_trailing_chars)
50
- end
51
-
52
- def self.from_to_h(node, match)
53
- new(match, node, 0, 0)
54
- end
55
-
56
- def strip_prefix_and_suffix(node, corrector)
57
- expression = node.source_range
58
- corrector.remove_leading(expression, leading)
59
- corrector.remove_trailing(expression, trailing)
60
- end
61
-
62
- def set_new_method_name(new_method_name, corrector)
63
- range = block_node.send_node.loc.selector
64
- if (send_end = block_node.send_node.loc.end)
65
- # If there are arguments (only true in the `each_with_object`
66
- # case)
67
- range = range.begin.join(send_end)
68
- end
69
- corrector.replace(range, new_method_name)
70
- end
71
-
72
- def set_new_arg_name(transformed_argname, corrector)
73
- corrector.replace(block_node.arguments, "|#{transformed_argname}|")
74
- end
75
-
76
- def set_new_body_expression(transforming_body_expr, corrector)
77
- body_source = transforming_body_expr.source
78
- if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
79
- body_source = "{ #{body_source} }"
80
- end
81
-
82
- corrector.replace(block_node.body, body_source)
83
- end
84
- end
85
-
86
- # @!method array_receiver?(node)
87
- def_node_matcher :array_receiver?, <<~PATTERN
88
- {(array ...) (send _ :each_with_index) (send _ :with_index _ ?) (send _ :zip ...)}
32
+ # @!method hash_receiver?(node)
33
+ def_node_matcher :hash_receiver?, <<~PATTERN
34
+ {(hash ...)
35
+ (send _ {:to_h :to_hash :merge :merge! :update :invert :except :tally} ...)
36
+ (block (send _ {:group_by :to_h :tally :transform_keys :transform_keys!
37
+ :transform_values :transform_values!}) ...)
38
+ (block (send _ :each_with_object (hash)) ...)}
89
39
  PATTERN
90
40
 
91
- def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
41
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
92
42
  on_bad_each_with_object(node) do |*match|
93
43
  handle_possible_offense(node, match, 'each_with_object')
94
44
  end
@@ -8,8 +8,27 @@ module RuboCop
8
8
 
9
9
  private
10
10
 
11
- def ignore_cop_directives?
12
- config.for_cop('Layout/LineLength')['IgnoreCopDirectives']
11
+ def allow_rbs_inline_annotation?
12
+ config.for_cop('Layout/LineLength')['AllowRBSInlineAnnotation']
13
+ end
14
+
15
+ def rbs_inline_annotation_on_source_line?(line_index)
16
+ source_line_number = line_index + processed_source.buffer.first_line
17
+ comment = processed_source.comment_at_line(source_line_number)
18
+
19
+ return false unless comment
20
+
21
+ comment.text.start_with?(/#:|#\[.+\]|#\|/)
22
+ end
23
+
24
+ def allow_cop_directives?
25
+ # TODO: This logic for backward compatibility with deprecated `IgnoreCopDirectives` option.
26
+ # The following three lines will be removed in RuboCop 2.0.
27
+ ignore_cop_directives = config.for_cop('Layout/LineLength')['IgnoreCopDirectives']
28
+ return true if ignore_cop_directives
29
+ return false if ignore_cop_directives == false
30
+
31
+ config.for_cop('Layout/LineLength')['AllowCopDirectives']
13
32
  end
14
33
 
15
34
  def directive_on_source_line?(line_index)
@@ -73,7 +73,7 @@ module RuboCop
73
73
 
74
74
  def location(node)
75
75
  if LSP.enabled?
76
- end_range = node.loc.respond_to?(:name) ? node.loc.name : node.loc.begin
76
+ end_range = node.loc?(:name) ? node.loc.name : node.loc.begin
77
77
  node.source_range.begin.join(end_range)
78
78
  else
79
79
  node.source_range
@@ -200,7 +200,7 @@ module RuboCop
200
200
  end
201
201
 
202
202
  def grouped_expression?(node)
203
- node.begin_type? && node.loc.respond_to?(:begin) && node.loc.begin
203
+ node.begin_type? && node.loc?(:begin) && node.loc.begin
204
204
  end
205
205
 
206
206
  def inside_arg_list_parentheses?(node, ancestor)
@@ -127,7 +127,7 @@ module RuboCop
127
127
  parent ||= node
128
128
 
129
129
  if node.respond_to?(:loc) &&
130
- node.loc.respond_to?(:heredoc_end) &&
130
+ node.loc?(:heredoc_end) &&
131
131
  node.loc.heredoc_end.last_line >= parent.last_line
132
132
  return true
133
133
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # Common helpers for cops that consult the project-wide static-analysis index
6
+ # via `Cop::Base#project_index`.
7
+ #
8
+ # Mixed-in cops gain the `external_dependency_checksum` override that invalidates
9
+ # the `ResultCache` whenever the indexed project files change on disk.
10
+ # To run index-backed analysis, cops should simply check whether `project_index` is non-nil;
11
+ # the runner only exposes a non-nil index when the user opted in via `AllCops/UseProjectIndex`
12
+ # and the underlying gem is available.
13
+ module ProjectIndexHelp
14
+ BUILTIN_DOCUMENT_URI = 'rubydex:built-in'
15
+ FILE_URI_PREFIX = 'file://'
16
+ # Matches the spurious leading slash before a Windows drive letter that
17
+ # remains after stripping `file://` from a `file:///C:/...` URI.
18
+ WINDOWS_DRIVE_PREFIX = %r{\A/(?=[A-Za-z]:[/\\])}.freeze
19
+
20
+ def external_dependency_checksum
21
+ return nil unless project_index
22
+
23
+ @external_dependency_checksum ||= Digest::SHA1.hexdigest(
24
+ project_index_signature.join("\n")
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ def project_index_signature
31
+ project_index.documents.filter_map do |doc|
32
+ uri = doc.uri
33
+ next if uri == BUILTIN_DOCUMENT_URI
34
+
35
+ path = uri.delete_prefix(FILE_URI_PREFIX).sub(WINDOWS_DRIVE_PREFIX, '')
36
+ mtime, size = begin
37
+ stat = File.stat(path)
38
+ [stat.mtime.to_f, stat.size]
39
+ rescue StandardError
40
+ [0, 0]
41
+ end
42
+
43
+ "#{path}:#{mtime}:#{size}"
44
+ end.sort
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,8 +8,8 @@ module RuboCop
8
8
  MSG = 'Space missing after %<token>s.'
9
9
 
10
10
  def on_new_investigation
11
- each_missing_space(processed_source.tokens) do |token|
12
- add_offense(token.pos, message: format(MSG, token: kind(token))) do |corrector|
11
+ each_missing_space(processed_source.tokens) do |token, kind|
12
+ add_offense(token.pos, message: format(MSG, token: kind)) do |corrector|
13
13
  PunctuationCorrector.add_space(corrector, token)
14
14
  end
15
15
  end
@@ -19,11 +19,12 @@ module RuboCop
19
19
 
20
20
  def each_missing_space(tokens)
21
21
  tokens.each_cons(2) do |token1, token2|
22
- next unless kind(token1)
22
+ kind = kind(token1, token2)
23
+ next unless kind
23
24
  next unless space_missing?(token1, token2)
24
25
  next unless space_required_before?(token2)
25
26
 
26
- yield token1
27
+ yield token1, kind
27
28
  end
28
29
  end
29
30
 
@@ -100,12 +100,6 @@ module RuboCop
100
100
  node.parent.send_type?
101
101
  end
102
102
 
103
- def max_line_length
104
- return unless config.cop_enabled?('Layout/LineLength')
105
-
106
- config.for_cop('Layout/LineLength')['Max']
107
- end
108
-
109
103
  def comment_disables_cop?(comment)
110
104
  regexp_pattern = "# rubocop : (disable|todo) ([^,],)* (all|#{cop_name})"
111
105
  Regexp.new(regexp_pattern.gsub(' ', '\s*')).match?(comment)
@@ -95,13 +95,16 @@ module RuboCop
95
95
  node.multiline? && !allowed_multiline_argument?(node)
96
96
  end
97
97
 
98
+ # rubocop:disable Metrics/AbcSize
98
99
  def method_name_and_arguments_on_same_line?(node)
99
- return false unless node.call_type?
100
+ return false if !node.call_type? || node.last_line != node.last_argument.last_line
101
+ return true if node.last_argument.hash_type? && node.last_argument.braces?
100
102
 
101
- line = node.loc.selector.nil? ? node.loc.line : node.loc.selector.line
103
+ line = node.loc.selector&.line || node.loc.line
102
104
 
103
- line == node.last_argument.last_line && node.last_line == node.last_argument.last_line
105
+ line == node.last_argument.last_line
104
106
  end
107
+ # rubocop:enable Metrics/AbcSize
105
108
 
106
109
  # A single argument with the closing bracket on the same line as the end
107
110
  # of the argument is not considered multiline, even if the argument
@@ -140,7 +143,7 @@ module RuboCop
140
143
  end
141
144
 
142
145
  def last_item_precedes_newline?(node)
143
- after_last_item = node.children.last.source_range.end.join(node.loc.end.begin)
146
+ after_last_item = node.children.last.source_range.end.join(node.source_range.end)
144
147
 
145
148
  after_last_item.source.start_with?(/,?\s*(#.*)?\n/)
146
149
  end
@@ -185,7 +188,7 @@ module RuboCop
185
188
 
186
189
  def heredoc?(node)
187
190
  return false unless node.is_a?(RuboCop::AST::Node)
188
- return true if node.loc.respond_to?(:heredoc_body)
191
+ return true if node.loc?(:heredoc_body)
189
192
 
190
193
  return heredoc_send?(node) if node.send_type?
191
194
 
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop # rubocop:disable Style/Documentation
5
+ # Autoloads mixin modules included by cops. Mixins are autoloaded to reduce the number of
6
+ # requires because they're used only when the relevant cop class is loaded.
7
+
8
+ autoload :ArrayMinSize, 'rubocop/cop/mixin/array_min_size'
9
+ autoload :ArraySyntax, 'rubocop/cop/mixin/array_syntax'
10
+ autoload :Alignment, 'rubocop/cop/mixin/alignment'
11
+ autoload :AllowedIdentifiers, 'rubocop/cop/mixin/allowed_identifiers'
12
+ autoload :AllowedMethods, 'rubocop/cop/mixin/allowed_methods'
13
+ autoload :AllowedPattern, 'rubocop/cop/mixin/allowed_pattern'
14
+ autoload :AllowedReceivers, 'rubocop/cop/mixin/allowed_receivers'
15
+ autoload :ForbiddenIdentifiers, 'rubocop/cop/mixin/forbidden_identifiers'
16
+ autoload :ForbiddenPattern, 'rubocop/cop/mixin/forbidden_pattern'
17
+ autoload :AutoCorrector, 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
18
+ autoload :CheckAssignment, 'rubocop/cop/mixin/check_assignment'
19
+ autoload :CheckLineBreakable, 'rubocop/cop/mixin/check_line_breakable'
20
+ autoload :CheckSingleLineSuitability, 'rubocop/cop/mixin/check_single_line_suitability'
21
+ autoload :ConfigurableMax, 'rubocop/cop/mixin/configurable_max'
22
+ autoload :CodeLength, 'rubocop/cop/mixin/code_length'
23
+ autoload :ConfigurableEnforcedStyle, 'rubocop/cop/mixin/configurable_enforced_style'
24
+ autoload :ConfigurableFormatting, 'rubocop/cop/mixin/configurable_formatting'
25
+ autoload :ConfigurableNaming, 'rubocop/cop/mixin/configurable_naming'
26
+ autoload :ConfigurableNumbering, 'rubocop/cop/mixin/configurable_numbering'
27
+ autoload :DigHelp, 'rubocop/cop/mixin/dig_help'
28
+ autoload :DocumentationComment, 'rubocop/cop/mixin/documentation_comment'
29
+ autoload :Duplication, 'rubocop/cop/mixin/duplication'
30
+ autoload :RangeHelp, 'rubocop/cop/mixin/range_help'
31
+ autoload :ProjectIndexHelp, 'rubocop/cop/mixin/project_index_help'
32
+ autoload :AnnotationComment, 'rubocop/cop/mixin/annotation_comment'
33
+ autoload :EmptyParameter, 'rubocop/cop/mixin/empty_parameter'
34
+ autoload :EndKeywordAlignment, 'rubocop/cop/mixin/end_keyword_alignment'
35
+ autoload :EndlessMethodRewriter, 'rubocop/cop/mixin/endless_method_rewriter'
36
+ autoload :EnforceSuperclass, 'rubocop/cop/mixin/enforce_superclass'
37
+ autoload :FirstElementLineBreak, 'rubocop/cop/mixin/first_element_line_break'
38
+ autoload :FrozenStringLiteral, 'rubocop/cop/mixin/frozen_string_literal'
39
+ autoload :GemDeclaration, 'rubocop/cop/mixin/gem_declaration'
40
+ autoload :GemspecHelp, 'rubocop/cop/mixin/gemspec_help'
41
+ autoload :HashAlignmentStyles, 'rubocop/cop/mixin/hash_alignment_styles'
42
+ autoload :HashSubset, 'rubocop/cop/mixin/hash_subset'
43
+ autoload :HashTransformMethod, 'rubocop/cop/mixin/hash_transform_method'
44
+ autoload :IntegerNode, 'rubocop/cop/mixin/integer_node'
45
+ autoload :Interpolation, 'rubocop/cop/mixin/interpolation'
46
+ autoload :LineLengthHelp, 'rubocop/cop/mixin/line_length_help'
47
+ autoload :MatchRange, 'rubocop/cop/mixin/match_range'
48
+ autoload :HashShorthandSyntax, 'rubocop/cop/mixin/hash_shorthand_syntax'
49
+ autoload :MethodComplexity, 'rubocop/cop/mixin/method_complexity'
50
+ autoload :MethodPreference, 'rubocop/cop/mixin/method_preference'
51
+ autoload :MinBodyLength, 'rubocop/cop/mixin/min_body_length'
52
+ autoload :MinBranchesCount, 'rubocop/cop/mixin/min_branches_count'
53
+ autoload :MultilineElementIndentation, 'rubocop/cop/mixin/multiline_element_indentation'
54
+ autoload :MultilineElementLineBreaks, 'rubocop/cop/mixin/multiline_element_line_breaks'
55
+ autoload :MultilineExpressionIndentation, 'rubocop/cop/mixin/multiline_expression_indentation'
56
+ autoload :MultilineLiteralBraceLayout, 'rubocop/cop/mixin/multiline_literal_brace_layout'
57
+ autoload :NegativeConditional, 'rubocop/cop/mixin/negative_conditional'
58
+ autoload :Heredoc, 'rubocop/cop/mixin/heredoc'
59
+ autoload :NilMethods, 'rubocop/cop/mixin/nil_methods'
60
+ autoload :OnNormalIfUnless, 'rubocop/cop/mixin/on_normal_if_unless'
61
+ autoload :OrderedGemNode, 'rubocop/cop/mixin/ordered_gem_node'
62
+ autoload :Parentheses, 'rubocop/cop/mixin/parentheses'
63
+ autoload :PercentArray, 'rubocop/cop/mixin/percent_array'
64
+ autoload :PercentLiteral, 'rubocop/cop/mixin/percent_literal'
65
+ autoload :PrecedingFollowingAlignment, 'rubocop/cop/mixin/preceding_following_alignment'
66
+ autoload :PreferredDelimiters, 'rubocop/cop/mixin/preferred_delimiters'
67
+ autoload :RationalLiteral, 'rubocop/cop/mixin/rational_literal'
68
+ autoload :RequireLibrary, 'rubocop/cop/mixin/require_library'
69
+ autoload :RescueNode, 'rubocop/cop/mixin/rescue_node'
70
+ autoload :SafeAssignment, 'rubocop/cop/mixin/safe_assignment'
71
+ autoload :SpaceAfterPunctuation, 'rubocop/cop/mixin/space_after_punctuation'
72
+ autoload :SpaceBeforePunctuation, 'rubocop/cop/mixin/space_before_punctuation'
73
+ autoload :SurroundingSpace, 'rubocop/cop/mixin/surrounding_space'
74
+ autoload :StatementModifier, 'rubocop/cop/mixin/statement_modifier'
75
+ autoload :StringHelp, 'rubocop/cop/mixin/string_help'
76
+ autoload :StringLiteralsHelp, 'rubocop/cop/mixin/string_literals_help'
77
+ autoload :SymbolHelp, 'rubocop/cop/mixin/symbol_help'
78
+ autoload :TargetRubyVersion, 'rubocop/cop/mixin/target_ruby_version'
79
+ autoload :TrailingBody, 'rubocop/cop/mixin/trailing_body'
80
+ autoload :TrailingComma, 'rubocop/cop/mixin/trailing_comma'
81
+ autoload :UncommunicativeName, 'rubocop/cop/mixin/uncommunicative_name'
82
+ autoload :VisibilityHelp, 'rubocop/cop/mixin/visibility_help'
83
+ autoload :CommentsHelp, 'rubocop/cop/mixin/comments_help'
84
+ autoload :DefNode, 'rubocop/cop/mixin/def_node'
85
+ end
86
+ end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Naming
6
6
  # Makes sure that certain binary operator methods have their
7
- # sole parameter named `other`.
7
+ # sole parameter named `other`.
8
8
  #
9
9
  # @example
10
10
  #
@@ -38,7 +38,7 @@ module RuboCop
38
38
  class BlockParameterName < Base
39
39
  include UncommunicativeName
40
40
 
41
- def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
41
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
42
42
  return unless node.arguments?
43
43
 
44
44
  check(node, node.arguments)
@@ -109,7 +109,7 @@ module RuboCop
109
109
  # @_foo = calculate_expensive_thing
110
110
  # end
111
111
  #
112
- # @example EnforcedStyleForLeadingUnderscores :optional
112
+ # @example EnforcedStyleForLeadingUnderscores: optional
113
113
  # # bad
114
114
  # def foo
115
115
  # @something ||= calculate_expensive_thing
@@ -147,7 +147,9 @@ module RuboCop
147
147
  alias on_defs on_def
148
148
 
149
149
  def on_alias(node)
150
- handle_method_name(node.new_identifier, node.new_identifier.value)
150
+ return unless (new_identifier = node.new_identifier).sym_type?
151
+
152
+ handle_method_name(new_identifier, new_identifier.value)
151
153
  end
152
154
 
153
155
  private
@@ -198,7 +200,7 @@ module RuboCop
198
200
 
199
201
  if forbidden_name?(name.to_s)
200
202
  register_forbidden_name(node)
201
- elsif !OPERATOR_METHODS.include?(name)
203
+ elsif !OPERATOR_METHODS.include?(name.to_sym)
202
204
  check_name(node, name, range_position(node))
203
205
  end
204
206
  end
@@ -232,7 +234,7 @@ module RuboCop
232
234
  end
233
235
 
234
236
  def range_position(node)
235
- if node.loc.respond_to?(:selector)
237
+ if node.loc?(:selector)
236
238
  selector_end_pos = node.loc.selector.end_pos + 1
237
239
  expr_end_pos = node.source_range.end_pos
238
240