rubocop 1.80.2 → 1.86.1

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 (310) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +170 -19
  5. data/config/obsoletion.yml +9 -0
  6. data/lib/rubocop/cache_config.rb +29 -0
  7. data/lib/rubocop/cli/command/auto_generate_config.rb +3 -3
  8. data/lib/rubocop/cli/command/lsp.rb +1 -1
  9. data/lib/rubocop/cli/command/mcp.rb +19 -0
  10. data/lib/rubocop/cli/command/show_cops.rb +2 -2
  11. data/lib/rubocop/cli/command/show_docs_url.rb +1 -1
  12. data/lib/rubocop/cli.rb +28 -6
  13. data/lib/rubocop/comment_config.rb +62 -17
  14. data/lib/rubocop/config.rb +14 -10
  15. data/lib/rubocop/config_finder.rb +1 -1
  16. data/lib/rubocop/config_loader.rb +20 -21
  17. data/lib/rubocop/config_loader_resolver.rb +9 -7
  18. data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -2
  19. data/lib/rubocop/config_store.rb +6 -1
  20. data/lib/rubocop/config_validator.rb +1 -1
  21. data/lib/rubocop/cop/autocorrect_logic.rb +8 -4
  22. data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
  23. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -2
  24. data/lib/rubocop/cop/correctors/alignment_corrector.rb +22 -6
  25. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
  26. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  27. data/lib/rubocop/cop/documentation.rb +2 -3
  28. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -2
  29. data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
  30. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +10 -5
  31. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
  32. data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
  33. data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
  34. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +9 -9
  35. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
  36. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
  37. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  38. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
  39. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  40. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -2
  41. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  42. data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
  43. data/lib/rubocop/cop/layout/class_structure.rb +13 -6
  44. data/lib/rubocop/cop/layout/dot_position.rb +2 -2
  45. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +12 -2
  46. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +31 -13
  47. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +1 -1
  48. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -0
  49. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +12 -2
  50. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +16 -2
  51. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +16 -2
  52. data/lib/rubocop/cop/layout/end_alignment.rb +8 -1
  53. data/lib/rubocop/cop/layout/first_argument_indentation.rb +34 -1
  54. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
  55. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +7 -1
  56. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
  57. data/lib/rubocop/cop/layout/hash_alignment.rb +3 -6
  58. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  59. data/lib/rubocop/cop/layout/heredoc_indentation.rb +33 -3
  60. data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
  61. data/lib/rubocop/cop/layout/indentation_width.rb +111 -7
  62. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
  63. data/lib/rubocop/cop/layout/line_length.rb +26 -9
  64. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
  65. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
  66. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
  67. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
  68. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +204 -39
  69. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -4
  70. data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
  71. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
  72. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +13 -3
  73. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
  74. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  75. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  76. data/lib/rubocop/cop/layout/space_around_keyword.rb +4 -2
  77. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -8
  78. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  79. data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -3
  80. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
  81. data/lib/rubocop/cop/lint/constant_reassignment.rb +59 -9
  82. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  83. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +14 -8
  84. data/lib/rubocop/cop/lint/data_define_override.rb +63 -0
  85. data/lib/rubocop/cop/lint/debugger.rb +0 -2
  86. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
  87. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
  88. data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -12
  89. data/lib/rubocop/cop/lint/else_layout.rb +19 -0
  90. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  91. data/lib/rubocop/cop/lint/empty_conditional_body.rb +6 -1
  92. data/lib/rubocop/cop/lint/empty_in_pattern.rb +8 -1
  93. data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
  94. data/lib/rubocop/cop/lint/empty_when.rb +8 -1
  95. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  96. data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
  97. data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -1
  98. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  99. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +16 -6
  100. data/lib/rubocop/cop/lint/next_without_accumulator.rb +2 -0
  101. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +4 -0
  102. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -1
  103. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  104. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
  105. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +0 -9
  106. data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
  107. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +23 -6
  108. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -2
  109. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  110. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +17 -0
  111. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
  112. data/lib/rubocop/cop/lint/self_assignment.rb +10 -2
  113. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  114. data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
  115. data/lib/rubocop/cop/lint/syntax.rb +25 -1
  116. data/lib/rubocop/cop/lint/to_json.rb +12 -16
  117. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -0
  118. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  119. data/lib/rubocop/cop/lint/unreachable_code.rb +5 -3
  120. data/lib/rubocop/cop/lint/unreachable_pattern_branch.rb +113 -0
  121. data/lib/rubocop/cop/lint/unused_method_argument.rb +10 -0
  122. data/lib/rubocop/cop/lint/useless_assignment.rb +45 -17
  123. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +4 -4
  124. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +2 -0
  125. data/lib/rubocop/cop/lint/useless_or.rb +15 -2
  126. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +24 -9
  127. data/lib/rubocop/cop/lint/void.rb +39 -12
  128. data/lib/rubocop/cop/message_annotator.rb +1 -1
  129. data/lib/rubocop/cop/metrics/block_nesting.rb +23 -0
  130. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
  131. data/lib/rubocop/cop/migration/department_name.rb +12 -1
  132. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  133. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +4 -6
  134. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  135. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +5 -5
  136. data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
  137. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -60
  138. data/lib/rubocop/cop/mixin/line_length_help.rb +21 -2
  139. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  140. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  141. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  142. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
  143. data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -6
  144. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -5
  145. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  146. data/lib/rubocop/cop/naming/method_name.rb +4 -2
  147. data/lib/rubocop/cop/naming/predicate_method.rb +27 -4
  148. data/lib/rubocop/cop/naming/predicate_prefix.rb +11 -11
  149. data/lib/rubocop/cop/offense.rb +9 -1
  150. data/lib/rubocop/cop/registry.rb +20 -13
  151. data/lib/rubocop/cop/security/eval.rb +15 -2
  152. data/lib/rubocop/cop/security/json_load.rb +33 -11
  153. data/lib/rubocop/cop/style/access_modifier_declarations.rb +15 -4
  154. data/lib/rubocop/cop/style/accessor_grouping.rb +4 -2
  155. data/lib/rubocop/cop/style/alias.rb +4 -1
  156. data/lib/rubocop/cop/style/and_or.rb +1 -0
  157. data/lib/rubocop/cop/style/arguments_forwarding.rb +25 -7
  158. data/lib/rubocop/cop/style/array_intersect.rb +2 -2
  159. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  160. data/lib/rubocop/cop/style/array_join.rb +4 -2
  161. data/lib/rubocop/cop/style/ascii_comments.rb +6 -3
  162. data/lib/rubocop/cop/style/attr.rb +5 -2
  163. data/lib/rubocop/cop/style/bare_percent_literals.rb +4 -3
  164. data/lib/rubocop/cop/style/begin_block.rb +3 -1
  165. data/lib/rubocop/cop/style/block_delimiters.rb +27 -34
  166. data/lib/rubocop/cop/style/case_equality.rb +15 -13
  167. data/lib/rubocop/cop/style/class_and_module_children.rb +11 -2
  168. data/lib/rubocop/cop/style/collection_compact.rb +36 -16
  169. data/lib/rubocop/cop/style/colon_method_call.rb +3 -1
  170. data/lib/rubocop/cop/style/concat_array_literals.rb +2 -0
  171. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -18
  172. data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
  173. data/lib/rubocop/cop/style/copyright.rb +1 -1
  174. data/lib/rubocop/cop/style/documentation.rb +6 -6
  175. data/lib/rubocop/cop/style/documentation_method.rb +8 -8
  176. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  177. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  178. data/lib/rubocop/cop/style/each_with_object.rb +2 -0
  179. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  180. data/lib/rubocop/cop/style/empty_class_definition.rb +119 -0
  181. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  182. data/lib/rubocop/cop/style/empty_method.rb +0 -6
  183. data/lib/rubocop/cop/style/encoding.rb +7 -1
  184. data/lib/rubocop/cop/style/end_block.rb +3 -1
  185. data/lib/rubocop/cop/style/endless_method.rb +23 -5
  186. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  187. data/lib/rubocop/cop/style/file_open.rb +84 -0
  188. data/lib/rubocop/cop/style/float_division.rb +15 -1
  189. data/lib/rubocop/cop/style/for.rb +3 -0
  190. data/lib/rubocop/cop/style/format_string_token.rb +49 -5
  191. data/lib/rubocop/cop/style/global_vars.rb +5 -2
  192. data/lib/rubocop/cop/style/guard_clause.rb +27 -22
  193. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +27 -9
  194. data/lib/rubocop/cop/style/hash_lookup_method.rb +101 -0
  195. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  196. data/lib/rubocop/cop/style/hash_transform_keys.rb +17 -7
  197. data/lib/rubocop/cop/style/hash_transform_values.rb +17 -7
  198. data/lib/rubocop/cop/style/if_inside_else.rb +1 -5
  199. data/lib/rubocop/cop/style/if_unless_modifier.rb +57 -17
  200. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -12
  201. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +4 -1
  202. data/lib/rubocop/cop/style/if_with_semicolon.rb +7 -5
  203. data/lib/rubocop/cop/style/inline_comment.rb +4 -1
  204. data/lib/rubocop/cop/style/ip_addresses.rb +1 -2
  205. data/lib/rubocop/cop/style/lambda_call.rb +8 -8
  206. data/lib/rubocop/cop/style/magic_comment_format.rb +2 -2
  207. data/lib/rubocop/cop/style/map_join.rb +123 -0
  208. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +15 -2
  209. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +17 -4
  210. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -4
  211. data/lib/rubocop/cop/style/module_member_existence_check.rb +107 -0
  212. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  213. data/lib/rubocop/cop/style/multiline_method_signature.rb +2 -4
  214. data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
  215. data/lib/rubocop/cop/style/negative_array_index.rb +220 -0
  216. data/lib/rubocop/cop/style/nil_comparison.rb +11 -10
  217. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  218. data/lib/rubocop/cop/style/non_nil_check.rb +5 -11
  219. data/lib/rubocop/cop/style/not.rb +2 -0
  220. data/lib/rubocop/cop/style/numeric_literals.rb +3 -2
  221. data/lib/rubocop/cop/style/one_class_per_file.rb +115 -0
  222. data/lib/rubocop/cop/style/one_line_conditional.rb +21 -12
  223. data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
  224. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -2
  225. data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
  226. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -0
  227. data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
  228. data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
  229. data/lib/rubocop/cop/style/proc.rb +3 -2
  230. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  231. data/lib/rubocop/cop/style/reduce_to_hash.rb +184 -0
  232. data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
  233. data/lib/rubocop/cop/style/redundant_begin.rb +3 -3
  234. data/lib/rubocop/cop/style/redundant_condition.rb +5 -2
  235. data/lib/rubocop/cop/style/redundant_each.rb +3 -3
  236. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  237. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  238. data/lib/rubocop/cop/style/redundant_format.rb +26 -5
  239. data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
  240. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
  241. data/lib/rubocop/cop/style/redundant_line_continuation.rb +16 -0
  242. data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
  243. data/lib/rubocop/cop/style/redundant_parentheses.rb +26 -22
  244. data/lib/rubocop/cop/style/redundant_percent_q.rb +5 -3
  245. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
  246. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  247. data/lib/rubocop/cop/style/redundant_return.rb +3 -1
  248. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +0 -5
  249. data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
  250. data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +114 -0
  251. data/lib/rubocop/cop/style/reverse_find.rb +51 -0
  252. data/lib/rubocop/cop/style/safe_navigation.rb +7 -7
  253. data/lib/rubocop/cop/style/select_by_kind.rb +158 -0
  254. data/lib/rubocop/cop/style/select_by_range.rb +197 -0
  255. data/lib/rubocop/cop/style/select_by_regexp.rb +51 -21
  256. data/lib/rubocop/cop/style/semicolon.rb +25 -7
  257. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
  258. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -1
  259. data/lib/rubocop/cop/style/single_line_methods.rb +3 -1
  260. data/lib/rubocop/cop/style/sole_nested_conditional.rb +8 -1
  261. data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
  262. data/lib/rubocop/cop/style/super_arguments.rb +2 -2
  263. data/lib/rubocop/cop/style/symbol_proc.rb +4 -3
  264. data/lib/rubocop/cop/style/tally_method.rb +181 -0
  265. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  266. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  267. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
  268. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +11 -11
  269. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  270. data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
  271. data/lib/rubocop/cop/team.rb +4 -4
  272. data/lib/rubocop/cop/util.rb +2 -3
  273. data/lib/rubocop/cop/utils/format_string.rb +10 -0
  274. data/lib/rubocop/cop/variable_force/branch.rb +30 -6
  275. data/lib/rubocop/cops_documentation_generator.rb +4 -4
  276. data/lib/rubocop/directive_comment.rb +48 -4
  277. data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
  278. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
  279. data/lib/rubocop/formatter/formatter_set.rb +2 -2
  280. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  281. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
  282. data/lib/rubocop/formatter/tap_formatter.rb +5 -2
  283. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
  284. data/lib/rubocop/formatter.rb +22 -21
  285. data/lib/rubocop/lsp/diagnostic.rb +18 -33
  286. data/lib/rubocop/lsp/disable_comment_edits.rb +135 -0
  287. data/lib/rubocop/lsp/routes.rb +12 -5
  288. data/lib/rubocop/lsp/runtime.rb +13 -3
  289. data/lib/rubocop/lsp/stdin_runner.rb +8 -17
  290. data/lib/rubocop/magic_comment.rb +20 -0
  291. data/lib/rubocop/mcp/server.rb +200 -0
  292. data/lib/rubocop/options.rb +10 -1
  293. data/lib/rubocop/path_util.rb +14 -2
  294. data/lib/rubocop/plugin/loader.rb +1 -1
  295. data/lib/rubocop/rake_task.rb +1 -1
  296. data/lib/rubocop/remote_config.rb +10 -8
  297. data/lib/rubocop/result_cache.rb +60 -37
  298. data/lib/rubocop/rspec/cop_helper.rb +8 -0
  299. data/lib/rubocop/rspec/shared_contexts.rb +18 -5
  300. data/lib/rubocop/rspec/support.rb +2 -1
  301. data/lib/rubocop/runner.rb +12 -3
  302. data/lib/rubocop/server/cache.rb +6 -29
  303. data/lib/rubocop/server/core.rb +2 -0
  304. data/lib/rubocop/target_finder.rb +1 -1
  305. data/lib/rubocop/target_ruby.rb +31 -14
  306. data/lib/rubocop/version.rb +2 -2
  307. data/lib/rubocop.rb +20 -0
  308. data/lib/ruby_lsp/rubocop/addon.rb +23 -8
  309. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
  310. metadata +33 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 427aedeb12fa3d9d84e7ccd8ea4c125b418a3170c0f91d02e66ef8717006fc0a
4
- data.tar.gz: f5a5b09520f27ed77d9cc5e2077ce9a55fa77db97bdd1d593e399551abd45bb8
3
+ metadata.gz: e7e3463c6020de496396b13ecf80f691f532af83ac8f8627286f3887f07b11b2
4
+ data.tar.gz: 9e8c332d0f33ea078abcc71e0ddb7cd009497842a026dfdcae103a63fc909ba6
5
5
  SHA512:
6
- metadata.gz: ddcf6fc4b8e900f900f5734c647b3d681d731d6d4bf37729c4960a751ace231d8835ca9800d4e499d1908f7e0474445bbf2490f5c8b9408d1301d6bff1196794
7
- data.tar.gz: 94f856e78e6af3c0c78fd926268ae8349af663c2e7a1bc40a11842bb04db7a6baa1f239cb2c537ef8b442a4a76dfc09a8a7bfe10244abb2a78ed3b3b6600d38b
6
+ metadata.gz: 0f0d7cff4de9dc7d8f04cdea8f8f28d6e45d5c0676a40ca67daa4e3fd6e3397363d2c2f4b368b5bcbb165d7478bdfb33c5352c49d2fd52896f8aa6d488e017cc
7
+ data.tar.gz: 357c3047ffea023a5c10162e4e2f2ee782796b5ca87d7c4413bde296d284c41362033ca9d997609ac6d9eceea7227b46e240150340a8a26cad8071bc5cce33c7
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-25 Bozhidar Batsov
1
+ Copyright (c) 2012-26 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -51,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
51
51
  in your `Gemfile`:
52
52
 
53
53
  ```rb
54
- gem 'rubocop', '~> 1.80', require: false
54
+ gem 'rubocop', '~> 1.82', require: false
55
55
  ```
56
56
 
57
57
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -251,5 +251,5 @@ RuboCop's release notes are available [here](https://github.com/rubocop/rubocop/
251
251
 
252
252
  ## Copyright
253
253
 
254
- Copyright (c) 2012-2025 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
254
+ Copyright (c) 2012-2026 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
255
255
  further details.
data/config/default.yml CHANGED
@@ -3,20 +3,16 @@
3
3
  AllCops:
4
4
  RubyInterpreters:
5
5
  - ruby
6
- - macruby
7
6
  - rake
8
7
  - jruby
9
- - rbx
10
8
  # Include common Ruby source files.
11
9
  Include:
12
10
  - '**/*.rb'
13
11
  - '**/*.arb'
14
12
  - '**/*.axlsx'
15
13
  - '**/*.builder'
16
- - '**/*.fcgi'
17
14
  - '**/*.gemfile'
18
15
  - '**/*.gemspec'
19
- - '**/*.god'
20
16
  - '**/*.jb'
21
17
  - '**/*.jbuilder'
22
18
  - '**/*.mspec'
@@ -25,15 +21,12 @@ AllCops:
25
21
  - '**/*.podspec'
26
22
  - '**/*.rabl'
27
23
  - '**/*.rake'
28
- - '**/*.rbuild'
29
24
  - '**/*.rbw'
30
- - '**/*.rbx'
31
25
  - '**/*.ru'
32
26
  - '**/*.ruby'
33
27
  - '**/*.schema'
34
28
  - '**/*.spec'
35
29
  - '**/*.thor'
36
- - '**/*.watchr'
37
30
  - '**/.irbrc'
38
31
  - '**/.pryrc'
39
32
  - '**/.simplecov'
@@ -43,7 +36,6 @@ AllCops:
43
36
  - '**/Brewfile'
44
37
  - '**/Buildfile'
45
38
  - '**/Capfile'
46
- - '**/Cheffile'
47
39
  - '**/Dangerfile'
48
40
  - '**/Deliverfile'
49
41
  - '**/Fastfile'
@@ -60,7 +52,6 @@ AllCops:
60
52
  - '**/Snapfile'
61
53
  - '**/Steepfile'
62
54
  - '**/Thorfile'
63
- - '**/Vagabondfile'
64
55
  - '**/Vagrantfile'
65
56
  Exclude:
66
57
  - 'node_modules/**/*'
@@ -117,7 +108,7 @@ AllCops:
117
108
  # line option.
118
109
  UseCache: true
119
110
  # Threshold for how many files can be stored in the result cache before some
120
- # of the files are automatically removed.
111
+ # of the files are automatically removed. Set to false to disable cache pruning.
121
112
  MaxFilesInCache: 20000
122
113
  # The cache will be stored in "rubocop_cache" under this directory. If
123
114
  # CacheRootDirectory is ~ (nil), which it is by default, the root will be
@@ -275,7 +266,7 @@ Gemspec/AddRuntimeDependency:
275
266
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
276
267
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
277
268
  References:
278
- - https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
269
+ - https://github.com/ruby/rubygems/issues/7799#issuecomment-2192720316
279
270
  Enabled: pending
280
271
  VersionAdded: '1.65'
281
272
  Include:
@@ -835,6 +826,7 @@ Layout/FirstArrayElementLineBreak:
835
826
  multi-line array.
836
827
  Enabled: false
837
828
  VersionAdded: '0.49'
829
+ AllowImplicitArrayLiterals: false
838
830
  AllowMultilineFinalElement: false
839
831
 
840
832
  Layout/FirstHashElementIndentation:
@@ -1037,6 +1029,15 @@ Layout/IndentationWidth:
1037
1029
  VersionAdded: '0.49'
1038
1030
  # Number of spaces for each indentation level.
1039
1031
  Width: 2
1032
+ # Block body indentation for method chain blocks.
1033
+ # The value `start_of_line` means that block bodies are indented
1034
+ # relative to the start of the line where the block starts.
1035
+ # The value `relative_to_receiver` means that block bodies are indented
1036
+ # relative to the method call position in the chain.
1037
+ EnforcedStyleAlignWith: start_of_line
1038
+ SupportedStylesAlignWith:
1039
+ - start_of_line
1040
+ - relative_to_receiver
1040
1041
  AllowedPatterns: []
1041
1042
 
1042
1043
  Layout/InitialIndentation:
@@ -1102,7 +1103,7 @@ Layout/LineLength:
1102
1103
  StyleGuide: '#max-line-length'
1103
1104
  Enabled: true
1104
1105
  VersionAdded: '0.25'
1105
- VersionChanged: '1.69'
1106
+ VersionChanged: '1.82'
1106
1107
  Max: 120
1107
1108
  AllowHeredoc: true
1108
1109
  # To make it possible to copy or click on URIs in the code, we allow lines
@@ -1112,9 +1113,12 @@ Layout/LineLength:
1112
1113
  URISchemes:
1113
1114
  - http
1114
1115
  - https
1115
- # The IgnoreCopDirectives option causes the LineLength rule to ignore cop
1116
+ # The AllowRBSInlineAnnotation option makes LineLength allow RBS::Inline annotations
1117
+ # such as `#: (?date: Date) -> Foo` when calculating line length.
1118
+ AllowRBSInlineAnnotation: false
1119
+ # The AllowCopDirectives option causes the LineLength rule to ignore cop
1116
1120
  # directives like '# rubocop: enable ...' when calculating a line's length.
1117
- IgnoreCopDirectives: true
1121
+ AllowCopDirectives: true
1118
1122
  # The AllowedPatterns option is a list of !ruby/regexp and/or string
1119
1123
  # elements. Strings will be converted to Regexp objects. A line that matches
1120
1124
  # any regular expression listed in this option will be ignored by LineLength.
@@ -1707,6 +1711,11 @@ Lint/CopDirectiveSyntax:
1707
1711
  Enabled: pending
1708
1712
  VersionAdded: '1.72'
1709
1713
 
1714
+ Lint/DataDefineOverride:
1715
+ Description: 'Disallow overriding the `Data` built-in methods via `Data.define`.'
1716
+ Enabled: pending
1717
+ VersionAdded: '1.85'
1718
+
1710
1719
  Lint/Debugger:
1711
1720
  Description: 'Checks for debugger calls.'
1712
1721
  Enabled: true
@@ -2396,8 +2405,9 @@ Lint/SafeNavigationConsistency:
2396
2405
  consistent and appropriate safe navigation, without excess or deficiency,
2397
2406
  is used for all method calls on the same object.
2398
2407
  Enabled: true
2408
+ SafeAutoCorrect: false
2399
2409
  VersionAdded: '0.55'
2400
- VersionChanged: '0.77'
2410
+ VersionChanged: '1.85'
2401
2411
  AllowedMethods:
2402
2412
  - present?
2403
2413
  - blank?
@@ -2574,6 +2584,11 @@ Lint/UnreachableLoop:
2574
2584
  # eg. `exactly(2).times`
2575
2585
  - !ruby/regexp /(exactly|at_least|at_most)\(\d+\)\.times/
2576
2586
 
2587
+ Lint/UnreachablePatternBranch:
2588
+ Description: 'Checks for unreachable `in` pattern branches after an unconditional catch-all pattern.'
2589
+ Enabled: pending
2590
+ VersionAdded: '1.85'
2591
+
2577
2592
  Lint/UnusedBlockArgument:
2578
2593
  Description: 'Checks for unused block arguments.'
2579
2594
  StyleGuide: '#underscore-unused-vars'
@@ -2669,7 +2684,10 @@ Lint/UselessNumericOperation:
2669
2684
  Lint/UselessOr:
2670
2685
  Description: 'Checks for useless OR expressions.'
2671
2686
  Enabled: pending
2687
+ SafeAutoCorrect: false
2688
+ AutoCorrect: contextual
2672
2689
  VersionAdded: '1.76'
2690
+ VersionChanged: '1.82'
2673
2691
 
2674
2692
  Lint/UselessRescue:
2675
2693
  Description: 'Checks for useless `rescue`s.'
@@ -3097,6 +3115,7 @@ Naming/PredicateMethod:
3097
3115
  AllowBangMethods: false
3098
3116
  # Methods that are known to not return a boolean value, despite ending in `?`.
3099
3117
  WaywardPredicates:
3118
+ - infinite?
3100
3119
  - nonzero?
3101
3120
 
3102
3121
  Naming/PredicatePrefix:
@@ -3207,6 +3226,7 @@ Security/JSONLoad:
3207
3226
  security issues. See reference for more information.
3208
3227
  References:
3209
3228
  - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3229
+ - 'https://bugs.ruby-lang.org/issues/19528'
3210
3230
  Enabled: true
3211
3231
  VersionAdded: '0.43'
3212
3232
  VersionChanged: '1.22'
@@ -3280,7 +3300,7 @@ Style/Alias:
3280
3300
 
3281
3301
  Style/AmbiguousEndlessMethodDefinition:
3282
3302
  Description: 'Checks for endless methods inside operators of lower precedence.'
3283
- StyleGuide: '#ambiguous-endless-method-defintions'
3303
+ StyleGuide: '#ambiguous-endless-method-definitions'
3284
3304
  Enabled: pending
3285
3305
  VersionAdded: '1.68'
3286
3306
 
@@ -3341,6 +3361,12 @@ Style/ArrayIntersect:
3341
3361
  Safe: false
3342
3362
  VersionAdded: '1.40'
3343
3363
 
3364
+ Style/ArrayIntersectWithSingleElement:
3365
+ Description: 'Use `include?(element)` instead of `intersect?([element])`.'
3366
+ Enabled: 'pending'
3367
+ Safe: false
3368
+ VersionAdded: '1.81'
3369
+
3344
3370
  Style/ArrayJoin:
3345
3371
  Description: 'Use Array#join instead of Array#*.'
3346
3372
  StyleGuide: '#array-join'
@@ -3518,9 +3544,11 @@ Style/BlockDelimiters:
3518
3544
  BracesRequiredMethods: []
3519
3545
 
3520
3546
  Style/CaseEquality:
3521
- Description: 'Avoid explicit use of the case equality operator(===).'
3547
+ Description: 'Avoid explicit use of the case equality operator (`===`).'
3522
3548
  StyleGuide: '#no-case-equality'
3523
3549
  Enabled: true
3550
+ References:
3551
+ - 'https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceregexpmatch'
3524
3552
  VersionAdded: '0.9'
3525
3553
  VersionChanged: '0.89'
3526
3554
  # If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
@@ -3952,6 +3980,18 @@ Style/EmptyCaseCondition:
3952
3980
  Enabled: true
3953
3981
  VersionAdded: '0.40'
3954
3982
 
3983
+ Style/EmptyClassDefinition:
3984
+ Description: 'Enforces consistent style for empty class definitions.'
3985
+ Enabled: pending
3986
+ VersionAdded: '1.84'
3987
+ VersionChanged: '1.86'
3988
+ EnforcedStyle: class_keyword
3989
+ SupportedStyles:
3990
+ - class_keyword
3991
+ - class_new
3992
+ - class_definition # Deprecated.
3993
+ AllowedParentClasses: []
3994
+
3955
3995
  Style/EmptyElse:
3956
3996
  Description: 'Avoid empty else-clauses.'
3957
3997
  Enabled: true
@@ -4110,6 +4150,12 @@ Style/FileNull:
4110
4150
  SafeAutoCorrect: false
4111
4151
  VersionAdded: '1.69'
4112
4152
 
4153
+ Style/FileOpen:
4154
+ Description: 'Checks for `File.open` without a block, which can leak file descriptors.'
4155
+ Enabled: pending
4156
+ Safe: false
4157
+ VersionAdded: '1.85'
4158
+
4113
4159
  Style/FileRead:
4114
4160
  Description: 'Favor `File.(bin)read` convenience methods.'
4115
4161
  StyleGuide: '#file-read'
@@ -4303,6 +4349,16 @@ Style/HashLikeCase:
4303
4349
  # to trigger this cop
4304
4350
  MinBranchesCount: 3
4305
4351
 
4352
+ Style/HashLookupMethod:
4353
+ Description: 'Enforces the use of either `Hash#[]` or `Hash#fetch` for hash lookup.'
4354
+ Enabled: false
4355
+ Safe: false
4356
+ VersionAdded: '1.84'
4357
+ EnforcedStyle: brackets
4358
+ SupportedStyles:
4359
+ - brackets
4360
+ - fetch
4361
+
4306
4362
  Style/HashSlice:
4307
4363
  Description: >-
4308
4364
  Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
@@ -4400,6 +4456,7 @@ Style/IfWithBooleanLiteralBranches:
4400
4456
  VersionAdded: '1.9'
4401
4457
  SafeAutoCorrect: false
4402
4458
  AllowedMethods:
4459
+ - infinite?
4403
4460
  - nonzero?
4404
4461
 
4405
4462
  Style/IfWithSemicolon:
@@ -4546,8 +4603,9 @@ Style/LambdaCall:
4546
4603
  Description: 'Use lambda.call(...) instead of lambda.(...).'
4547
4604
  StyleGuide: '#proc-call'
4548
4605
  Enabled: true
4606
+ AutoCorrect: contextual
4549
4607
  VersionAdded: '0.13'
4550
- VersionChanged: '0.14'
4608
+ VersionChanged: '1.81'
4551
4609
  EnforcedStyle: call
4552
4610
  SupportedStyles:
4553
4611
  - call
@@ -4595,6 +4653,12 @@ Style/MapIntoArray:
4595
4653
  VersionChanged: '1.67'
4596
4654
  Safe: false
4597
4655
 
4656
+ Style/MapJoin:
4657
+ Description: 'Checks for redundant `map(&:to_s)` before `join`.'
4658
+ Enabled: pending
4659
+ Safe: false
4660
+ VersionAdded: '1.85'
4661
+
4598
4662
  Style/MapToHash:
4599
4663
  Description: 'Prefer `to_h` with a block over `map.to_h`.'
4600
4664
  Enabled: pending
@@ -4617,6 +4681,7 @@ Style/MethodCallWithArgsParentheses:
4617
4681
  AllowedMethods: []
4618
4682
  AllowedPatterns: []
4619
4683
  IncludedMacros: []
4684
+ IncludedMacroPatterns: []
4620
4685
  AllowParenthesesInMultilineCall: false
4621
4686
  AllowParenthesesInChaining: false
4622
4687
  AllowParenthesesInCamelCaseMethod: false
@@ -4727,6 +4792,11 @@ Style/ModuleFunction:
4727
4792
  Autocorrect: false
4728
4793
  SafeAutoCorrect: false
4729
4794
 
4795
+ Style/ModuleMemberExistenceCheck:
4796
+ Description: 'Checks for usage of `Module` methods returning arrays that can be replaced with equivalent predicates.'
4797
+ Enabled: pending
4798
+ VersionAdded: '1.82'
4799
+
4730
4800
  Style/MultilineBlockChain:
4731
4801
  Description: 'Avoid multi-line chains of blocks.'
4732
4802
  StyleGuide: '#single-line-blocks'
@@ -4854,6 +4924,14 @@ Style/NegatedWhile:
4854
4924
  Enabled: true
4855
4925
  VersionAdded: '0.20'
4856
4926
 
4927
+ Style/NegativeArrayIndex:
4928
+ Description: >-
4929
+ Use negative array indices instead of calculating array length minus a value.
4930
+ Also handles range patterns with length calculations. Recognizes preserving methods
4931
+ and their combinations, allowing safe replacement when the receiver matches.
4932
+ Enabled: pending
4933
+ VersionAdded: '1.84'
4934
+
4857
4935
  Style/NestedFileDirname:
4858
4936
  Description: 'Checks for nested `File.dirname`.'
4859
4937
  Enabled: pending
@@ -5029,6 +5107,16 @@ Style/ObjectThen:
5029
5107
  - then
5030
5108
  - yield_self
5031
5109
 
5110
+ Style/OneClassPerFile:
5111
+ Description: 'Checks that each source file defines at most one top-level class or module.'
5112
+ Enabled: pending
5113
+ VersionAdded: '1.85'
5114
+ VersionChanged: '1.86'
5115
+ AllowedClasses: []
5116
+ Exclude:
5117
+ - 'spec/**/*'
5118
+ - 'test/**/*'
5119
+
5032
5120
  Style/OneLineConditional:
5033
5121
  Description: >-
5034
5122
  Favor the ternary operator (?:) or multi-line constructs over
@@ -5117,6 +5205,14 @@ Style/ParenthesesAroundCondition:
5117
5205
  AllowSafeAssignment: true
5118
5206
  AllowInMultilineConditions: false
5119
5207
 
5208
+ Style/PartitionInsteadOfDoubleSelect:
5209
+ Description: >-
5210
+ Checks for consecutive `select`/`filter`/`find_all` and `reject` calls
5211
+ on the same receiver with the same block body.
5212
+ Enabled: pending
5213
+ Safe: false
5214
+ VersionAdded: '1.85'
5215
+
5120
5216
  Style/PercentLiteralDelimiters:
5121
5217
  Description: 'Use `%`-literal delimiters consistently.'
5122
5218
  StyleGuide: '#percent-literal-braces'
@@ -5149,6 +5245,12 @@ Style/PerlBackrefs:
5149
5245
  Enabled: true
5150
5246
  VersionAdded: '0.13'
5151
5247
 
5248
+ Style/PredicateWithKind:
5249
+ Description: 'Prefer `any?(Klass)` to `any? { |x| x.is_a?(Klass) }`.'
5250
+ Enabled: pending
5251
+ SafeAutoCorrect: false
5252
+ VersionAdded: '1.85'
5253
+
5152
5254
  Style/PreferredHashMethods:
5153
5255
  Description: 'Checks use of `has_key?` and `has_value?` Hash methods.'
5154
5256
  StyleGuide: '#hash-key'
@@ -5199,6 +5301,12 @@ Style/RandomWithOffset:
5199
5301
  Enabled: true
5200
5302
  VersionAdded: '0.52'
5201
5303
 
5304
+ Style/ReduceToHash:
5305
+ Description: 'Use `to_h { ... }` instead of `each_with_object`, `inject`, or `reduce` to build a hash.'
5306
+ Enabled: pending
5307
+ Safe: false
5308
+ VersionAdded: '1.85'
5309
+
5202
5310
  Style/RedundantArgument:
5203
5311
  Description: 'Checks for a redundant argument passed to certain methods.'
5204
5312
  Enabled: pending
@@ -5214,6 +5322,8 @@ Style/RedundantArgument:
5214
5322
  exit: true
5215
5323
  # Kernel.#exit!
5216
5324
  exit!: false
5325
+ # String#to_i
5326
+ to_i: 10
5217
5327
  # String#split
5218
5328
  split: ' '
5219
5329
  # String#chomp
@@ -5255,6 +5365,7 @@ Style/RedundantCondition:
5255
5365
  VersionAdded: '0.76'
5256
5366
  VersionChanged: '1.73'
5257
5367
  AllowedMethods:
5368
+ - infinite?
5258
5369
  - nonzero?
5259
5370
 
5260
5371
  Style/RedundantConditional:
@@ -5365,6 +5476,11 @@ Style/RedundantLineContinuation:
5365
5476
  Enabled: pending
5366
5477
  VersionAdded: '1.49'
5367
5478
 
5479
+ Style/RedundantMinMaxBy:
5480
+ Description: 'Identifies places where `max_by`/`min_by` can be replaced by `max`/`min`.'
5481
+ Enabled: pending
5482
+ VersionAdded: '1.85'
5483
+
5368
5484
  Style/RedundantParentheses:
5369
5485
  Description: "Checks for parentheses that seem not to serve any purpose."
5370
5486
  Enabled: true
@@ -5442,6 +5558,13 @@ Style/RedundantStringEscape:
5442
5558
  Enabled: pending
5443
5559
  VersionAdded: '1.37'
5444
5560
 
5561
+ Style/RedundantStructKeywordInit:
5562
+ Description: 'Checks for redundant `keyword_init` option for `Struct.new`.'
5563
+ Enabled: false
5564
+ SafeAutoCorrect: false
5565
+ VersionAdded: '1.85'
5566
+ VersionChanged: '1.86'
5567
+
5445
5568
  Style/RegexpLiteral:
5446
5569
  Description: 'Use / or %r around regular expressions.'
5447
5570
  StyleGuide: '#percent-r'
@@ -5503,6 +5626,12 @@ Style/ReturnNilInPredicateMethodDefinition:
5503
5626
  VersionAdded: '1.53'
5504
5627
  VersionChanged: '1.67'
5505
5628
 
5629
+ Style/ReverseFind:
5630
+ Description: 'Use `array.rfind` instead of `array.reverse.find`.'
5631
+ Enabled: pending
5632
+ Safe: false
5633
+ VersionAdded: '1.84'
5634
+
5506
5635
  Style/SafeNavigation:
5507
5636
  Description: >-
5508
5637
  Transforms usages of a method call safeguarded by
@@ -5542,8 +5671,20 @@ Style/Sample:
5542
5671
  Enabled: true
5543
5672
  VersionAdded: '0.30'
5544
5673
 
5674
+ Style/SelectByKind:
5675
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a kind check.'
5676
+ Enabled: pending
5677
+ SafeAutoCorrect: false
5678
+ VersionAdded: '1.85'
5679
+
5680
+ Style/SelectByRange:
5681
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a range check.'
5682
+ Enabled: pending
5683
+ SafeAutoCorrect: false
5684
+ VersionAdded: '1.85'
5685
+
5545
5686
  Style/SelectByRegexp:
5546
- Description: 'Prefer grep/grep_v to select/reject with a regexp match.'
5687
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a regexp match.'
5547
5688
  Enabled: pending
5548
5689
  SafeAutoCorrect: false
5549
5690
  VersionAdded: '1.22'
@@ -5802,6 +5943,12 @@ Style/SymbolProc:
5802
5943
  AllowedPatterns: []
5803
5944
  AllowComments: false
5804
5945
 
5946
+ Style/TallyMethod:
5947
+ Description: 'Prefer `Enumerable#tally` over manual counting patterns.'
5948
+ Enabled: pending
5949
+ Safe: false
5950
+ VersionAdded: '1.85'
5951
+
5805
5952
  Style/TernaryParentheses:
5806
5953
  Description: 'Checks for use of parentheses around ternary conditions.'
5807
5954
  Enabled: true
@@ -5844,10 +5991,14 @@ Style/TrailingCommaInArguments:
5844
5991
  # parenthesized method calls where each argument is on its own line.
5845
5992
  # If `consistent_comma`, the cop requires a comma after the last argument,
5846
5993
  # for all parenthesized method calls with arguments.
5994
+ # If `diff_comma`, the cop requires a comma after the last argument, but only
5995
+ # when that argument is followed by an immediate newline, even if
5996
+ # there is an inline comment.
5847
5997
  EnforcedStyleForMultiline: no_comma
5848
5998
  SupportedStylesForMultiline:
5849
5999
  - comma
5850
6000
  - consistent_comma
6001
+ - diff_comma
5851
6002
  - no_comma
5852
6003
 
5853
6004
  Style/TrailingCommaInArrayLiteral:
@@ -145,6 +145,10 @@ changed_parameters:
145
145
  - cops: Layout/CaseIndentation
146
146
  parameters: IndentWhenRelativeTo
147
147
  alternative: EnforcedStyle
148
+ - cops: Layout/LineLength
149
+ parameters: IgnoreCopDirectives
150
+ alternative: AllowCopDirectives
151
+ severity: warning
148
152
  - cops:
149
153
  - Lint/BlockAlignment
150
154
  - Layout/BlockAlignment
@@ -241,3 +245,8 @@ changed_enforced_styles:
241
245
  parameters: EnforcedStyle
242
246
  value: rails
243
247
  alternative: indented_internal_methods
248
+ - cops: Style/EmptyClassDefinition
249
+ parameters: EnforcedStyle
250
+ value: class_definition
251
+ alternative: class_keyword
252
+ severity: warning
@@ -25,5 +25,34 @@ module RuboCop
25
25
 
26
26
  File.join(root, 'rubocop_cache')
27
27
  end
28
+
29
+ # Lightweight cache root computation that reads CacheRootDirectory from
30
+ # the toplevel config file and environment variables without going through
31
+ # the full ConfigStore/ConfigLoader. This method can be used, for example,
32
+ # before loading configuration files. Please note that this method doesn't
33
+ # take into account any `inherit_from` dependencies.
34
+ def self.root_dir_from_toplevel_config(cache_root_override = nil)
35
+ root_dir do
36
+ next cache_root_override if cache_root_override
37
+
38
+ config_path = ConfigFinder.find_config_path(PathUtil.pwd)
39
+ file_contents = File.read(config_path)
40
+
41
+ # Returns early if `CacheRootDirectory` is not used before requiring `erb` or `yaml`.
42
+ next unless file_contents.include?('CacheRootDirectory')
43
+
44
+ require 'erb'
45
+ require 'yaml'
46
+ yaml_code = ERB.new(file_contents).result
47
+ config_yaml = YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true)
48
+
49
+ # For compatibility with Ruby 3.0 or lower.
50
+ if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
51
+ config_yaml == false ? nil : config_yaml
52
+ end
53
+
54
+ config_yaml&.dig('AllCops', 'CacheRootDirectory')
55
+ end
56
+ end
28
57
  end
29
58
  end
@@ -83,7 +83,7 @@ module RuboCop
83
83
  execute_runner
84
84
  @options.delete(:only)
85
85
  @config_store = ConfigStore.new
86
- @config_store.options_config = @options[:config] if @options[:config]
86
+ @config_store.apply_options!(@options)
87
87
  # Save the todo configuration of the LineLength cop.
88
88
  File.read(AUTO_GENERATED_FILE).lines.drop_while { |line| line.start_with?('#') }.join
89
89
  end
@@ -99,7 +99,7 @@ module RuboCop
99
99
 
100
100
  def reset_config_and_auto_gen_file
101
101
  @config_store = ConfigStore.new
102
- @config_store.options_config = @options[:config] if @options[:config]
102
+ @config_store.apply_options!(@options)
103
103
  File.open(AUTO_GENERATED_FILE, 'w') {} # create or truncate if exists
104
104
  add_inheritance_from_auto_generated_file(@options[:config])
105
105
  end
@@ -153,7 +153,7 @@ module RuboCop
153
153
  def relative_path_to_todo_from_options_config
154
154
  return AUTO_GENERATED_FILE unless @options[:config]
155
155
 
156
- base = Pathname.new(Dir.pwd)
156
+ base = Pathname.new(PathUtil.pwd)
157
157
  config_dir = Pathname.new(@options[:config]).realpath.dirname
158
158
 
159
159
  # Don't have the path start with `/`
@@ -9,7 +9,7 @@ module RuboCop
9
9
  self.command_name = :lsp
10
10
 
11
11
  def run
12
- # Load on demand, `languge-server-protocol` is heavy to require.
12
+ # Load on demand, `language-server-protocol` is heavy to require.
13
13
  require_relative '../../lsp/server'
14
14
  RuboCop::LSP::Server.new(@config_store).start
15
15
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Start Model Context Protocol of RuboCop.
7
+ # @api private
8
+ class MCP < Base
9
+ self.command_name = :mcp
10
+
11
+ def run
12
+ require_relative '../../mcp/server'
13
+
14
+ RuboCop::MCP::Server.new(@config_store).start
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -25,7 +25,7 @@ module RuboCop
25
25
  super
26
26
 
27
27
  # Load the configs so the require()s are done for custom cops
28
- @config = @config_store.for(Dir.pwd)
28
+ @config = @config_store.for(PathUtil.pwd)
29
29
 
30
30
  @cop_matchers = @options[:show_cops].map do |pattern|
31
31
  if pattern.include?('*')
@@ -46,7 +46,7 @@ module RuboCop
46
46
  registry = Cop::Registry.global
47
47
  show_all = @cop_matchers.empty?
48
48
 
49
- puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: " if show_all
49
+ puts "# Available cops (#{registry.length}) + config for #{PathUtil.pwd}: " if show_all
50
50
 
51
51
  registry.departments.sort!.each do |department|
52
52
  print_cops_of_department(registry, department, show_all)
@@ -12,7 +12,7 @@ module RuboCop
12
12
  def initialize(env)
13
13
  super
14
14
 
15
- @config = @config_store.for(Dir.pwd)
15
+ @config = @config_store.for(PathUtil.pwd)
16
16
  end
17
17
 
18
18
  def run