rubocop 1.71.1 → 1.88.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (590) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +23 -19
  4. data/config/default.yml +513 -149
  5. data/config/internal_affairs.yml +20 -0
  6. data/config/obsoletion.yml +38 -4
  7. data/exe/rubocop +1 -8
  8. data/lib/rubocop/cache_config.rb +29 -0
  9. data/lib/rubocop/cli/command/auto_generate_config.rb +36 -4
  10. data/lib/rubocop/cli/command/list_enabled_cops_for.rb +40 -0
  11. data/lib/rubocop/cli/command/lsp.rb +1 -1
  12. data/lib/rubocop/cli/command/mcp.rb +19 -0
  13. data/lib/rubocop/cli/command/show_cops.rb +2 -2
  14. data/lib/rubocop/cli/command/show_docs_url.rb +4 -8
  15. data/lib/rubocop/cli/command/suggest_extensions.rb +8 -2
  16. data/lib/rubocop/cli.rb +48 -11
  17. data/lib/rubocop/comment_config.rb +60 -18
  18. data/lib/rubocop/config.rb +53 -16
  19. data/lib/rubocop/config_finder.rb +1 -1
  20. data/lib/rubocop/config_loader.rb +65 -49
  21. data/lib/rubocop/config_loader_resolver.rb +44 -19
  22. data/lib/rubocop/config_obsoletion/extracted_cop.rb +6 -3
  23. data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
  24. data/lib/rubocop/config_obsoletion.rb +46 -2
  25. data/lib/rubocop/config_store.rb +7 -2
  26. data/lib/rubocop/config_validator.rb +7 -6
  27. data/lib/rubocop/cop/autocorrect_logic.rb +27 -14
  28. data/lib/rubocop/cop/base.rb +38 -12
  29. data/lib/rubocop/cop/bundler/gem_comment.rb +5 -3
  30. data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
  31. data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -3
  32. data/lib/rubocop/cop/commissioner.rb +13 -11
  33. data/lib/rubocop/cop/correctors/alignment_corrector.rb +26 -7
  34. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -1
  35. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +1 -1
  36. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  37. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -1
  38. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +1 -5
  39. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +8 -1
  40. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +36 -2
  41. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  42. data/lib/rubocop/cop/correctors.rb +28 -0
  43. data/lib/rubocop/cop/documentation.rb +2 -3
  44. data/lib/rubocop/cop/exclude_limit.rb +31 -5
  45. data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
  46. data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
  47. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +49 -17
  48. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +2 -3
  49. data/lib/rubocop/cop/gemspec/require_mfa.rb +22 -5
  50. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +12 -7
  51. data/lib/rubocop/cop/internal_affairs/example_description.rb +9 -5
  52. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
  53. data/lib/rubocop/cop/internal_affairs/itblock_handler.rb +69 -0
  54. data/lib/rubocop/cop/internal_affairs/location_exists.rb +142 -0
  55. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +1 -0
  56. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +13 -13
  57. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +1 -1
  58. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -1
  59. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +6 -2
  60. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
  61. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  62. data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
  63. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
  64. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +5 -3
  65. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +13 -2
  66. data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
  67. data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
  68. data/lib/rubocop/cop/internal_affairs.rb +3 -16
  69. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -2
  70. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  71. data/lib/rubocop/cop/layout/begin_end_alignment.rb +1 -1
  72. data/lib/rubocop/cop/layout/block_alignment.rb +60 -4
  73. data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
  74. data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
  75. data/lib/rubocop/cop/layout/class_structure.rb +56 -10
  76. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
  77. data/lib/rubocop/cop/layout/comment_indentation.rb +9 -2
  78. data/lib/rubocop/cop/layout/condition_position.rb +13 -3
  79. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  80. data/lib/rubocop/cop/layout/dot_position.rb +2 -2
  81. data/lib/rubocop/cop/layout/else_alignment.rb +2 -15
  82. data/lib/rubocop/cop/layout/empty_comment.rb +8 -10
  83. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +28 -9
  84. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +46 -21
  85. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
  86. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +34 -4
  87. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
  88. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -0
  89. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +13 -2
  90. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +17 -3
  91. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
  92. data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +16 -2
  93. data/lib/rubocop/cop/layout/end_alignment.rb +10 -3
  94. data/lib/rubocop/cop/layout/first_argument_indentation.rb +35 -2
  95. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
  96. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +20 -15
  97. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
  98. data/lib/rubocop/cop/layout/hash_alignment.rb +5 -8
  99. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +3 -3
  100. data/lib/rubocop/cop/layout/heredoc_indentation.rb +33 -3
  101. data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
  102. data/lib/rubocop/cop/layout/indentation_width.rb +152 -7
  103. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  104. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
  105. data/lib/rubocop/cop/layout/line_length.rb +62 -15
  106. data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
  107. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +9 -2
  108. data/lib/rubocop/cop/layout/multiline_block_layout.rb +3 -0
  109. data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
  110. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
  111. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +236 -41
  112. data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
  113. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +9 -5
  114. data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
  115. data/lib/rubocop/cop/layout/redundant_line_break.rb +12 -6
  116. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +15 -7
  117. data/lib/rubocop/cop/layout/space_after_comma.rb +2 -10
  118. data/lib/rubocop/cop/layout/space_after_semicolon.rb +11 -1
  119. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  120. data/lib/rubocop/cop/layout/space_around_keyword.rb +10 -3
  121. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
  122. data/lib/rubocop/cop/layout/space_around_operators.rb +18 -3
  123. data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
  124. data/lib/rubocop/cop/layout/space_before_brackets.rb +6 -39
  125. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -8
  126. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
  127. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
  128. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  129. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  130. data/lib/rubocop/cop/lint/ambiguous_assignment.rb +1 -11
  131. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  132. data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +1 -10
  133. data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
  134. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  135. data/lib/rubocop/cop/lint/assignment_in_condition.rb +13 -1
  136. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  137. data/lib/rubocop/cop/lint/circular_argument_reference.rb +47 -8
  138. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +4 -3
  139. data/lib/rubocop/cop/lint/constant_reassignment.rb +93 -11
  140. data/lib/rubocop/cop/lint/constant_resolution.rb +6 -6
  141. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +90 -0
  142. data/lib/rubocop/cop/lint/data_define_override.rb +63 -0
  143. data/lib/rubocop/cop/lint/debugger.rb +13 -4
  144. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  145. data/lib/rubocop/cop/lint/deprecated_constants.rb +2 -8
  146. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +5 -2
  147. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +4 -4
  148. data/lib/rubocop/cop/lint/duplicate_methods.rb +219 -32
  149. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  150. data/lib/rubocop/cop/lint/else_layout.rb +19 -0
  151. data/lib/rubocop/cop/lint/empty_block.rb +4 -4
  152. data/lib/rubocop/cop/lint/empty_conditional_body.rb +20 -65
  153. data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
  154. data/lib/rubocop/cop/lint/empty_in_pattern.rb +8 -1
  155. data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
  156. data/lib/rubocop/cop/lint/empty_when.rb +8 -1
  157. data/lib/rubocop/cop/lint/ensure_return.rb +19 -1
  158. data/lib/rubocop/cop/lint/erb_new_arguments.rb +4 -8
  159. data/lib/rubocop/cop/lint/float_comparison.rb +33 -10
  160. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  161. data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
  162. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -1
  163. data/lib/rubocop/cop/lint/interpolation_check.rb +25 -5
  164. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
  165. data/lib/rubocop/cop/lint/literal_as_condition.rb +129 -11
  166. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +11 -1
  167. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +9 -12
  168. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +19 -10
  169. data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
  170. data/lib/rubocop/cop/lint/multiple_comparison.rb +2 -2
  171. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  172. data/lib/rubocop/cop/lint/next_without_accumulator.rb +2 -0
  173. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +20 -0
  174. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +4 -2
  175. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +4 -4
  176. data/lib/rubocop/cop/lint/number_conversion.rb +19 -10
  177. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
  178. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +11 -0
  179. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  180. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +7 -7
  181. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +3 -13
  182. data/lib/rubocop/cop/lint/raise_exception.rb +30 -11
  183. data/lib/rubocop/cop/lint/rand_one.rb +1 -1
  184. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +27 -10
  185. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +6 -12
  186. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +15 -4
  187. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  188. data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -23
  189. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +134 -11
  190. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +12 -2
  191. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +268 -0
  192. data/lib/rubocop/cop/lint/redundant_with_index.rb +4 -1
  193. data/lib/rubocop/cop/lint/redundant_with_object.rb +8 -0
  194. data/lib/rubocop/cop/lint/refinement_import_methods.rb +8 -1
  195. data/lib/rubocop/cop/lint/regexp_as_condition.rb +9 -1
  196. data/lib/rubocop/cop/lint/require_parentheses.rb +13 -4
  197. data/lib/rubocop/cop/lint/require_range_parentheses.rb +3 -2
  198. data/lib/rubocop/cop/lint/require_relative_self_path.rb +7 -5
  199. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  200. data/lib/rubocop/cop/lint/rescue_type.rb +2 -2
  201. data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
  202. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +22 -4
  203. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +7 -1
  204. data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
  205. data/lib/rubocop/cop/lint/script_permission.rb +5 -1
  206. data/lib/rubocop/cop/lint/self_assignment.rb +63 -6
  207. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -1
  208. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  209. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  210. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +27 -1
  211. data/lib/rubocop/cop/lint/shared_mutable_default.rb +14 -1
  212. data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
  213. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  214. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +123 -0
  215. data/lib/rubocop/cop/lint/symbol_conversion.rb +21 -4
  216. data/lib/rubocop/cop/lint/syntax.rb +25 -1
  217. data/lib/rubocop/cop/lint/to_enum_arguments.rb +36 -3
  218. data/lib/rubocop/cop/lint/to_json.rb +20 -17
  219. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  220. data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +5 -1
  221. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +36 -10
  222. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +2 -0
  223. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -1
  224. data/lib/rubocop/cop/lint/unreachable_code.rb +17 -9
  225. data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
  226. data/lib/rubocop/cop/lint/unreachable_pattern_branch.rb +113 -0
  227. data/lib/rubocop/cop/lint/unused_method_argument.rb +10 -0
  228. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  229. data/lib/rubocop/cop/lint/useless_access_modifier.rb +30 -4
  230. data/lib/rubocop/cop/lint/useless_assignment.rb +55 -25
  231. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +71 -0
  232. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +92 -0
  233. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +11 -10
  234. data/lib/rubocop/cop/lint/useless_or.rb +111 -0
  235. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  236. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +11 -7
  237. data/lib/rubocop/cop/lint/useless_setter_call.rb +4 -1
  238. data/lib/rubocop/cop/lint/useless_times.rb +22 -1
  239. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +147 -0
  240. data/lib/rubocop/cop/lint/void.rb +50 -21
  241. data/lib/rubocop/cop/message_annotator.rb +7 -3
  242. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  243. data/lib/rubocop/cop/metrics/block_length.rb +2 -1
  244. data/lib/rubocop/cop/metrics/block_nesting.rb +23 -0
  245. data/lib/rubocop/cop/metrics/collection_literal_length.rb +1 -1
  246. data/lib/rubocop/cop/metrics/method_length.rb +3 -2
  247. data/lib/rubocop/cop/metrics/perceived_complexity.rb +38 -7
  248. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +4 -3
  249. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  250. data/lib/rubocop/cop/metrics/utils/iterating_block.rb +1 -1
  251. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
  252. data/lib/rubocop/cop/migration/department_name.rb +12 -1
  253. data/lib/rubocop/cop/mixin/alignment.rb +3 -3
  254. data/lib/rubocop/cop/mixin/allowed_methods.rb +5 -5
  255. data/lib/rubocop/cop/mixin/allowed_pattern.rb +9 -5
  256. data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -4
  257. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +5 -7
  258. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  259. data/lib/rubocop/cop/mixin/comments_help.rb +1 -1
  260. data/lib/rubocop/cop/mixin/configurable_max.rb +6 -5
  261. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  262. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  263. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  264. data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
  265. data/lib/rubocop/cop/mixin/forbidden_pattern.rb +20 -0
  266. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
  267. data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
  268. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  269. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +22 -22
  270. data/lib/rubocop/cop/mixin/hash_subset.rb +27 -4
  271. data/lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb +63 -0
  272. data/lib/rubocop/cop/mixin/hash_transform_method.rb +32 -78
  273. data/lib/rubocop/cop/mixin/line_length_help.rb +45 -10
  274. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  275. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -1
  276. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  277. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  278. data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
  279. data/lib/rubocop/cop/mixin/project_index_help.rb +48 -0
  280. data/lib/rubocop/cop/mixin/range_help.rb +15 -3
  281. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -4
  282. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -7
  283. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  284. data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
  285. data/lib/rubocop/cop/mixin/trailing_comma.rb +25 -6
  286. data/lib/rubocop/cop/mixin.rb +86 -0
  287. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  288. data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
  289. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  290. data/lib/rubocop/cop/naming/file_name.rb +6 -5
  291. data/lib/rubocop/cop/naming/inclusive_language.rb +8 -2
  292. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +11 -2
  293. data/lib/rubocop/cop/naming/method_name.rb +187 -15
  294. data/lib/rubocop/cop/naming/predicate_method.rb +330 -0
  295. data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +48 -4
  296. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -4
  297. data/lib/rubocop/cop/naming/variable_name.rb +51 -6
  298. data/lib/rubocop/cop/offense.rb +17 -1
  299. data/lib/rubocop/cop/registry.rb +66 -39
  300. data/lib/rubocop/cop/security/eval.rb +17 -3
  301. data/lib/rubocop/cop/security/io_methods.rb +2 -2
  302. data/lib/rubocop/cop/security/json_load.rb +33 -11
  303. data/lib/rubocop/cop/security/marshal_load.rb +1 -1
  304. data/lib/rubocop/cop/security/open.rb +1 -0
  305. data/lib/rubocop/cop/style/access_modifier_declarations.rb +45 -12
  306. data/lib/rubocop/cop/style/accessor_grouping.rb +46 -8
  307. data/lib/rubocop/cop/style/alias.rb +15 -3
  308. data/lib/rubocop/cop/style/and_or.rb +2 -1
  309. data/lib/rubocop/cop/style/arguments_forwarding.rb +46 -31
  310. data/lib/rubocop/cop/style/array_first_last.rb +12 -1
  311. data/lib/rubocop/cop/style/array_intersect.rb +117 -38
  312. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +50 -0
  313. data/lib/rubocop/cop/style/array_join.rb +4 -2
  314. data/lib/rubocop/cop/style/ascii_comments.rb +6 -3
  315. data/lib/rubocop/cop/style/attr.rb +5 -2
  316. data/lib/rubocop/cop/style/bare_percent_literals.rb +4 -3
  317. data/lib/rubocop/cop/style/begin_block.rb +3 -1
  318. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  319. data/lib/rubocop/cop/style/block_delimiters.rb +42 -34
  320. data/lib/rubocop/cop/style/case_equality.rb +29 -15
  321. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  322. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  323. data/lib/rubocop/cop/style/class_and_module_children.rb +67 -12
  324. data/lib/rubocop/cop/style/class_equality_comparison.rb +22 -14
  325. data/lib/rubocop/cop/style/class_methods_definitions.rb +11 -5
  326. data/lib/rubocop/cop/style/collection_compact.rb +37 -17
  327. data/lib/rubocop/cop/style/collection_methods.rb +1 -0
  328. data/lib/rubocop/cop/style/collection_querying.rb +167 -0
  329. data/lib/rubocop/cop/style/colon_method_call.rb +16 -7
  330. data/lib/rubocop/cop/style/combinable_loops.rb +6 -0
  331. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  332. data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
  333. data/lib/rubocop/cop/style/comparable_between.rb +78 -0
  334. data/lib/rubocop/cop/style/comparable_clamp.rb +12 -1
  335. data/lib/rubocop/cop/style/concat_array_literals.rb +7 -1
  336. data/lib/rubocop/cop/style/conditional_assignment.rb +33 -24
  337. data/lib/rubocop/cop/style/constant_visibility.rb +20 -12
  338. data/lib/rubocop/cop/style/copyright.rb +22 -11
  339. data/lib/rubocop/cop/style/data_inheritance.rb +11 -0
  340. data/lib/rubocop/cop/style/date_time.rb +4 -4
  341. data/lib/rubocop/cop/style/def_with_parentheses.rb +22 -5
  342. data/lib/rubocop/cop/style/dig_chain.rb +6 -1
  343. data/lib/rubocop/cop/style/dir_empty.rb +4 -0
  344. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
  345. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +6 -1
  346. data/lib/rubocop/cop/style/documentation.rb +6 -6
  347. data/lib/rubocop/cop/style/documentation_method.rb +12 -8
  348. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  349. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  350. data/lib/rubocop/cop/style/each_with_object.rb +4 -3
  351. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  352. data/lib/rubocop/cop/style/empty_case_condition.rb +12 -2
  353. data/lib/rubocop/cop/style/empty_class_definition.rb +126 -0
  354. data/lib/rubocop/cop/style/empty_heredoc.rb +4 -0
  355. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  356. data/lib/rubocop/cop/style/empty_literal.rb +11 -2
  357. data/lib/rubocop/cop/style/empty_method.rb +0 -6
  358. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +110 -0
  359. data/lib/rubocop/cop/style/encoding.rb +7 -1
  360. data/lib/rubocop/cop/style/end_block.rb +3 -1
  361. data/lib/rubocop/cop/style/endless_method.rb +181 -18
  362. data/lib/rubocop/cop/style/env_home.rb +4 -0
  363. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  364. data/lib/rubocop/cop/style/even_odd.rb +11 -1
  365. data/lib/rubocop/cop/style/exact_regexp_match.rb +8 -1
  366. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
  367. data/lib/rubocop/cop/style/explicit_block_argument.rb +16 -3
  368. data/lib/rubocop/cop/style/exponential_notation.rb +5 -4
  369. data/lib/rubocop/cop/style/fetch_env_var.rb +33 -7
  370. data/lib/rubocop/cop/style/file_null.rb +4 -2
  371. data/lib/rubocop/cop/style/file_open.rb +84 -0
  372. data/lib/rubocop/cop/style/file_write.rb +21 -16
  373. data/lib/rubocop/cop/style/float_division.rb +15 -1
  374. data/lib/rubocop/cop/style/for.rb +4 -0
  375. data/lib/rubocop/cop/style/format_string.rb +17 -4
  376. data/lib/rubocop/cop/style/format_string_token.rb +85 -14
  377. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  378. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  379. data/lib/rubocop/cop/style/global_vars.rb +5 -2
  380. data/lib/rubocop/cop/style/guard_clause.rb +29 -23
  381. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +27 -9
  382. data/lib/rubocop/cop/style/hash_conversion.rb +28 -12
  383. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -2
  384. data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
  385. data/lib/rubocop/cop/style/hash_lookup_method.rb +102 -0
  386. data/lib/rubocop/cop/style/hash_slice.rb +16 -0
  387. data/lib/rubocop/cop/style/hash_syntax.rb +6 -1
  388. data/lib/rubocop/cop/style/hash_transform_keys.rb +19 -9
  389. data/lib/rubocop/cop/style/hash_transform_values.rb +19 -9
  390. data/lib/rubocop/cop/style/identical_conditional_branches.rb +18 -7
  391. data/lib/rubocop/cop/style/if_inside_else.rb +26 -20
  392. data/lib/rubocop/cop/style/if_unless_modifier.rb +83 -16
  393. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +16 -19
  394. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +5 -2
  395. data/lib/rubocop/cop/style/if_with_semicolon.rb +16 -6
  396. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  397. data/lib/rubocop/cop/style/inline_comment.rb +5 -2
  398. data/lib/rubocop/cop/style/inverse_methods.rb +10 -6
  399. data/lib/rubocop/cop/style/invertible_unless_condition.rb +27 -7
  400. data/lib/rubocop/cop/style/ip_addresses.rb +3 -4
  401. data/lib/rubocop/cop/style/it_assignment.rb +69 -12
  402. data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
  403. data/lib/rubocop/cop/style/keyword_arguments_merging.rb +4 -0
  404. data/lib/rubocop/cop/style/keyword_parameters_order.rb +20 -10
  405. data/lib/rubocop/cop/style/lambda.rb +8 -1
  406. data/lib/rubocop/cop/style/lambda_call.rb +26 -10
  407. data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
  408. data/lib/rubocop/cop/style/magic_comment_format.rb +3 -3
  409. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +11 -0
  410. data/lib/rubocop/cop/style/map_into_array.rb +5 -2
  411. data/lib/rubocop/cop/style/map_join.rb +123 -0
  412. data/lib/rubocop/cop/style/map_to_hash.rb +12 -3
  413. data/lib/rubocop/cop/style/map_to_set.rb +1 -3
  414. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +9 -8
  415. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +15 -2
  416. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +33 -4
  417. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -5
  418. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -1
  419. data/lib/rubocop/cop/style/method_def_parentheses.rb +7 -5
  420. data/lib/rubocop/cop/style/min_max_comparison.rb +17 -6
  421. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +10 -7
  422. data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
  423. data/lib/rubocop/cop/style/module_function.rb +4 -2
  424. data/lib/rubocop/cop/style/module_member_existence_check.rb +110 -0
  425. data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
  426. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  427. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -4
  428. data/lib/rubocop/cop/style/multiline_memoization.rb +7 -1
  429. data/lib/rubocop/cop/style/multiline_method_signature.rb +13 -16
  430. data/lib/rubocop/cop/style/mutable_constant.rb +106 -12
  431. data/lib/rubocop/cop/style/negative_array_index.rb +220 -0
  432. data/lib/rubocop/cop/style/next.rb +44 -0
  433. data/lib/rubocop/cop/style/nil_comparison.rb +11 -10
  434. data/lib/rubocop/cop/style/nil_lambda.rb +9 -1
  435. data/lib/rubocop/cop/style/non_nil_check.rb +5 -11
  436. data/lib/rubocop/cop/style/not.rb +2 -0
  437. data/lib/rubocop/cop/style/numeric_literals.rb +3 -2
  438. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  439. data/lib/rubocop/cop/style/object_then.rb +1 -0
  440. data/lib/rubocop/cop/style/one_class_per_file.rb +115 -0
  441. data/lib/rubocop/cop/style/one_line_conditional.rb +21 -12
  442. data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
  443. data/lib/rubocop/cop/style/operator_method_call.rb +11 -2
  444. data/lib/rubocop/cop/style/option_hash.rb +1 -1
  445. data/lib/rubocop/cop/style/optional_arguments.rb +1 -0
  446. data/lib/rubocop/cop/style/parallel_assignment.rb +57 -25
  447. data/lib/rubocop/cop/style/partition_instead_of_double_select.rb +270 -0
  448. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +4 -0
  449. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  450. data/lib/rubocop/cop/style/perl_backrefs.rb +5 -3
  451. data/lib/rubocop/cop/style/predicate_with_kind.rb +84 -0
  452. data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
  453. data/lib/rubocop/cop/style/proc.rb +4 -2
  454. data/lib/rubocop/cop/style/raise_args.rb +9 -9
  455. data/lib/rubocop/cop/style/reduce_to_hash.rb +200 -0
  456. data/lib/rubocop/cop/style/redundant_argument.rb +2 -0
  457. data/lib/rubocop/cop/style/redundant_array_constructor.rb +2 -2
  458. data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
  459. data/lib/rubocop/cop/style/redundant_begin.rb +38 -3
  460. data/lib/rubocop/cop/style/redundant_condition.rb +61 -1
  461. data/lib/rubocop/cop/style/redundant_constant_base.rb +5 -5
  462. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +26 -4
  463. data/lib/rubocop/cop/style/redundant_each.rb +3 -3
  464. data/lib/rubocop/cop/style/redundant_exception.rb +7 -1
  465. data/lib/rubocop/cop/style/redundant_fetch_block.rb +2 -10
  466. data/lib/rubocop/cop/style/redundant_filter_chain.rb +1 -1
  467. data/lib/rubocop/cop/style/redundant_format.rb +312 -0
  468. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
  469. data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +6 -1
  470. data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
  471. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +26 -10
  472. data/lib/rubocop/cop/style/redundant_line_continuation.rb +28 -7
  473. data/lib/rubocop/cop/style/redundant_min_max_by.rb +93 -0
  474. data/lib/rubocop/cop/style/redundant_parentheses.rb +111 -37
  475. data/lib/rubocop/cop/style/redundant_percent_q.rb +5 -3
  476. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +9 -0
  477. data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +2 -2
  478. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +12 -0
  479. data/lib/rubocop/cop/style/redundant_return.rb +3 -1
  480. data/lib/rubocop/cop/style/redundant_self.rb +20 -7
  481. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
  482. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +0 -5
  483. data/lib/rubocop/cop/style/redundant_sort.rb +7 -7
  484. data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
  485. data/lib/rubocop/cop/style/redundant_struct_keyword_init.rb +133 -0
  486. data/lib/rubocop/cop/style/regexp_literal.rb +32 -3
  487. data/lib/rubocop/cop/style/rescue_modifier.rb +6 -3
  488. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  489. data/lib/rubocop/cop/style/reverse_find.rb +51 -0
  490. data/lib/rubocop/cop/style/safe_navigation.rb +67 -20
  491. data/lib/rubocop/cop/style/select_by_kind.rb +158 -0
  492. data/lib/rubocop/cop/style/select_by_range.rb +197 -0
  493. data/lib/rubocop/cop/style/select_by_regexp.rb +53 -20
  494. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  495. data/lib/rubocop/cop/style/semicolon.rb +45 -12
  496. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
  497. data/lib/rubocop/cop/style/single_line_do_end_block.rb +21 -6
  498. data/lib/rubocop/cop/style/single_line_methods.rb +13 -8
  499. data/lib/rubocop/cop/style/sole_nested_conditional.rb +77 -101
  500. data/lib/rubocop/cop/style/special_global_vars.rb +6 -1
  501. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
  502. data/lib/rubocop/cop/style/string_concatenation.rb +18 -15
  503. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -0
  504. data/lib/rubocop/cop/style/struct_inheritance.rb +24 -2
  505. data/lib/rubocop/cop/style/super_arguments.rb +3 -4
  506. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  507. data/lib/rubocop/cop/style/symbol_proc.rb +10 -7
  508. data/lib/rubocop/cop/style/tally_method.rb +181 -0
  509. data/lib/rubocop/cop/style/ternary_parentheses.rb +11 -0
  510. data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -2
  511. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +52 -1
  512. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
  513. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +2 -2
  514. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
  515. data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
  516. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +18 -19
  517. data/lib/rubocop/cop/style/trivial_accessors.rb +2 -2
  518. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  519. data/lib/rubocop/cop/style/unless_logical_operators.rb +3 -3
  520. data/lib/rubocop/cop/style/while_until_do.rb +7 -0
  521. data/lib/rubocop/cop/style/while_until_modifier.rb +16 -1
  522. data/lib/rubocop/cop/style/word_array.rb +1 -0
  523. data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
  524. data/lib/rubocop/cop/style/yoda_expression.rb +1 -1
  525. data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -3
  526. data/lib/rubocop/cop/team.rb +105 -40
  527. data/lib/rubocop/cop/util.rb +4 -5
  528. data/lib/rubocop/cop/utils/format_string.rb +20 -5
  529. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  530. data/lib/rubocop/cop/variable_force/branch.rb +30 -6
  531. data/lib/rubocop/cop/variable_force/scope.rb +1 -1
  532. data/lib/rubocop/cop/variable_force/variable.rb +10 -3
  533. data/lib/rubocop/cop/variable_force.rb +26 -9
  534. data/lib/rubocop/cops_documentation_generator.rb +23 -7
  535. data/lib/rubocop/directive_comment.rb +80 -3
  536. data/lib/rubocop/ext/regexp_node.rb +0 -1
  537. data/lib/rubocop/file_patterns.rb +9 -1
  538. data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
  539. data/lib/rubocop/formatter/disabled_config_formatter.rb +38 -13
  540. data/lib/rubocop/formatter/formatter_set.rb +2 -2
  541. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  542. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  543. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  544. data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
  545. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
  546. data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
  547. data/lib/rubocop/formatter/simple_text_formatter.rb +0 -2
  548. data/lib/rubocop/formatter/tap_formatter.rb +5 -2
  549. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -1
  550. data/lib/rubocop/formatter.rb +22 -21
  551. data/lib/rubocop/lsp/diagnostic.rb +22 -37
  552. data/lib/rubocop/lsp/disable_comment_edits.rb +135 -0
  553. data/lib/rubocop/lsp/routes.rb +47 -11
  554. data/lib/rubocop/lsp/runtime.rb +19 -8
  555. data/lib/rubocop/lsp/server.rb +0 -2
  556. data/lib/rubocop/lsp/stdin_runner.rb +11 -18
  557. data/lib/rubocop/magic_comment.rb +28 -0
  558. data/lib/rubocop/mcp/server.rb +200 -0
  559. data/lib/rubocop/options.rb +60 -14
  560. data/lib/rubocop/path_util.rb +18 -2
  561. data/lib/rubocop/pending_cops_reporter.rb +56 -0
  562. data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
  563. data/lib/rubocop/plugin/load_error.rb +26 -0
  564. data/lib/rubocop/plugin/loader.rb +100 -0
  565. data/lib/rubocop/plugin/not_supported_error.rb +29 -0
  566. data/lib/rubocop/plugin.rb +46 -0
  567. data/lib/rubocop/project_index_loader.rb +66 -0
  568. data/lib/rubocop/rake_task.rb +5 -2
  569. data/lib/rubocop/remote_config.rb +10 -8
  570. data/lib/rubocop/result_cache.rb +72 -47
  571. data/lib/rubocop/rspec/cop_helper.rb +21 -1
  572. data/lib/rubocop/rspec/expect_offense.rb +9 -3
  573. data/lib/rubocop/rspec/shared_contexts.rb +71 -3
  574. data/lib/rubocop/rspec/support.rb +4 -0
  575. data/lib/rubocop/runner.rb +188 -65
  576. data/lib/rubocop/server/cache.rb +56 -41
  577. data/lib/rubocop/server/cli.rb +2 -2
  578. data/lib/rubocop/server/client_command/base.rb +10 -0
  579. data/lib/rubocop/server/client_command/exec.rb +2 -1
  580. data/lib/rubocop/server/client_command/start.rb +11 -1
  581. data/lib/rubocop/server/core.rb +8 -0
  582. data/lib/rubocop/target_finder.rb +21 -10
  583. data/lib/rubocop/target_ruby.rb +31 -14
  584. data/lib/rubocop/version.rb +50 -10
  585. data/lib/rubocop.rb +47 -96
  586. data/lib/ruby_lsp/rubocop/addon.rb +29 -17
  587. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +99 -0
  588. metadata +86 -16
  589. data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
  590. data/lib/ruby_lsp/rubocop/wraps_built_in_lsp_runtime.rb +0 -50
@@ -27,14 +27,43 @@ module RuboCop
27
27
  config
28
28
  end
29
29
 
30
- # rubocop:disable Metrics/AbcSize
30
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31
31
  def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
32
32
  @loaded_path = loaded_path
33
33
  @for_cop = Hash.new do |h, cop|
34
34
  cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
35
- qualified_cop_name = Cop::Registry.qualified_cop_name(cop_name, loaded_path)
36
- cop_options = self[qualified_cop_name].dup || {}
37
- cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
35
+
36
+ if ConfigObsoletion.deprecated_cop_name?(cop)
37
+ # Since a deprecated cop will no longer have a qualified name (as the badge is no
38
+ # longer valid), and since we do not want to automatically enable the cop, we just
39
+ # set the configuration to an empty hash if it is unset.
40
+ # This is necessary to allow a renamed cop have its old configuration merged in
41
+ # before being used (which is necessary to allow it to be disabled via config).
42
+ cop_options = self[cop_name].dup || {}
43
+ else
44
+ qualified_cop_name = Cop::Registry.qualified_cop_name(cop_name, loaded_path, warn: false)
45
+ cop_options = self[qualified_cop_name].dup || {}
46
+ cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
47
+
48
+ # If the cop has deprecated names (ie. it has been renamed), it is possible that
49
+ # users will still have old configuration for the cop's old name. In this case,
50
+ # if `ConfigObsoletion` is configured to warn rather than error (and therefore
51
+ # RuboCop runs), we want to respect the old configuration, so merge it in.
52
+ #
53
+ # NOTE: If there is configuration for both the cop and a deprecated names, the old
54
+ # configuration will be merged on top of the new configuration!
55
+ ConfigObsoletion.deprecated_names_for(cop).each do |deprecated_cop_name|
56
+ deprecated_config = @for_cop[deprecated_cop_name]
57
+ next if deprecated_config.empty?
58
+
59
+ warn Rainbow(<<~WARNING).yellow
60
+ Warning: Using `#{deprecated_cop_name}` configuration in #{loaded_path} for `#{cop}`.
61
+ WARNING
62
+
63
+ cop_options.merge!(@for_cop[deprecated_cop_name])
64
+ end
65
+ end
66
+
38
67
  h[cop] = h[cop_name] = cop_options
39
68
  end
40
69
  @hash = hash
@@ -43,7 +72,11 @@ module RuboCop
43
72
  @badge_config_cache = {}.compare_by_identity
44
73
  @clusivity_config_exists_cache = {}
45
74
  end
46
- # rubocop:enable Metrics/AbcSize
75
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
76
+
77
+ def loaded_plugins
78
+ @loaded_plugins ||= ConfigLoader.loaded_plugins
79
+ end
47
80
 
48
81
  def loaded_features
49
82
  @loaded_features ||= ConfigLoader.loaded_features
@@ -184,6 +217,9 @@ module RuboCop
184
217
  for_all_cops['StringLiteralsFrozenByDefault']
185
218
  end
186
219
 
220
+ # Returns true if the file matches any include pattern. If a block is given, the block is called
221
+ # to determine if the pattern is relevant (true returned by the block) or should be skipped
222
+ # (false returned).
187
223
  def file_to_include?(file)
188
224
  relative_file_path = path_relative_to_config(file)
189
225
 
@@ -195,11 +231,9 @@ module RuboCop
195
231
  absolute_file_path = File.expand_path(file)
196
232
 
197
233
  patterns_to_include.any? do |pattern|
198
- if block_given?
199
- yield pattern, relative_file_path, absolute_file_path
200
- else
201
- match_path?(pattern, relative_file_path) || match_path?(pattern, absolute_file_path)
202
- end
234
+ next if block_given? && !yield(pattern)
235
+
236
+ match_relative_or_absolute_path?(pattern, relative_file_path, absolute_file_path)
203
237
  end
204
238
  end
205
239
 
@@ -209,10 +243,7 @@ module RuboCop
209
243
  # `bundler-console` conveys `Bundler::Console`).
210
244
  return true if File.extname(file) == '.gemspec'
211
245
 
212
- file_to_include?(file) do |pattern, relative_path, absolute_path|
213
- /[A-Z]/.match?(pattern.to_s) &&
214
- (match_path?(pattern, relative_path) || match_path?(pattern, absolute_path))
215
- end
246
+ file_to_include?(file) { |pattern| /[A-Z]/.match?(pattern.to_s) }
216
247
  end
217
248
 
218
249
  # Returns true if there's a chance that an Include pattern matches hidden
@@ -253,12 +284,12 @@ module RuboCop
253
284
  loaded_path != File.join(Dir.home, ConfigLoader::DOTFILE)
254
285
  File.expand_path(File.dirname(loaded_path))
255
286
  else
256
- Dir.pwd
287
+ PathUtil.pwd
257
288
  end
258
289
  end
259
290
 
260
291
  def parser_engine
261
- @parser_engine ||= for_all_cops.fetch('ParserEngine', :parser_whitequark).to_sym
292
+ @parser_engine ||= for_all_cops.fetch('ParserEngine', :default).to_sym
262
293
  end
263
294
 
264
295
  def target_rails_version
@@ -312,6 +343,12 @@ module RuboCop
312
343
 
313
344
  private
314
345
 
346
+ def match_relative_or_absolute_path?(pattern, relative_file_path, absolute_file_path)
347
+ should_use_absolute_path = absolute?(pattern.to_s) || pattern.to_s.start_with?('..') ||
348
+ relative_file_path.start_with?('..')
349
+ match_path?(pattern, should_use_absolute_path ? absolute_file_path : relative_file_path)
350
+ end
351
+
315
352
  # @return [Float, nil] The Rails version as a `major.minor` Float.
316
353
  def target_rails_version_from_bundler_lock_file
317
354
  @target_rails_version_from_bundler_lock_file ||= read_rails_version_from_bundler_lock_file
@@ -30,7 +30,7 @@ module RuboCop
30
30
  private
31
31
 
32
32
  def find_project_root
33
- pwd = Dir.pwd
33
+ pwd = PathUtil.pwd
34
34
  gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd)
35
35
  return unless gems_file
36
36
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'erb'
4
4
  require 'yaml'
5
+ require_relative 'cache_config'
5
6
  require_relative 'config_finder'
6
7
 
7
8
  module RuboCop
@@ -22,41 +23,46 @@ module RuboCop
22
23
  class << self
23
24
  include FileFinder
24
25
 
25
- PENDING_BANNER = <<~BANNER
26
- The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
27
-
28
- Please also note that you can opt-in to new cops by default by adding this to your config:
29
- AllCops:
30
- NewCops: enable
31
- BANNER
32
-
33
26
  attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
34
- :ignore_unrecognized_cops
35
- attr_writer :default_configuration
36
- attr_reader :loaded_features
27
+ :enabled_by_default, :disabled_by_default, :ignore_unrecognized_cops
28
+ attr_writer :default_configuration, :cache_root
29
+ attr_reader :loaded_plugins, :loaded_features
37
30
 
38
31
  alias debug? debug
39
32
  alias ignore_parent_exclusion? ignore_parent_exclusion
40
33
 
34
+ def cache_root(cache_root_override = nil)
35
+ @cache_root ||= CacheConfig.root_dir_from_toplevel_config(cache_root_override)
36
+ end
37
+
41
38
  def clear_options
42
39
  @debug = nil
40
+ @loaded_plugins = Set.new
43
41
  @loaded_features = Set.new
44
42
  @disable_pending_cops = nil
45
43
  @enable_pending_cops = nil
44
+ @enabled_by_default = nil
45
+ @disabled_by_default = nil
46
46
  @ignore_parent_exclusion = nil
47
47
  @ignore_unrecognized_cops = nil
48
+ @cache_root = nil
48
49
  FileFinder.root_level = nil
49
50
  end
50
51
 
52
+ # rubocop:disable Metrics/AbcSize
51
53
  def load_file(file, check: true)
52
54
  path = file_path(file)
53
55
 
54
56
  hash = load_yaml_configuration(path)
55
57
 
58
+ rubocop_config = Config.create(hash, path, check: false)
59
+ plugins = hash.delete('plugins')
60
+ loaded_plugins = resolver.resolve_plugins(rubocop_config, plugins)
61
+ add_loaded_plugins(loaded_plugins)
62
+
56
63
  loaded_features = resolver.resolve_requires(path, hash)
57
64
  add_loaded_features(loaded_features)
58
65
 
59
- resolver.override_department_setting_for_cops({}, hash)
60
66
  resolver.resolve_inheritance_from_gems(hash)
61
67
  resolver.resolve_inheritance(path, hash, file, debug?)
62
68
  hash.delete('inherit_from')
@@ -67,6 +73,7 @@ module RuboCop
67
73
 
68
74
  Config.create(hash, path, check: check)
69
75
  end
76
+ # rubocop:enable Metrics/AbcSize
70
77
 
71
78
  def load_yaml_configuration(absolute_path)
72
79
  file_contents = read_file(absolute_path)
@@ -76,7 +83,9 @@ module RuboCop
76
83
 
77
84
  puts "configuration from #{absolute_path}" if debug?
78
85
 
79
- raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
86
+ unless hash.is_a?(Hash)
87
+ raise(ValidationError, "Malformed configuration in #{absolute_path}")
88
+ end
80
89
 
81
90
  hash
82
91
  end
@@ -84,8 +93,12 @@ module RuboCop
84
93
  def add_missing_namespaces(path, hash)
85
94
  # Using `hash.each_key` will cause the
86
95
  # `can't add a new key into hash during iteration` error
96
+ obsoletion = ConfigObsoletion.new(hash)
97
+
87
98
  hash_keys = hash.keys
88
99
  hash_keys.each do |key|
100
+ next if obsoletion.deprecated_cop_name?(key)
101
+
89
102
  q = Cop::Registry.qualified_cop_name(key, path)
90
103
  next if q == key
91
104
 
@@ -110,7 +123,7 @@ module RuboCop
110
123
  end
111
124
 
112
125
  def configuration_from_file(config_file, check: true)
113
- return default_configuration if config_file == DEFAULT_FILE
126
+ return apply_default_overrides(default_configuration) if config_file == DEFAULT_FILE
114
127
 
115
128
  config = load_file(config_file, check: check)
116
129
  config.validate_after_resolution if check
@@ -121,21 +134,7 @@ module RuboCop
121
134
  add_excludes_from_files(config, config_file)
122
135
  end
123
136
 
124
- merge_with_default(config, config_file).tap do |merged_config|
125
- unless possible_new_cops?(merged_config)
126
- pending_cops = pending_cops_only_qualified(merged_config.pending_cops)
127
- warn_on_pending_cops(pending_cops) unless pending_cops.empty?
128
- end
129
- end
130
- end
131
-
132
- def pending_cops_only_qualified(pending_cops)
133
- pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
134
- end
135
-
136
- def possible_new_cops?(config)
137
- disable_pending_cops || enable_pending_cops ||
138
- config.disabled_new_cops? || config.enabled_new_cops?
137
+ merge_with_default(config, config_file)
139
138
  end
140
139
 
141
140
  def add_excludes_from_files(config, config_file)
@@ -155,13 +154,25 @@ module RuboCop
155
154
  end
156
155
  end
157
156
 
158
- # @api private
159
- def inject_defaults!(project_root)
160
- path = File.join(project_root, 'config', 'default.yml')
161
- config = load_file(path)
162
- new_config = ConfigLoader.merge_with_default(config, path)
163
- puts "configuration from #{path}" if debug?
164
- @default_configuration = new_config
157
+ # This API is primarily intended for testing and documenting plugins.
158
+ # When testing a plugin using `rubocop/rspec/support`, the plugin is loaded automatically,
159
+ # so this API is usually not needed. It is intended to be used only when implementing tests
160
+ # that do not use `rubocop/rspec/support`.
161
+ def inject_defaults!(config_yml_path)
162
+ if Pathname(config_yml_path).directory?
163
+ warn Rainbow(<<~MESSAGE).yellow, uplevel: 1
164
+ Use config YAML file path instead of project root directory.
165
+ e.g., `path/to/config/default.yml`
166
+ MESSAGE
167
+ raise ArgumentError,
168
+ 'Passing a project root directory to `inject_defaults!` is no longer supported.'
169
+ end
170
+
171
+ path = config_yml_path.to_s
172
+ hash = ConfigLoader.load_yaml_configuration(path)
173
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
174
+
175
+ @default_configuration = ConfigLoader.merge_with_default(config, path)
165
176
  end
166
177
 
167
178
  # Returns the path RuboCop inferred as the root of the project. No file
@@ -176,24 +187,29 @@ module RuboCop
176
187
  ConfigFinder.project_root
177
188
  end
178
189
 
179
- def warn_on_pending_cops(pending_cops)
180
- warn Rainbow(PENDING_BANNER).yellow
181
-
182
- pending_cops.each { |cop| warn_pending_cop cop }
183
-
184
- warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
190
+ # Merges the given configuration with the default one.
191
+ def merge_with_default(config, config_file, unset_nil: true)
192
+ resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
185
193
  end
186
194
 
187
- def warn_pending_cop(cop)
188
- version = cop.metadata['VersionAdded'] || 'N/A'
195
+ # Applies CLI overrides for `AllCops/EnabledByDefault` and
196
+ # `AllCops/DisabledByDefault` to the given configuration. Used when the
197
+ # configuration would otherwise be returned without going through
198
+ # `merge_with_default` (e.g. there is no user-supplied `.rubocop.yml`).
199
+ def apply_default_overrides(config)
200
+ return config if @enabled_by_default.nil? && @disabled_by_default.nil?
189
201
 
190
- warn Rainbow("#{cop.name}: # new in #{version}").yellow
191
- warn Rainbow(' Enabled: true').yellow
202
+ hash = config.transform_values do |params|
203
+ params.is_a?(Hash) ? params.merge('Enabled' => !@disabled_by_default) : params
204
+ end
205
+ Config.new(hash, config.loaded_path)
192
206
  end
193
207
 
194
- # Merges the given configuration with the default one.
195
- def merge_with_default(config, config_file, unset_nil: true)
196
- resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
208
+ # @api private
209
+ # Used to add plugins that were required inside a config or from
210
+ # the CLI using `--plugin`.
211
+ def add_loaded_plugins(loaded_plugins)
212
+ @loaded_plugins.merge(Array(loaded_plugins))
197
213
  end
198
214
 
199
215
  # @api private
@@ -2,16 +2,35 @@
2
2
 
3
3
  require 'pathname'
4
4
  require 'yaml'
5
+ require_relative 'plugin'
5
6
 
6
7
  module RuboCop
7
8
  # A help class for ConfigLoader that handles configuration resolution.
8
9
  # @api private
9
10
  class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
11
+ def resolve_plugins(rubocop_config, plugins)
12
+ plugins = Array(plugins) - ConfigLoader.loaded_plugins.map { |plugin| plugin.about.name }
13
+ return if plugins.empty?
14
+
15
+ Plugin.integrate_plugins(rubocop_config, plugins)
16
+ end
17
+
10
18
  def resolve_requires(path, hash)
11
19
  config_dir = File.dirname(path)
12
20
  hash.delete('require').tap do |loaded_features|
13
21
  Array(loaded_features).each do |feature|
14
- FeatureLoader.load(config_directory_path: config_dir, feature: feature)
22
+ if Plugin.plugin_capable?(feature)
23
+ # NOTE: Compatibility for before plugins style.
24
+ warn Rainbow(<<~MESSAGE).yellow
25
+ #{feature} extension supports plugin, specify `plugins: #{feature}` instead of `require: #{feature}` in #{path}.
26
+ For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
27
+ MESSAGE
28
+ rubocop_config = Config.create(hash, path, check: false)
29
+
30
+ resolve_plugins(rubocop_config, feature)
31
+ else
32
+ FeatureLoader.load(config_directory_path: config_dir, feature: feature)
33
+ end
15
34
  end
16
35
  end
17
36
  end
@@ -26,6 +45,7 @@ module RuboCop
26
45
  base_config.each do |k, v|
27
46
  next unless v.is_a?(Hash)
28
47
 
48
+ only_base_has_include = v.key?('Include') && !hash.dig(k, 'Include')
29
49
  if hash.key?(k)
30
50
  v = merge(v, hash[k],
31
51
  cop_name: k, file: file, debug: debug,
@@ -33,7 +53,7 @@ module RuboCop
33
53
  inherit_mode: determine_inherit_mode(hash, k))
34
54
  end
35
55
  hash[k] = v
36
- fix_include_paths(base_config.loaded_path, hash, path, k, v) if v.key?('Include')
56
+ fix_include_paths(base_config.loaded_path, hash, path, k, v) if only_base_has_include
37
57
  end
38
58
  end
39
59
  end
@@ -72,11 +92,11 @@ module RuboCop
72
92
  # only cops from user configuration are enabled. If
73
93
  # AllCops:EnabledByDefault is true, it changes the Enabled params so that
74
94
  # only cops explicitly disabled in user configuration are disabled.
95
+ # When the `--disable-all-cops` or `--enable-all-cops` CLI option is given,
96
+ # it takes precedence over the configuration values.
75
97
  def merge_with_default(config, config_file, unset_nil:)
76
98
  default_configuration = ConfigLoader.default_configuration
77
-
78
- disabled_by_default = config.for_all_cops['DisabledByDefault']
79
- enabled_by_default = config.for_all_cops['EnabledByDefault']
99
+ disabled_by_default, enabled_by_default = resolve_default_overrides(config)
80
100
 
81
101
  if disabled_by_default || enabled_by_default
82
102
  default_configuration = transform(default_configuration) do |params|
@@ -105,7 +125,7 @@ module RuboCop
105
125
  elsif merge_hashes?(base_hash, derived_hash, key)
106
126
  result[key] = merge(base_hash[key], derived_hash[key], **opts)
107
127
  elsif should_union?(derived_hash, base_hash, opts[:inherit_mode], key)
108
- result[key] = base_hash[key] | derived_hash[key]
128
+ result[key] = Array(base_hash[key]) | Array(derived_hash[key])
109
129
  elsif opts[:debug]
110
130
  warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
111
131
  end
@@ -149,6 +169,14 @@ module RuboCop
149
169
 
150
170
  private
151
171
 
172
+ def resolve_default_overrides(config)
173
+ if ConfigLoader.disabled_by_default || ConfigLoader.enabled_by_default
174
+ [ConfigLoader.disabled_by_default, ConfigLoader.enabled_by_default]
175
+ else
176
+ [config.for_all_cops['DisabledByDefault'], config.for_all_cops['EnabledByDefault']]
177
+ end
178
+ end
179
+
152
180
  def disabled?(hash, department)
153
181
  hash[department].is_a?(Hash) && hash[department]['Enabled'] == false
154
182
  end
@@ -157,7 +185,7 @@ module RuboCop
157
185
  return false if inherited_file.nil? # Not inheritance resolving merge
158
186
  return false if inherited_file.start_with?('..') # Legitimate override
159
187
  return false if base_hash[key] == derived_hash[key] # Same value
160
- return false if remote_file?(inherited_file) # Can't change
188
+ return false if PathUtil.remote_file?(inherited_file) # Can't change
161
189
 
162
190
  Gem.path.none? { |dir| inherited_file.start_with?(dir) } # Can change?
163
191
  end
@@ -187,7 +215,7 @@ module RuboCop
187
215
  end
188
216
 
189
217
  def should_union?(derived_hash, base_hash, root_mode, key)
190
- return false unless base_hash[key].is_a?(Array)
218
+ return false unless base_hash[key].is_a?(Array) || derived_hash[key].is_a?(Array)
191
219
 
192
220
  derived_mode = derived_hash['inherit_mode']
193
221
  return false if should_override?(derived_mode, key)
@@ -225,9 +253,9 @@ module RuboCop
225
253
  end
226
254
 
227
255
  def inherited_file(path, inherit_from, file)
228
- if remote_file?(inherit_from)
256
+ if PathUtil.remote_file?(inherit_from)
229
257
  # A remote configuration, e.g. `inherit_from: http://example.com/rubocop.yml`.
230
- RemoteConfig.new(inherit_from, File.dirname(path))
258
+ RemoteConfig.new(inherit_from, ConfigLoader.cache_root)
231
259
  elsif Pathname.new(inherit_from).absolute?
232
260
  # An absolute path to a config, e.g. `inherit_from: /Users/me/rubocop.yml`.
233
261
  # The path may come from `inherit_gem` option, where a gem name is expanded
@@ -237,7 +265,7 @@ module RuboCop
237
265
  elsif file.is_a?(RemoteConfig)
238
266
  # A path relative to a URL, e.g. `inherit_from: configs/default.yml`
239
267
  # in a config included with `inherit_from: http://example.com/rubocop.yml`
240
- file.inherit_from_remote(inherit_from, path)
268
+ file.inherit_from_remote(inherit_from)
241
269
  else
242
270
  # A local relative path, e.g. `inherit_from: default.yml`
243
271
  print 'Inheriting ' if ConfigLoader.debug?
@@ -245,10 +273,6 @@ module RuboCop
245
273
  end
246
274
  end
247
275
 
248
- def remote_file?(uri)
249
- uri.start_with?('http://', 'https://')
250
- end
251
-
252
276
  def remote_config?(file)
253
277
  file.is_a?(RemoteConfig)
254
278
  end
@@ -280,10 +304,11 @@ module RuboCop
280
304
  begin
281
305
  gem = Bundler.load.specs[gem_name].first
282
306
  gem_path = gem.full_gem_path if gem
283
- rescue Bundler::GemfileNotFound
284
- # No Gemfile found. Bundler may be loaded manually
285
- rescue Bundler::GitError
286
- # The Gemfile exists but contains an uninstalled git source
307
+ rescue StandardError
308
+ # The Gemfile has a problem, which could be one of:
309
+ # - No Gemfile found. Bundler may be loaded manually
310
+ # - The Gemfile exists but contains an uninstalled git source
311
+ # - The Gemfile exists but cannot be loaded for some other reason
287
312
  end
288
313
  end
289
314
 
@@ -15,7 +15,7 @@ module RuboCop
15
15
  end
16
16
 
17
17
  def violated?
18
- return false if feature_loaded?
18
+ return false if plugin_loaded?
19
19
 
20
20
  affected_cops.any?
21
21
  end
@@ -38,8 +38,11 @@ module RuboCop
38
38
  end
39
39
  end
40
40
 
41
- def feature_loaded?
42
- config.loaded_features.include?(gem)
41
+ def plugin_loaded?
42
+ # Plugins loaded via `plugins` are Plugin objects with an `about.name` attribute.
43
+ # Plugins loaded via `require` are included in `loaded_features` as strings.
44
+ config.loaded_plugins.any? { |plugin| plugin.about.name == gem } ||
45
+ config.loaded_features.include?(gem)
43
46
  end
44
47
  end
45
48
  end
@@ -6,17 +6,28 @@ module RuboCop
6
6
  # a cop or moving it to a new department.
7
7
  # @api private
8
8
  class RenamedCop < CopRule
9
- attr_reader :new_name
9
+ attr_reader :new_name, :metadata
10
10
 
11
- def initialize(config, old_name, new_name)
11
+ def initialize(config, old_name, name_or_hash)
12
12
  super(config, old_name)
13
- @new_name = new_name
13
+
14
+ if name_or_hash.is_a?(Hash)
15
+ @metadata = name_or_hash
16
+ @new_name = name_or_hash['new_name']
17
+ else
18
+ @metadata = {}
19
+ @new_name = name_or_hash
20
+ end
14
21
  end
15
22
 
16
23
  def rule_message
17
24
  "The `#{old_name}` cop has been #{verb} to `#{new_name}`."
18
25
  end
19
26
 
27
+ def warning?
28
+ severity == 'warning'
29
+ end
30
+
20
31
  private
21
32
 
22
33
  def moved?
@@ -29,6 +40,10 @@ module RuboCop
29
40
  def verb
30
41
  moved? ? 'moved' : 'renamed'
31
42
  end
43
+
44
+ def severity
45
+ metadata['severity']
46
+ end
32
47
  end
33
48
  end
34
49
  end
@@ -23,9 +23,40 @@ module RuboCop
23
23
  class << self
24
24
  attr_accessor :files
25
25
 
26
+ def global
27
+ @global ||= new(Config.new)
28
+ end
29
+
30
+ def reset!
31
+ @global = nil
32
+ @deprecated_names = {}
33
+ LOAD_RULES_CACHE[rules_cache_key] = nil
34
+ end
35
+
36
+ def rules_cache_key
37
+ files.hash
38
+ end
39
+
26
40
  def legacy_cop_names
27
41
  # Used by DepartmentName#qualified_legacy_cop_name
28
- new(Config.new).rules.select(&:cop_rule?).map(&:old_name)
42
+ global.legacy_cop_names
43
+ end
44
+
45
+ def deprecated_cop_name?(name)
46
+ global.deprecated_cop_name?(name)
47
+ end
48
+
49
+ def deprecated_names_for(cop)
50
+ @deprecated_names ||= {}
51
+ return @deprecated_names[cop] if @deprecated_names.key?(cop)
52
+
53
+ @deprecated_names[cop] = global.rules.filter_map do |rule|
54
+ next unless rule.cop_rule?
55
+ next unless rule.respond_to?(:new_name)
56
+ next unless rule.new_name == cop
57
+
58
+ rule.old_name
59
+ end
29
60
  end
30
61
  end
31
62
 
@@ -45,12 +76,21 @@ module RuboCop
45
76
  raise ValidationError, messages.join("\n")
46
77
  end
47
78
 
79
+ def legacy_cop_names
80
+ # Used by DepartmentName#qualified_legacy_cop_name
81
+ cop_rules.map(&:old_name)
82
+ end
83
+
84
+ def deprecated_cop_name?(name)
85
+ legacy_cop_names.include?(name)
86
+ end
87
+
48
88
  private
49
89
 
50
90
  # Default rules for obsoletions are in config/obsoletion.yml
51
91
  # Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
52
92
  def load_rules # rubocop:disable Metrics/AbcSize
53
- rules = LOAD_RULES_CACHE[self.class.files] ||=
93
+ rules = LOAD_RULES_CACHE[self.class.rules_cache_key] ||=
54
94
  self.class.files.each_with_object({}) do |filename, hash|
55
95
  hash.merge!(YAML.safe_load(File.read(filename)) || {}) do |_key, first, second|
56
96
  case first
@@ -107,5 +147,9 @@ module RuboCop
107
147
  rule.message
108
148
  end
109
149
  end
150
+
151
+ def cop_rules
152
+ rules.select(&:cop_rule?)
153
+ end
110
154
  end
111
155
  end
@@ -25,13 +25,18 @@ module RuboCop
25
25
  @validated = true
26
26
  end
27
27
 
28
+ def apply_options!(options)
29
+ self.options_config = options[:config] if options[:config]
30
+ force_default_config! if options[:force_default_config]
31
+ end
32
+
28
33
  def options_config=(options_config)
29
34
  loaded_config = ConfigLoader.load_file(options_config)
30
35
  @options_config = ConfigLoader.merge_with_default(loaded_config, options_config)
31
36
  end
32
37
 
33
38
  def force_default_config!
34
- @options_config = ConfigLoader.default_configuration
39
+ @options_config = ConfigLoader.apply_default_overrides(ConfigLoader.default_configuration)
35
40
  end
36
41
 
37
42
  def unvalidated
@@ -44,7 +49,7 @@ module RuboCop
44
49
  end
45
50
 
46
51
  def for_pwd
47
- for_dir(Dir.pwd)
52
+ for_dir(PathUtil.pwd)
48
53
  end
49
54
 
50
55
  # If type (file/dir) is known beforehand,