rubocop 1.79.2 → 1.85.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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +163 -9
  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 +2 -2
  9. data/lib/rubocop/cli/command/lsp.rb +1 -1
  10. data/lib/rubocop/cli/command/mcp.rb +19 -0
  11. data/lib/rubocop/cli.rb +32 -5
  12. data/lib/rubocop/comment_config.rb +62 -17
  13. data/lib/rubocop/config_loader.rb +20 -21
  14. data/lib/rubocop/config_loader_resolver.rb +7 -6
  15. data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -2
  16. data/lib/rubocop/config_store.rb +5 -0
  17. data/lib/rubocop/cop/autocorrect_logic.rb +8 -4
  18. data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
  19. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -2
  20. data/lib/rubocop/cop/correctors/alignment_corrector.rb +26 -7
  21. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
  22. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  23. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  24. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -2
  25. data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
  26. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +10 -5
  27. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
  28. data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
  29. data/lib/rubocop/cop/internal_affairs/location_exists.rb +28 -2
  30. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +9 -9
  31. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
  32. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
  33. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  34. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
  35. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  36. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
  37. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  38. data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
  39. data/lib/rubocop/cop/layout/class_structure.rb +13 -6
  40. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  41. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +3 -0
  42. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +30 -12
  43. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +2 -2
  44. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +12 -2
  45. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +16 -2
  46. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +16 -2
  47. data/lib/rubocop/cop/layout/end_alignment.rb +4 -0
  48. data/lib/rubocop/cop/layout/first_argument_indentation.rb +34 -1
  49. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
  50. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +7 -1
  51. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
  52. data/lib/rubocop/cop/layout/hash_alignment.rb +3 -6
  53. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  54. data/lib/rubocop/cop/layout/heredoc_indentation.rb +33 -3
  55. data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
  56. data/lib/rubocop/cop/layout/indentation_width.rb +111 -7
  57. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
  58. data/lib/rubocop/cop/layout/line_length.rb +22 -7
  59. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
  60. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
  61. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
  62. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
  63. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +179 -39
  64. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
  65. data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
  66. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
  67. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +13 -3
  68. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
  69. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  70. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  71. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  72. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +8 -8
  73. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  74. data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -3
  75. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
  76. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  77. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +14 -8
  78. data/lib/rubocop/cop/lint/data_define_override.rb +63 -0
  79. data/lib/rubocop/cop/lint/debugger.rb +0 -2
  80. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
  81. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
  82. data/lib/rubocop/cop/lint/duplicate_methods.rb +57 -5
  83. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  84. data/lib/rubocop/cop/lint/else_layout.rb +19 -0
  85. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  86. data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
  87. data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
  88. data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
  89. data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -1
  90. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  91. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
  92. data/lib/rubocop/cop/lint/next_without_accumulator.rb +2 -0
  93. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +4 -0
  94. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -1
  95. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +23 -9
  96. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +0 -9
  97. data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -2
  98. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +7 -6
  99. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -2
  100. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  101. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
  102. data/lib/rubocop/cop/lint/self_assignment.rb +15 -6
  103. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  104. data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
  105. data/lib/rubocop/cop/lint/to_json.rb +12 -16
  106. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  107. data/lib/rubocop/cop/lint/unreachable_code.rb +5 -3
  108. data/lib/rubocop/cop/lint/unreachable_pattern_branch.rb +113 -0
  109. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  110. data/lib/rubocop/cop/lint/useless_assignment.rb +45 -17
  111. data/lib/rubocop/cop/lint/useless_or.rb +15 -2
  112. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +2 -2
  113. data/lib/rubocop/cop/lint/void.rb +39 -12
  114. data/lib/rubocop/cop/message_annotator.rb +1 -1
  115. data/lib/rubocop/cop/metrics/block_nesting.rb +23 -0
  116. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
  117. data/lib/rubocop/cop/migration/department_name.rb +12 -1
  118. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  119. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +3 -5
  120. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  121. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  122. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +5 -5
  123. data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
  124. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -60
  125. data/lib/rubocop/cop/mixin/line_length_help.rb +21 -2
  126. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  127. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
  128. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  129. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
  130. data/lib/rubocop/cop/mixin/statement_modifier.rb +0 -6
  131. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -5
  132. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  133. data/lib/rubocop/cop/naming/method_name.rb +5 -3
  134. data/lib/rubocop/cop/naming/predicate_method.rb +30 -6
  135. data/lib/rubocop/cop/naming/predicate_prefix.rb +11 -11
  136. data/lib/rubocop/cop/offense.rb +9 -1
  137. data/lib/rubocop/cop/security/eval.rb +15 -2
  138. data/lib/rubocop/cop/security/json_load.rb +33 -11
  139. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -2
  140. data/lib/rubocop/cop/style/accessor_grouping.rb +4 -2
  141. data/lib/rubocop/cop/style/alias.rb +4 -1
  142. data/lib/rubocop/cop/style/array_intersect.rb +46 -12
  143. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  144. data/lib/rubocop/cop/style/array_join.rb +4 -2
  145. data/lib/rubocop/cop/style/ascii_comments.rb +5 -2
  146. data/lib/rubocop/cop/style/attr.rb +5 -2
  147. data/lib/rubocop/cop/style/bare_percent_literals.rb +4 -3
  148. data/lib/rubocop/cop/style/begin_block.rb +3 -1
  149. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  150. data/lib/rubocop/cop/style/block_delimiters.rb +4 -3
  151. data/lib/rubocop/cop/style/case_equality.rb +15 -13
  152. data/lib/rubocop/cop/style/class_and_module_children.rb +11 -2
  153. data/lib/rubocop/cop/style/colon_method_call.rb +3 -1
  154. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -14
  155. data/lib/rubocop/cop/style/constant_visibility.rb +17 -12
  156. data/lib/rubocop/cop/style/copyright.rb +1 -1
  157. data/lib/rubocop/cop/style/documentation.rb +6 -6
  158. data/lib/rubocop/cop/style/documentation_method.rb +8 -8
  159. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  160. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  161. data/lib/rubocop/cop/style/each_with_object.rb +2 -0
  162. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  163. data/lib/rubocop/cop/style/empty_class_definition.rb +97 -0
  164. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  165. data/lib/rubocop/cop/style/empty_method.rb +0 -6
  166. data/lib/rubocop/cop/style/encoding.rb +7 -1
  167. data/lib/rubocop/cop/style/end_block.rb +3 -1
  168. data/lib/rubocop/cop/style/endless_method.rb +23 -5
  169. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  170. data/lib/rubocop/cop/style/file_open.rb +63 -0
  171. data/lib/rubocop/cop/style/float_division.rb +15 -1
  172. data/lib/rubocop/cop/style/for.rb +3 -0
  173. data/lib/rubocop/cop/style/format_string_token.rb +49 -5
  174. data/lib/rubocop/cop/style/global_vars.rb +4 -1
  175. data/lib/rubocop/cop/style/guard_clause.rb +24 -22
  176. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +27 -9
  177. data/lib/rubocop/cop/style/hash_lookup_method.rb +94 -0
  178. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  179. data/lib/rubocop/cop/style/hash_transform_keys.rb +17 -7
  180. data/lib/rubocop/cop/style/hash_transform_values.rb +17 -7
  181. data/lib/rubocop/cop/style/if_unless_modifier.rb +46 -17
  182. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -12
  183. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +4 -1
  184. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  185. data/lib/rubocop/cop/style/inline_comment.rb +4 -1
  186. data/lib/rubocop/cop/style/lambda_call.rb +8 -8
  187. data/lib/rubocop/cop/style/map_join.rb +123 -0
  188. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +12 -1
  189. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +17 -4
  190. data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -4
  191. data/lib/rubocop/cop/style/module_member_existence_check.rb +117 -0
  192. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  193. data/lib/rubocop/cop/style/multiline_method_signature.rb +2 -4
  194. data/lib/rubocop/cop/style/negative_array_index.rb +220 -0
  195. data/lib/rubocop/cop/style/nil_comparison.rb +11 -10
  196. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  197. data/lib/rubocop/cop/style/not.rb +2 -0
  198. data/lib/rubocop/cop/style/numeric_literals.rb +2 -1
  199. data/lib/rubocop/cop/style/one_class_per_file.rb +95 -0
  200. data/lib/rubocop/cop/style/one_line_conditional.rb +21 -12
  201. data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
  202. data/lib/rubocop/cop/style/parallel_assignment.rb +6 -2
  203. data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
  204. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -0
  205. data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
  206. data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
  207. data/lib/rubocop/cop/style/proc.rb +3 -2
  208. data/lib/rubocop/cop/style/reduce_to_hash.rb +169 -0
  209. data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
  210. data/lib/rubocop/cop/style/redundant_begin.rb +37 -3
  211. data/lib/rubocop/cop/style/redundant_condition.rb +6 -3
  212. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  213. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  214. data/lib/rubocop/cop/style/redundant_format.rb +26 -5
  215. data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
  216. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
  217. data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
  218. data/lib/rubocop/cop/style/redundant_parentheses.rb +17 -11
  219. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -2
  220. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
  221. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  222. data/lib/rubocop/cop/style/redundant_return.rb +3 -1
  223. data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
  224. data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +104 -0
  225. data/lib/rubocop/cop/style/reverse_find.rb +51 -0
  226. data/lib/rubocop/cop/style/safe_navigation.rb +18 -1
  227. data/lib/rubocop/cop/style/select_by_kind.rb +158 -0
  228. data/lib/rubocop/cop/style/select_by_range.rb +197 -0
  229. data/lib/rubocop/cop/style/select_by_regexp.rb +51 -21
  230. data/lib/rubocop/cop/style/semicolon.rb +25 -7
  231. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  232. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -1
  233. data/lib/rubocop/cop/style/single_line_methods.rb +3 -1
  234. data/lib/rubocop/cop/style/sole_nested_conditional.rb +8 -1
  235. data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
  236. data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
  237. data/lib/rubocop/cop/style/super_arguments.rb +2 -2
  238. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  239. data/lib/rubocop/cop/style/tally_method.rb +181 -0
  240. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  241. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  242. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +11 -11
  243. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  244. data/lib/rubocop/cop/team.rb +4 -4
  245. data/lib/rubocop/cop/util.rb +2 -3
  246. data/lib/rubocop/cop/utils/format_string.rb +10 -0
  247. data/lib/rubocop/cop/variable_force/branch.rb +30 -6
  248. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  249. data/lib/rubocop/cop/variable_force.rb +9 -7
  250. data/lib/rubocop/cops_documentation_generator.rb +4 -4
  251. data/lib/rubocop/directive_comment.rb +48 -4
  252. data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
  253. data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -5
  254. data/lib/rubocop/formatter/formatter_set.rb +2 -2
  255. data/lib/rubocop/formatter/tap_formatter.rb +5 -2
  256. data/lib/rubocop/lsp/diagnostic.rb +18 -33
  257. data/lib/rubocop/lsp/disable_comment_edits.rb +135 -0
  258. data/lib/rubocop/lsp/routes.rb +33 -4
  259. data/lib/rubocop/lsp/runtime.rb +13 -3
  260. data/lib/rubocop/lsp/stdin_runner.rb +8 -17
  261. data/lib/rubocop/magic_comment.rb +20 -0
  262. data/lib/rubocop/mcp/server.rb +174 -0
  263. data/lib/rubocop/options.rb +10 -1
  264. data/lib/rubocop/rake_task.rb +1 -1
  265. data/lib/rubocop/remote_config.rb +10 -8
  266. data/lib/rubocop/result_cache.rb +39 -28
  267. data/lib/rubocop/rspec/shared_contexts.rb +7 -3
  268. data/lib/rubocop/rspec/support.rb +2 -1
  269. data/lib/rubocop/runner.rb +10 -4
  270. data/lib/rubocop/server/cache.rb +6 -29
  271. data/lib/rubocop/target_finder.rb +9 -9
  272. data/lib/rubocop/target_ruby.rb +31 -14
  273. data/lib/rubocop/version.rb +1 -1
  274. data/lib/rubocop.rb +20 -0
  275. data/lib/ruby_lsp/rubocop/addon.rb +23 -8
  276. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
  277. metadata +45 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f846b1bf660549b8197375e32c8219bff1e42888b925976bd3514cd9b32c1d3b
4
- data.tar.gz: 4e862ade4bbe0c24c7734427695733316c893b5278f9868aa88c44255d03461c
3
+ metadata.gz: 540ad681621feef2b8ffb784afa823f9f03df707e480c371da9b95576c42a0c0
4
+ data.tar.gz: 2e346929c88929a4c923c3f4f5907b986580fbcd36de82687433ef22e5648f9b
5
5
  SHA512:
6
- metadata.gz: 05ff2343d4ddcdd26cf94325a5b9026fb7468f456b5714da5108030c39fb0fcfb7218848596d07b04817052af53bc225e66b1f81c53f18adb780c2b4bd417012
7
- data.tar.gz: 9c2ce30fbd9467d85bed0aa581beaa225f3e5b032f0e7a5b09130c8eb2918b25e452f3704a9774e8199c1b9e1ccb1b7d10e558a710c7a73d9f9bd86940475ebf
6
+ metadata.gz: 6c7d48381d4f7121e7e17303ad5ce20c74d24e04b71d9b6d57a89d9c8c435da93e1db46b2a9b574dcdd363dfaad4e568c02f24ad1c13bfc0481e73109b06c8a5
7
+ data.tar.gz: a04e081927cf6dca0c9775a741aa589ae5878cda28fbf8c7e69545970089a48908b56b82872416680acc4461b7ab6261191ea35190d994dc3f9bb3a3b57e0018
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.79', 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
@@ -275,7 +275,7 @@ Gemspec/AddRuntimeDependency:
275
275
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
276
276
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
277
277
  References:
278
- - https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
278
+ - https://github.com/ruby/rubygems/issues/7799#issuecomment-2192720316
279
279
  Enabled: pending
280
280
  VersionAdded: '1.65'
281
281
  Include:
@@ -835,6 +835,7 @@ Layout/FirstArrayElementLineBreak:
835
835
  multi-line array.
836
836
  Enabled: false
837
837
  VersionAdded: '0.49'
838
+ AllowImplicitArrayLiterals: false
838
839
  AllowMultilineFinalElement: false
839
840
 
840
841
  Layout/FirstHashElementIndentation:
@@ -1037,6 +1038,15 @@ Layout/IndentationWidth:
1037
1038
  VersionAdded: '0.49'
1038
1039
  # Number of spaces for each indentation level.
1039
1040
  Width: 2
1041
+ # Block body indentation for method chain blocks.
1042
+ # The value `start_of_line` means that block bodies are indented
1043
+ # relative to the start of the line where the block starts.
1044
+ # The value `relative_to_receiver` means that block bodies are indented
1045
+ # relative to the method call position in the chain.
1046
+ EnforcedStyleAlignWith: start_of_line
1047
+ SupportedStylesAlignWith:
1048
+ - start_of_line
1049
+ - relative_to_receiver
1040
1050
  AllowedPatterns: []
1041
1051
 
1042
1052
  Layout/InitialIndentation:
@@ -1102,7 +1112,7 @@ Layout/LineLength:
1102
1112
  StyleGuide: '#max-line-length'
1103
1113
  Enabled: true
1104
1114
  VersionAdded: '0.25'
1105
- VersionChanged: '1.69'
1115
+ VersionChanged: '1.82'
1106
1116
  Max: 120
1107
1117
  AllowHeredoc: true
1108
1118
  # To make it possible to copy or click on URIs in the code, we allow lines
@@ -1112,9 +1122,12 @@ Layout/LineLength:
1112
1122
  URISchemes:
1113
1123
  - http
1114
1124
  - https
1115
- # The IgnoreCopDirectives option causes the LineLength rule to ignore cop
1125
+ # The AllowRBSInlineAnnotation option makes LineLength allow RBS::Inline annotations
1126
+ # such as `#: (?date: Date) -> Foo` when calculating line length.
1127
+ AllowRBSInlineAnnotation: false
1128
+ # The AllowCopDirectives option causes the LineLength rule to ignore cop
1116
1129
  # directives like '# rubocop: enable ...' when calculating a line's length.
1117
- IgnoreCopDirectives: true
1130
+ AllowCopDirectives: true
1118
1131
  # The AllowedPatterns option is a list of !ruby/regexp and/or string
1119
1132
  # elements. Strings will be converted to Regexp objects. A line that matches
1120
1133
  # any regular expression listed in this option will be ignored by LineLength.
@@ -1707,6 +1720,11 @@ Lint/CopDirectiveSyntax:
1707
1720
  Enabled: pending
1708
1721
  VersionAdded: '1.72'
1709
1722
 
1723
+ Lint/DataDefineOverride:
1724
+ Description: 'Disallow overriding the `Data` built-in methods via `Data.define`.'
1725
+ Enabled: pending
1726
+ VersionAdded: '1.85'
1727
+
1710
1728
  Lint/Debugger:
1711
1729
  Description: 'Checks for debugger calls.'
1712
1730
  Enabled: true
@@ -2396,8 +2414,9 @@ Lint/SafeNavigationConsistency:
2396
2414
  consistent and appropriate safe navigation, without excess or deficiency,
2397
2415
  is used for all method calls on the same object.
2398
2416
  Enabled: true
2417
+ SafeAutoCorrect: false
2399
2418
  VersionAdded: '0.55'
2400
- VersionChanged: '0.77'
2419
+ VersionChanged: '1.85'
2401
2420
  AllowedMethods:
2402
2421
  - present?
2403
2422
  - blank?
@@ -2574,6 +2593,11 @@ Lint/UnreachableLoop:
2574
2593
  # eg. `exactly(2).times`
2575
2594
  - !ruby/regexp /(exactly|at_least|at_most)\(\d+\)\.times/
2576
2595
 
2596
+ Lint/UnreachablePatternBranch:
2597
+ Description: 'Checks for unreachable `in` pattern branches after an unconditional catch-all pattern.'
2598
+ Enabled: pending
2599
+ VersionAdded: '1.85'
2600
+
2577
2601
  Lint/UnusedBlockArgument:
2578
2602
  Description: 'Checks for unused block arguments.'
2579
2603
  StyleGuide: '#underscore-unused-vars'
@@ -2669,7 +2693,10 @@ Lint/UselessNumericOperation:
2669
2693
  Lint/UselessOr:
2670
2694
  Description: 'Checks for useless OR expressions.'
2671
2695
  Enabled: pending
2696
+ SafeAutoCorrect: false
2697
+ AutoCorrect: contextual
2672
2698
  VersionAdded: '1.76'
2699
+ VersionChanged: '1.82'
2673
2700
 
2674
2701
  Lint/UselessRescue:
2675
2702
  Description: 'Checks for useless `rescue`s.'
@@ -3097,6 +3124,7 @@ Naming/PredicateMethod:
3097
3124
  AllowBangMethods: false
3098
3125
  # Methods that are known to not return a boolean value, despite ending in `?`.
3099
3126
  WaywardPredicates:
3127
+ - infinite?
3100
3128
  - nonzero?
3101
3129
 
3102
3130
  Naming/PredicatePrefix:
@@ -3207,6 +3235,7 @@ Security/JSONLoad:
3207
3235
  security issues. See reference for more information.
3208
3236
  References:
3209
3237
  - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3238
+ - 'https://bugs.ruby-lang.org/issues/19528'
3210
3239
  Enabled: true
3211
3240
  VersionAdded: '0.43'
3212
3241
  VersionChanged: '1.22'
@@ -3280,7 +3309,7 @@ Style/Alias:
3280
3309
 
3281
3310
  Style/AmbiguousEndlessMethodDefinition:
3282
3311
  Description: 'Checks for endless methods inside operators of lower precedence.'
3283
- StyleGuide: '#ambiguous-endless-method-defintions'
3312
+ StyleGuide: '#ambiguous-endless-method-definitions'
3284
3313
  Enabled: pending
3285
3314
  VersionAdded: '1.68'
3286
3315
 
@@ -3341,6 +3370,12 @@ Style/ArrayIntersect:
3341
3370
  Safe: false
3342
3371
  VersionAdded: '1.40'
3343
3372
 
3373
+ Style/ArrayIntersectWithSingleElement:
3374
+ Description: 'Use `include?(element)` instead of `intersect?([element])`.'
3375
+ Enabled: 'pending'
3376
+ Safe: false
3377
+ VersionAdded: '1.81'
3378
+
3344
3379
  Style/ArrayJoin:
3345
3380
  Description: 'Use Array#join instead of Array#*.'
3346
3381
  StyleGuide: '#array-join'
@@ -3518,9 +3553,11 @@ Style/BlockDelimiters:
3518
3553
  BracesRequiredMethods: []
3519
3554
 
3520
3555
  Style/CaseEquality:
3521
- Description: 'Avoid explicit use of the case equality operator(===).'
3556
+ Description: 'Avoid explicit use of the case equality operator (`===`).'
3522
3557
  StyleGuide: '#no-case-equality'
3523
3558
  Enabled: true
3559
+ References:
3560
+ - 'https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceregexpmatch'
3524
3561
  VersionAdded: '0.9'
3525
3562
  VersionChanged: '0.89'
3526
3563
  # If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
@@ -3952,6 +3989,16 @@ Style/EmptyCaseCondition:
3952
3989
  Enabled: true
3953
3990
  VersionAdded: '0.40'
3954
3991
 
3992
+ Style/EmptyClassDefinition:
3993
+ Description: 'Enforces consistent style for empty class definitions.'
3994
+ Enabled: pending
3995
+ VersionAdded: '1.84'
3996
+ EnforcedStyle: class_keyword
3997
+ SupportedStyles:
3998
+ - class_keyword
3999
+ - class_new
4000
+ - class_definition # Deprecated.
4001
+
3955
4002
  Style/EmptyElse:
3956
4003
  Description: 'Avoid empty else-clauses.'
3957
4004
  Enabled: true
@@ -4110,6 +4157,12 @@ Style/FileNull:
4110
4157
  SafeAutoCorrect: false
4111
4158
  VersionAdded: '1.69'
4112
4159
 
4160
+ Style/FileOpen:
4161
+ Description: 'Checks for `File.open` without a block, which can leak file descriptors.'
4162
+ Enabled: pending
4163
+ Safe: false
4164
+ VersionAdded: '1.85'
4165
+
4113
4166
  Style/FileRead:
4114
4167
  Description: 'Favor `File.(bin)read` convenience methods.'
4115
4168
  StyleGuide: '#file-read'
@@ -4303,6 +4356,16 @@ Style/HashLikeCase:
4303
4356
  # to trigger this cop
4304
4357
  MinBranchesCount: 3
4305
4358
 
4359
+ Style/HashLookupMethod:
4360
+ Description: 'Enforces the use of either `Hash#[]` or `Hash#fetch` for hash lookup.'
4361
+ Enabled: false
4362
+ Safe: false
4363
+ VersionAdded: '1.84'
4364
+ EnforcedStyle: brackets
4365
+ SupportedStyles:
4366
+ - brackets
4367
+ - fetch
4368
+
4306
4369
  Style/HashSlice:
4307
4370
  Description: >-
4308
4371
  Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
@@ -4400,6 +4463,7 @@ Style/IfWithBooleanLiteralBranches:
4400
4463
  VersionAdded: '1.9'
4401
4464
  SafeAutoCorrect: false
4402
4465
  AllowedMethods:
4466
+ - infinite?
4403
4467
  - nonzero?
4404
4468
 
4405
4469
  Style/IfWithSemicolon:
@@ -4546,8 +4610,9 @@ Style/LambdaCall:
4546
4610
  Description: 'Use lambda.call(...) instead of lambda.(...).'
4547
4611
  StyleGuide: '#proc-call'
4548
4612
  Enabled: true
4613
+ AutoCorrect: contextual
4549
4614
  VersionAdded: '0.13'
4550
- VersionChanged: '0.14'
4615
+ VersionChanged: '1.81'
4551
4616
  EnforcedStyle: call
4552
4617
  SupportedStyles:
4553
4618
  - call
@@ -4595,6 +4660,12 @@ Style/MapIntoArray:
4595
4660
  VersionChanged: '1.67'
4596
4661
  Safe: false
4597
4662
 
4663
+ Style/MapJoin:
4664
+ Description: 'Checks for redundant `map(&:to_s)` before `join`.'
4665
+ Enabled: pending
4666
+ Safe: false
4667
+ VersionAdded: '1.85'
4668
+
4598
4669
  Style/MapToHash:
4599
4670
  Description: 'Prefer `to_h` with a block over `map.to_h`.'
4600
4671
  Enabled: pending
@@ -4617,6 +4688,7 @@ Style/MethodCallWithArgsParentheses:
4617
4688
  AllowedMethods: []
4618
4689
  AllowedPatterns: []
4619
4690
  IncludedMacros: []
4691
+ IncludedMacroPatterns: []
4620
4692
  AllowParenthesesInMultilineCall: false
4621
4693
  AllowParenthesesInChaining: false
4622
4694
  AllowParenthesesInCamelCaseMethod: false
@@ -4727,6 +4799,12 @@ Style/ModuleFunction:
4727
4799
  Autocorrect: false
4728
4800
  SafeAutoCorrect: false
4729
4801
 
4802
+ Style/ModuleMemberExistenceCheck:
4803
+ Description: 'Checks for usage of `Module` methods returning arrays that can be replaced with equivalent predicates.'
4804
+ Enabled: pending
4805
+ VersionAdded: '1.82'
4806
+ AllowedMethods: []
4807
+
4730
4808
  Style/MultilineBlockChain:
4731
4809
  Description: 'Avoid multi-line chains of blocks.'
4732
4810
  StyleGuide: '#single-line-blocks'
@@ -4854,6 +4932,14 @@ Style/NegatedWhile:
4854
4932
  Enabled: true
4855
4933
  VersionAdded: '0.20'
4856
4934
 
4935
+ Style/NegativeArrayIndex:
4936
+ Description: >-
4937
+ Use negative array indices instead of calculating array length minus a value.
4938
+ Also handles range patterns with length calculations. Recognizes preserving methods
4939
+ and their combinations, allowing safe replacement when the receiver matches.
4940
+ Enabled: pending
4941
+ VersionAdded: '1.84'
4942
+
4857
4943
  Style/NestedFileDirname:
4858
4944
  Description: 'Checks for nested `File.dirname`.'
4859
4945
  Enabled: pending
@@ -5029,6 +5115,12 @@ Style/ObjectThen:
5029
5115
  - then
5030
5116
  - yield_self
5031
5117
 
5118
+ Style/OneClassPerFile:
5119
+ Description: 'Checks that each source file defines at most one top-level class or module.'
5120
+ Enabled: pending
5121
+ VersionAdded: '1.85'
5122
+ AllowedClasses: []
5123
+
5032
5124
  Style/OneLineConditional:
5033
5125
  Description: >-
5034
5126
  Favor the ternary operator (?:) or multi-line constructs over
@@ -5117,6 +5209,14 @@ Style/ParenthesesAroundCondition:
5117
5209
  AllowSafeAssignment: true
5118
5210
  AllowInMultilineConditions: false
5119
5211
 
5212
+ Style/PartitionInsteadOfDoubleSelect:
5213
+ Description: >-
5214
+ Checks for consecutive `select`/`filter`/`find_all` and `reject` calls
5215
+ on the same receiver with the same block body.
5216
+ Enabled: pending
5217
+ Safe: false
5218
+ VersionAdded: '1.85'
5219
+
5120
5220
  Style/PercentLiteralDelimiters:
5121
5221
  Description: 'Use `%`-literal delimiters consistently.'
5122
5222
  StyleGuide: '#percent-literal-braces'
@@ -5149,6 +5249,12 @@ Style/PerlBackrefs:
5149
5249
  Enabled: true
5150
5250
  VersionAdded: '0.13'
5151
5251
 
5252
+ Style/PredicateWithKind:
5253
+ Description: 'Prefer `any?(Klass)` to `any? { |x| x.is_a?(Klass) }`.'
5254
+ Enabled: pending
5255
+ SafeAutoCorrect: false
5256
+ VersionAdded: '1.85'
5257
+
5152
5258
  Style/PreferredHashMethods:
5153
5259
  Description: 'Checks use of `has_key?` and `has_value?` Hash methods.'
5154
5260
  StyleGuide: '#hash-key'
@@ -5199,6 +5305,12 @@ Style/RandomWithOffset:
5199
5305
  Enabled: true
5200
5306
  VersionAdded: '0.52'
5201
5307
 
5308
+ Style/ReduceToHash:
5309
+ Description: 'Use `to_h { ... }` instead of `each_with_object`, `inject`, or `reduce` to build a hash.'
5310
+ Enabled: pending
5311
+ Safe: false
5312
+ VersionAdded: '1.85'
5313
+
5202
5314
  Style/RedundantArgument:
5203
5315
  Description: 'Checks for a redundant argument passed to certain methods.'
5204
5316
  Enabled: pending
@@ -5214,6 +5326,8 @@ Style/RedundantArgument:
5214
5326
  exit: true
5215
5327
  # Kernel.#exit!
5216
5328
  exit!: false
5329
+ # String#to_i
5330
+ to_i: 10
5217
5331
  # String#split
5218
5332
  split: ' '
5219
5333
  # String#chomp
@@ -5255,6 +5369,7 @@ Style/RedundantCondition:
5255
5369
  VersionAdded: '0.76'
5256
5370
  VersionChanged: '1.73'
5257
5371
  AllowedMethods:
5372
+ - infinite?
5258
5373
  - nonzero?
5259
5374
 
5260
5375
  Style/RedundantConditional:
@@ -5365,6 +5480,11 @@ Style/RedundantLineContinuation:
5365
5480
  Enabled: pending
5366
5481
  VersionAdded: '1.49'
5367
5482
 
5483
+ Style/RedundantMinMaxBy:
5484
+ Description: 'Identifies places where `max_by`/`min_by` can be replaced by `max`/`min`.'
5485
+ Enabled: pending
5486
+ VersionAdded: '1.85'
5487
+
5368
5488
  Style/RedundantParentheses:
5369
5489
  Description: "Checks for parentheses that seem not to serve any purpose."
5370
5490
  Enabled: true
@@ -5442,6 +5562,12 @@ Style/RedundantStringEscape:
5442
5562
  Enabled: pending
5443
5563
  VersionAdded: '1.37'
5444
5564
 
5565
+ Style/RedundantStructKeywordInit:
5566
+ Description: 'Checks for redundant `keyword_init` option for `Struct.new`.'
5567
+ Enabled: pending
5568
+ SafeAutoCorrect: false
5569
+ VersionAdded: '1.85'
5570
+
5445
5571
  Style/RegexpLiteral:
5446
5572
  Description: 'Use / or %r around regular expressions.'
5447
5573
  StyleGuide: '#percent-r'
@@ -5503,6 +5629,12 @@ Style/ReturnNilInPredicateMethodDefinition:
5503
5629
  VersionAdded: '1.53'
5504
5630
  VersionChanged: '1.67'
5505
5631
 
5632
+ Style/ReverseFind:
5633
+ Description: 'Use `array.rfind` instead of `array.reverse.find`.'
5634
+ Enabled: pending
5635
+ Safe: false
5636
+ VersionAdded: '1.84'
5637
+
5506
5638
  Style/SafeNavigation:
5507
5639
  Description: >-
5508
5640
  Transforms usages of a method call safeguarded by
@@ -5542,8 +5674,20 @@ Style/Sample:
5542
5674
  Enabled: true
5543
5675
  VersionAdded: '0.30'
5544
5676
 
5677
+ Style/SelectByKind:
5678
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a kind check.'
5679
+ Enabled: pending
5680
+ SafeAutoCorrect: false
5681
+ VersionAdded: '1.85'
5682
+
5683
+ Style/SelectByRange:
5684
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a range check.'
5685
+ Enabled: pending
5686
+ SafeAutoCorrect: false
5687
+ VersionAdded: '1.85'
5688
+
5545
5689
  Style/SelectByRegexp:
5546
- Description: 'Prefer grep/grep_v to select/reject with a regexp match.'
5690
+ Description: 'Prefer grep/grep_v to select/reject/find/detect with a regexp match.'
5547
5691
  Enabled: pending
5548
5692
  SafeAutoCorrect: false
5549
5693
  VersionAdded: '1.22'
@@ -5802,6 +5946,12 @@ Style/SymbolProc:
5802
5946
  AllowedPatterns: []
5803
5947
  AllowComments: false
5804
5948
 
5949
+ Style/TallyMethod:
5950
+ Description: 'Prefer `Enumerable#tally` over manual counting patterns.'
5951
+ Enabled: pending
5952
+ Safe: false
5953
+ VersionAdded: '1.85'
5954
+
5805
5955
  Style/TernaryParentheses:
5806
5956
  Description: 'Checks for use of parentheses around ternary conditions.'
5807
5957
  Enabled: true
@@ -5844,10 +5994,14 @@ Style/TrailingCommaInArguments:
5844
5994
  # parenthesized method calls where each argument is on its own line.
5845
5995
  # If `consistent_comma`, the cop requires a comma after the last argument,
5846
5996
  # for all parenthesized method calls with arguments.
5997
+ # If `diff_comma`, the cop requires a comma after the last argument, but only
5998
+ # when that argument is followed by an immediate newline, even if
5999
+ # there is an inline comment.
5847
6000
  EnforcedStyleForMultiline: no_comma
5848
6001
  SupportedStylesForMultiline:
5849
6002
  - comma
5850
6003
  - consistent_comma
6004
+ - diff_comma
5851
6005
  - no_comma
5852
6006
 
5853
6007
  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
data/exe/rubocop CHANGED
@@ -12,13 +12,6 @@ if RuboCop::Server.running?
12
12
  exit_status = RuboCop::Server::ClientCommand::Exec.new.run
13
13
  else
14
14
  require 'rubocop'
15
-
16
- cli = RuboCop::CLI.new
17
-
18
- time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
- exit_status = cli.run
20
- elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
21
-
22
- puts "Finished in #{elapsed_time} seconds" if cli.options[:debug] || cli.options[:display_time]
15
+ exit_status = RuboCop::CLI.new.run
23
16
  end
24
17
  exit exit_status
@@ -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(Dir.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
@@ -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
data/lib/rubocop/cli.rb CHANGED
@@ -37,6 +37,8 @@ module RuboCop
37
37
  #
38
38
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39
39
  def run(args = ARGV)
40
+ time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
+
40
42
  @options, paths = Options.new.parse(args)
41
43
  @env = Environment.new(@options, @config_store, paths)
42
44
 
@@ -64,7 +66,7 @@ module RuboCop
64
66
  STATUS_INTERRUPTED
65
67
  rescue Finished
66
68
  STATUS_SUCCESS
67
- rescue OptionParser::InvalidOption => e
69
+ rescue OptionParser::ParseError => e
68
70
  warn e.message
69
71
  warn 'For usage information, use --help'
70
72
  STATUS_ERROR
@@ -72,6 +74,11 @@ module RuboCop
72
74
  warn e.message
73
75
  warn e.backtrace
74
76
  STATUS_ERROR
77
+ ensure
78
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
79
+ if @options[:debug] || @options[:display_time]
80
+ puts "Finished in #{elapsed_time.round(5)} seconds"
81
+ end
75
82
  end
76
83
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
77
84
 
@@ -159,8 +166,11 @@ module RuboCop
159
166
  set_options_to_pending_cops_reporter
160
167
  handle_editor_mode
161
168
 
162
- @config_store.options_config = @options[:config] if @options[:config]
163
- @config_store.force_default_config! if @options[:force_default_config]
169
+ @config_store.apply_options!(@options)
170
+ # Set cache root after apply_options! to ensure force_default_config is applied first.
171
+ early_cache_root = ConfigLoader.cache_root(@options[:cache_root])
172
+ ConfigLoader.cache_root = ResultCache.cache_root(@config_store, @options[:cache_root])
173
+ warn_if_cache_root_changed(early_cache_root, ConfigLoader.cache_root)
164
174
 
165
175
  handle_exiting_options
166
176
 
@@ -190,7 +200,7 @@ module RuboCop
190
200
  RuboCop::LSP.enable if @options[:editor_mode]
191
201
  end
192
202
 
193
- # rubocop:disable Metrics/CyclomaticComplexity
203
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
194
204
  def handle_exiting_options
195
205
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
196
206
 
@@ -198,9 +208,10 @@ module RuboCop
198
208
  run_command(:show_cops) if @options[:show_cops]
199
209
  run_command(:show_docs_url) if @options[:show_docs_url]
200
210
  run_command(:lsp) if @options[:lsp]
211
+ run_command(:mcp) if @options[:mcp]
201
212
  raise Finished
202
213
  end
203
- # rubocop:enable Metrics/CyclomaticComplexity
214
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
204
215
 
205
216
  def apply_default_formatter
206
217
  # This must be done after the options have already been processed,
@@ -219,5 +230,21 @@ module RuboCop
219
230
  def report_pending_cops
220
231
  PendingCopsReporter.warn_if_needed(@config_store.for_pwd)
221
232
  end
233
+
234
+ def warn_if_cache_root_changed(early, desired)
235
+ return if early == desired
236
+ # Normalize paths to avoid false positives from symlink resolution differences
237
+ if File.exist?(early) && File.exist?(desired) &&
238
+ File.realpath(early) == File.realpath(desired)
239
+ return
240
+ end
241
+
242
+ warn Rainbow(
243
+ "Warning: Remote configuration cache files were stored in `#{early}` " \
244
+ "because a desired cache root (`#{desired}`) was not set at the top level. " \
245
+ 'Consider setting `AllCops: CacheRootDirectory` in your toplevel configuration file, ' \
246
+ 'using the `RUBOCOP_CACHE_ROOT` environment variable, or using CLI options.'
247
+ ).yellow
248
+ end
222
249
  end
223
250
  end