rubocop 1.69.2 → 1.72.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 (284) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +66 -2
  5. data/lib/rubocop/cli/command/execute_runner.rb +3 -3
  6. data/lib/rubocop/cli/command/show_cops.rb +24 -2
  7. data/lib/rubocop/cli/command/suggest_extensions.rb +7 -1
  8. data/lib/rubocop/comment_config.rb +2 -2
  9. data/lib/rubocop/config.rb +17 -4
  10. data/lib/rubocop/config_loader.rb +48 -8
  11. data/lib/rubocop/config_loader_resolver.rb +33 -8
  12. data/lib/rubocop/config_validator.rb +18 -8
  13. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  14. data/lib/rubocop/cop/base.rb +6 -0
  15. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  16. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  17. data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
  18. data/lib/rubocop/cop/internal_affairs/example_description.rb +4 -2
  19. data/lib/rubocop/cop/internal_affairs/location_exists.rb +116 -0
  20. data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
  21. data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
  22. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  23. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
  24. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
  25. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
  26. data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
  27. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
  28. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
  29. data/lib/rubocop/cop/internal_affairs/plugin.rb +33 -0
  30. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
  31. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
  32. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +7 -1
  33. data/lib/rubocop/cop/internal_affairs.rb +5 -16
  34. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
  35. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -8
  36. data/lib/rubocop/cop/layout/block_alignment.rb +3 -1
  37. data/lib/rubocop/cop/layout/class_structure.rb +9 -9
  38. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  39. data/lib/rubocop/cop/layout/else_alignment.rb +2 -2
  40. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  41. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -11
  42. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
  43. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
  44. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +22 -2
  45. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  46. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  47. data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -8
  48. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -7
  49. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
  50. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
  51. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  52. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -4
  53. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -1
  54. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
  55. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
  56. data/lib/rubocop/cop/layout/line_length.rb +1 -0
  57. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
  58. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
  59. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -0
  60. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +4 -4
  61. data/lib/rubocop/cop/layout/redundant_line_break.rb +7 -6
  62. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
  63. data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
  64. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  65. data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
  66. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  67. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  68. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -0
  69. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
  70. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -3
  71. data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
  72. data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
  73. data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -3
  74. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  75. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +119 -0
  76. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
  77. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
  78. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
  79. data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
  80. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -0
  81. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  82. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
  83. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
  84. data/lib/rubocop/cop/lint/duplicate_set_element.rb +20 -7
  85. data/lib/rubocop/cop/lint/empty_expression.rb +0 -2
  86. data/lib/rubocop/cop/lint/float_comparison.rb +5 -2
  87. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  88. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
  89. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  90. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
  91. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  92. data/lib/rubocop/cop/lint/mixed_case_range.rb +1 -1
  93. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
  94. data/lib/rubocop/cop/lint/nested_method_definition.rb +8 -4
  95. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  96. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +4 -3
  97. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  98. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +18 -31
  99. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -1
  100. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
  101. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  102. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
  103. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +231 -0
  104. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  105. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
  106. data/lib/rubocop/cop/lint/shared_mutable_default.rb +65 -0
  107. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  108. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +111 -0
  109. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  110. data/lib/rubocop/cop/lint/syntax.rb +4 -1
  111. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -4
  112. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
  113. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -1
  114. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  115. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
  116. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
  117. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
  118. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +80 -0
  119. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  120. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +2 -1
  121. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
  122. data/lib/rubocop/cop/lint/void.rb +5 -9
  123. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  124. data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
  125. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  126. data/lib/rubocop/cop/metrics/method_length.rb +8 -1
  127. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  128. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  129. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +7 -7
  130. data/lib/rubocop/cop/mixin/alignment.rb +2 -2
  131. data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
  132. data/lib/rubocop/cop/mixin/check_line_breakable.rb +11 -11
  133. data/lib/rubocop/cop/mixin/comments_help.rb +4 -2
  134. data/lib/rubocop/cop/mixin/dig_help.rb +1 -1
  135. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  136. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +22 -22
  137. data/lib/rubocop/cop/mixin/hash_subset.rb +188 -0
  138. data/lib/rubocop/cop/mixin/hash_transform_method.rb +74 -74
  139. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  140. data/lib/rubocop/cop/mixin/percent_literal.rb +1 -1
  141. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +48 -24
  142. data/lib/rubocop/cop/mixin/range_help.rb +3 -3
  143. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  144. data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -3
  145. data/lib/rubocop/cop/mixin/string_help.rb +2 -2
  146. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  147. data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
  148. data/lib/rubocop/cop/naming/block_forwarding.rb +19 -15
  149. data/lib/rubocop/cop/naming/predicate_name.rb +44 -0
  150. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
  151. data/lib/rubocop/cop/security/compound_hash.rb +1 -0
  152. data/lib/rubocop/cop/style/access_modifier_declarations.rb +34 -5
  153. data/lib/rubocop/cop/style/and_or.rb +1 -1
  154. data/lib/rubocop/cop/style/arguments_forwarding.rb +39 -23
  155. data/lib/rubocop/cop/style/array_first_last.rb +18 -2
  156. data/lib/rubocop/cop/style/block_delimiters.rb +7 -20
  157. data/lib/rubocop/cop/style/class_and_module_children.rb +6 -3
  158. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  159. data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
  160. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  161. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
  162. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -4
  163. data/lib/rubocop/cop/style/documentation.rb +1 -1
  164. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  165. data/lib/rubocop/cop/style/each_for_simple_loop.rb +4 -7
  166. data/lib/rubocop/cop/style/each_with_object.rb +2 -3
  167. data/lib/rubocop/cop/style/empty_else.rb +4 -2
  168. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  169. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  170. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  171. data/lib/rubocop/cop/style/exact_regexp_match.rb +3 -10
  172. data/lib/rubocop/cop/style/explicit_block_argument.rb +15 -2
  173. data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
  174. data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
  175. data/lib/rubocop/cop/style/float_division.rb +8 -4
  176. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  177. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -6
  178. data/lib/rubocop/cop/style/hash_except.rb +24 -148
  179. data/lib/rubocop/cop/style/hash_slice.rb +80 -0
  180. data/lib/rubocop/cop/style/hash_syntax.rb +6 -3
  181. data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
  182. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
  183. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  184. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
  185. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  186. data/lib/rubocop/cop/style/inverse_methods.rb +6 -6
  187. data/lib/rubocop/cop/style/it_assignment.rb +36 -0
  188. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  189. data/lib/rubocop/cop/style/map_into_array.rb +1 -1
  190. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  191. data/lib/rubocop/cop/style/map_to_set.rb +3 -2
  192. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -12
  193. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -0
  194. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -1
  195. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
  196. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  197. data/lib/rubocop/cop/style/missing_else.rb +2 -0
  198. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  199. data/lib/rubocop/cop/style/multiple_comparison.rb +26 -20
  200. data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
  201. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
  202. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  203. data/lib/rubocop/cop/style/object_then.rb +13 -15
  204. data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
  205. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
  206. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  207. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  208. data/lib/rubocop/cop/style/proc.rb +1 -2
  209. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  210. data/lib/rubocop/cop/style/raise_args.rb +6 -4
  211. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  212. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  213. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  214. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +2 -1
  215. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
  216. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  217. data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
  218. data/lib/rubocop/cop/style/redundant_format.rb +238 -0
  219. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
  220. data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
  221. data/lib/rubocop/cop/style/redundant_line_continuation.rb +34 -13
  222. data/lib/rubocop/cop/style/redundant_parentheses.rb +28 -14
  223. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +3 -0
  224. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
  225. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  226. data/lib/rubocop/cop/style/redundant_self_assignment.rb +14 -28
  227. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  228. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
  229. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  230. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  231. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  232. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
  233. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  234. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -2
  235. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  236. data/lib/rubocop/cop/style/slicing_with_range.rb +40 -11
  237. data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
  238. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  239. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  240. data/lib/rubocop/cop/style/string_methods.rb +1 -1
  241. data/lib/rubocop/cop/style/super_arguments.rb +65 -17
  242. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  243. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  244. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -1
  245. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  246. data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
  247. data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
  248. data/lib/rubocop/cop/util.rb +12 -5
  249. data/lib/rubocop/cop/utils/format_string.rb +7 -5
  250. data/lib/rubocop/cop/variable_force/variable.rb +14 -2
  251. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
  252. data/lib/rubocop/cops_documentation_generator.rb +13 -13
  253. data/lib/rubocop/directive_comment.rb +44 -10
  254. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  255. data/lib/rubocop/lsp/diagnostic.rb +189 -0
  256. data/lib/rubocop/lsp/logger.rb +2 -2
  257. data/lib/rubocop/lsp/routes.rb +7 -23
  258. data/lib/rubocop/lsp/runtime.rb +17 -49
  259. data/lib/rubocop/lsp/server.rb +0 -2
  260. data/lib/rubocop/lsp/stdin_runner.rb +83 -0
  261. data/lib/rubocop/options.rb +28 -12
  262. data/lib/rubocop/path_util.rb +15 -8
  263. data/lib/rubocop/plugin/configuration_integrator.rb +143 -0
  264. data/lib/rubocop/plugin/load_error.rb +26 -0
  265. data/lib/rubocop/plugin/loader.rb +100 -0
  266. data/lib/rubocop/plugin/not_supported_error.rb +29 -0
  267. data/lib/rubocop/plugin.rb +39 -0
  268. data/lib/rubocop/rake_task.rb +4 -1
  269. data/lib/rubocop/result_cache.rb +13 -13
  270. data/lib/rubocop/rspec/cop_helper.rb +9 -0
  271. data/lib/rubocop/rspec/expect_offense.rb +6 -2
  272. data/lib/rubocop/rspec/shared_contexts.rb +4 -1
  273. data/lib/rubocop/rspec/support.rb +1 -2
  274. data/lib/rubocop/runner.rb +5 -6
  275. data/lib/rubocop/server/cache.rb +35 -2
  276. data/lib/rubocop/server/cli.rb +2 -2
  277. data/lib/rubocop/target_finder.rb +1 -0
  278. data/lib/rubocop/target_ruby.rb +15 -0
  279. data/lib/rubocop/version.rb +17 -2
  280. data/lib/rubocop.rb +11 -0
  281. data/lib/ruby_lsp/rubocop/addon.rb +75 -0
  282. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +47 -0
  283. metadata +53 -15
  284. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45af4a986637b8c3dacb16d942870c2138501ae834e79c0875b81bbf09644b54
4
- data.tar.gz: 65961fc4cb25730ad9528201e22a82427def59f6ad5f048cd01a0ca89a437c3c
3
+ metadata.gz: 4a6ff0f849d961da13d2131ff60e0ed49dce01a4c2d32caa8484a2344344609b
4
+ data.tar.gz: 9da9fc43212c62cd6542649c90423e9365f50cb00e82b6337be1a241c6a17283
5
5
  SHA512:
6
- metadata.gz: aa6eb7a2cbf39d99cbda0faff3dfe690a61e9665847c21669bc9a005f9ac316e9404a8babc8cadf7f033bf82afcf317c8c503ede2306e8b3a8c211abaa878cb9
7
- data.tar.gz: 126f20d27ebf2e0098d0a1039230fea4178d2a196693db8c75326a7f3fdc797b1f030af3d116f2d74f69bb70cc033372ede6836962b2c47632a9ecf4f524dd56
6
+ metadata.gz: 7ff34957554167b3b1e30645e3754094968fae93d0284a3882460b3e24f44fd64bcf358b23fd0e8154489206fd9c95fc6555b551f1af5ac810805fac2b6d27be
7
+ data.tar.gz: 48e989049de37523554c740ba1368e32de38bc0f879c1fc717924a758a1ba465ef4413cba80a42be59ccaaf87616b52c0ad437256702bf5fd091c4a5818f428a
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-24 Bozhidar Batsov
1
+ Copyright (c) 2012-25 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
@@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
52
52
  in your `Gemfile`:
53
53
 
54
54
  ```rb
55
- gem 'rubocop', '~> 1.69', require: false
55
+ gem 'rubocop', '~> 1.72', require: false
56
56
  ```
57
57
 
58
58
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -247,5 +247,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
247
247
 
248
248
  ## Copyright
249
249
 
250
- Copyright (c) 2012-2024 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
250
+ Copyright (c) 2012-2025 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
251
251
  further details.
data/config/default.yml CHANGED
@@ -1616,6 +1616,12 @@ Lint/AmbiguousRegexpLiteral:
1616
1616
  VersionAdded: '0.17'
1617
1617
  VersionChanged: '0.83'
1618
1618
 
1619
+ Lint/ArrayLiteralInRegexp:
1620
+ Description: 'Checks for an array literal interpolated inside a regexp.'
1621
+ Enabled: pending
1622
+ VersionAdded: '1.71'
1623
+ SafeAutoCorrect: false
1624
+
1619
1625
  Lint/AssignmentInCondition:
1620
1626
  Description: "Don't use assignment in conditions."
1621
1627
  StyleGuide: '#safe-assignment-in-condition'
@@ -1665,6 +1671,11 @@ Lint/ConstantOverwrittenInRescue:
1665
1671
  Enabled: pending
1666
1672
  VersionAdded: '1.31'
1667
1673
 
1674
+ Lint/ConstantReassignment:
1675
+ Description: 'Checks for constant reassignments.'
1676
+ Enabled: pending
1677
+ VersionAdded: '1.70'
1678
+
1668
1679
  Lint/ConstantResolution:
1669
1680
  Description: 'Check that constants are fully qualified with `::`.'
1670
1681
  Enabled: false
@@ -1674,6 +1685,11 @@ Lint/ConstantResolution:
1674
1685
  # Restrict this cop from only looking at certain names
1675
1686
  Ignore: []
1676
1687
 
1688
+ Lint/CopDirectiveSyntax:
1689
+ Description: 'Checks that `# rubocop:` directives are strictly formatted.'
1690
+ Enabled: pending
1691
+ VersionAdded: '1.72'
1692
+
1677
1693
  Lint/Debugger:
1678
1694
  Description: 'Check for debugger calls.'
1679
1695
  Enabled: true
@@ -2274,6 +2290,11 @@ Lint/RedundantStringCoercion:
2274
2290
  VersionAdded: '0.19'
2275
2291
  VersionChanged: '0.77'
2276
2292
 
2293
+ Lint/RedundantTypeConversion:
2294
+ Description: 'Checks for redundantly converting a literal to the same type.'
2295
+ Enabled: pending
2296
+ VersionAdded: '1.72'
2297
+
2277
2298
  Lint/RedundantWithIndex:
2278
2299
  Description: 'Checks for redundant `with_index`.'
2279
2300
  Enabled: true
@@ -2402,6 +2423,12 @@ Lint/ShadowingOuterLocalVariable:
2402
2423
  Enabled: true
2403
2424
  VersionAdded: '0.9'
2404
2425
 
2426
+ Lint/SharedMutableDefault:
2427
+ Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
2428
+ StyleGuide: '#no-mutable-defaults'
2429
+ Enabled: pending
2430
+ VersionAdded: '1.70'
2431
+
2405
2432
  Lint/StructNewOverride:
2406
2433
  Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
2407
2434
  Enabled: true
@@ -2416,6 +2443,12 @@ Lint/SuppressedException:
2416
2443
  VersionAdded: '0.9'
2417
2444
  VersionChanged: '1.12'
2418
2445
 
2446
+ Lint/SuppressedExceptionInNumberConversion:
2447
+ Description: 'Checks for cases where exceptions unrelated to the numeric constructors may be unintentionally swallowed.'
2448
+ Enabled: pending
2449
+ SafeAutoCorrect: false
2450
+ VersionAdded: '1.72'
2451
+
2419
2452
  Lint/SymbolConversion:
2420
2453
  Description: 'Checks for unnecessary symbol conversions.'
2421
2454
  Enabled: pending
@@ -2571,6 +2604,11 @@ Lint/UselessAssignment:
2571
2604
  VersionAdded: '0.11'
2572
2605
  VersionChanged: '1.66'
2573
2606
 
2607
+ Lint/UselessConstantScoping:
2608
+ Description: 'Checks for useless constant scoping.'
2609
+ Enabled: pending
2610
+ VersionAdded: '1.72'
2611
+
2574
2612
  Lint/UselessDefined:
2575
2613
  Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2576
2614
  Enabled: pending
@@ -3024,6 +3062,8 @@ Naming/PredicateName:
3024
3062
  MethodDefinitionMacros:
3025
3063
  - define_method
3026
3064
  - define_singleton_method
3065
+ # Use Sorbet's T::Boolean return type to detect predicate methods.
3066
+ UseSorbetSigs: false
3027
3067
  # Exclude Rspec specs because there is a strong convention to write spec
3028
3068
  # helpers in the form of `have_something` or `be_something`.
3029
3069
  Exclude:
@@ -3136,13 +3176,14 @@ Style/AccessModifierDeclarations:
3136
3176
  Description: 'Checks style of how access modifiers are used.'
3137
3177
  Enabled: true
3138
3178
  VersionAdded: '0.57'
3139
- VersionChanged: '0.81'
3179
+ VersionChanged: '1.70'
3140
3180
  EnforcedStyle: group
3141
3181
  SupportedStyles:
3142
3182
  - inline
3143
3183
  - group
3144
3184
  AllowModifiersOnSymbols: true
3145
3185
  AllowModifiersOnAttrs: true
3186
+ AllowModifiersOnAliasMethod: true
3146
3187
  SafeAutoCorrect: false
3147
3188
 
3148
3189
  Style/AccessorGrouping:
@@ -4051,6 +4092,9 @@ Style/FrozenStringLiteralComment:
4051
4092
  # exist in a file.
4052
4093
  - never
4053
4094
  SafeAutoCorrect: false
4095
+ Exclude:
4096
+ # Prevent the Ruby warning: `'frozen_string_literal' is ignored after any tokens` when using Active Admin.
4097
+ - '**/*.arb'
4054
4098
 
4055
4099
  Style/GlobalStdStream:
4056
4100
  Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
@@ -4129,6 +4173,14 @@ Style/HashLikeCase:
4129
4173
  # to trigger this cop
4130
4174
  MinBranchesCount: 3
4131
4175
 
4176
+ Style/HashSlice:
4177
+ Description: >-
4178
+ Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
4179
+ that can be replaced with `Hash#slice` method.
4180
+ Enabled: pending
4181
+ Safe: false
4182
+ VersionAdded: '1.71'
4183
+
4132
4184
  Style/HashSyntax:
4133
4185
  Description: >-
4134
4186
  Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
@@ -4316,6 +4368,11 @@ Style/IpAddresses:
4316
4368
  - '**/gems.rb'
4317
4369
  - '**/*.gemspec'
4318
4370
 
4371
+ Style/ItAssignment:
4372
+ Description: 'Checks for assignment to `it` inside a block.'
4373
+ Enabled: pending
4374
+ VersionAdded: '1.70'
4375
+
4319
4376
  Style/KeywordArgumentsMerging:
4320
4377
  Description: >-
4321
4378
  When passing an existing hash as keyword arguments, provide additional arguments
@@ -5059,7 +5116,7 @@ Style/RedundantConstantBase:
5059
5116
  VersionAdded: '1.40'
5060
5117
 
5061
5118
  Style/RedundantCurrentDirectoryInPath:
5062
- Description: 'Checks for uses a redundant current directory in path.'
5119
+ Description: 'Checks for a redundant current directory in a path given to `require_relative`.'
5063
5120
  Enabled: pending
5064
5121
  VersionAdded: '1.53'
5065
5122
 
@@ -5111,6 +5168,13 @@ Style/RedundantFilterChain:
5111
5168
  VersionAdded: '1.52'
5112
5169
  VersionChanged: '1.57'
5113
5170
 
5171
+ Style/RedundantFormat:
5172
+ Description: 'Checks for usages of `Kernel#format` or `Kernel#sprintf` with only a single argument.'
5173
+ Enabled: pending
5174
+ SafeAutoCorrect: false
5175
+ VersionAdded: '1.72'
5176
+ VersionChanged: '1.72'
5177
+
5114
5178
  Style/RedundantFreeze:
5115
5179
  Description: "Checks usages of Object#freeze on immutable objects."
5116
5180
  Enabled: true
@@ -71,11 +71,11 @@ module RuboCop
71
71
 
72
72
  warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
73
73
 
74
- errors.each { |error| warn error }
74
+ errors.each { |error| warn Rainbow(error).red }
75
75
 
76
- warn <<~WARNING
76
+ warn Rainbow(<<~WARNING.strip).yellow
77
77
  Errors are usually caused by RuboCop bugs.
78
- Please, report your problems to RuboCop's issue tracker.
78
+ Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.
79
79
  #{bug_tracker_uri}
80
80
  Mention the following information in the issue report:
81
81
  #{RuboCop::Version.verbose}
@@ -9,11 +9,31 @@ module RuboCop
9
9
  class ShowCops < Base
10
10
  self.command_name = :show_cops
11
11
 
12
+ ExactMatcher = Struct.new(:pattern) do
13
+ def match?(name)
14
+ name == pattern
15
+ end
16
+ end
17
+
18
+ WildcardMatcher = Struct.new(:pattern) do
19
+ def match?(name)
20
+ File.fnmatch(pattern, name, File::FNM_PATHNAME)
21
+ end
22
+ end
23
+
12
24
  def initialize(env)
13
25
  super
14
26
 
15
27
  # Load the configs so the require()s are done for custom cops
16
28
  @config = @config_store.for(Dir.pwd)
29
+
30
+ @cop_matchers = @options[:show_cops].map do |pattern|
31
+ if pattern.include?('*')
32
+ WildcardMatcher.new(pattern)
33
+ else
34
+ ExactMatcher.new(pattern)
35
+ end
36
+ end
17
37
  end
18
38
 
19
39
  def run
@@ -24,7 +44,7 @@ module RuboCop
24
44
 
25
45
  def print_available_cops
26
46
  registry = Cop::Registry.global
27
- show_all = @options[:show_cops].empty?
47
+ show_all = @cop_matchers.empty?
28
48
 
29
49
  puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: " if show_all
30
50
 
@@ -56,7 +76,9 @@ module RuboCop
56
76
 
57
77
  def selected_cops_of_department(cops, department)
58
78
  cops_of_department(cops, department).select do |cop|
59
- @options[:show_cops].include?(cop.cop_name)
79
+ @cop_matchers.any? do |matcher|
80
+ matcher.match?(cop.cop_name)
81
+ end
60
82
  end
61
83
  end
62
84
 
@@ -97,7 +97,13 @@ module RuboCop
97
97
  end
98
98
 
99
99
  def loaded_extensions
100
- @config_store.for_pwd.loaded_features.to_a
100
+ rubocop_config = @config_store.for_pwd
101
+
102
+ plugin_names = rubocop_config.loaded_plugins.map do |plugin|
103
+ plugin.about.name
104
+ end
105
+
106
+ plugin_names + rubocop_config.loaded_features.to_a
101
107
  end
102
108
 
103
109
  def installed_and_not_loaded_extensions
@@ -87,7 +87,7 @@ module RuboCop
87
87
  next unless directive.enabled?
88
88
  next if directive.all_cops?
89
89
 
90
- cops.merge(directive.cop_names)
90
+ cops.merge(directive.raw_cop_names)
91
91
  end
92
92
  cops
93
93
  end
@@ -205,7 +205,7 @@ module RuboCop
205
205
  directive.cop_names.each do |name|
206
206
  if directive.disabled?
207
207
  names[name] += 1
208
- elsif (names[name]).positive?
208
+ elsif names[name].positive?
209
209
  names[name] -= 1
210
210
  else
211
211
  extras[directive.comment] << name
@@ -16,6 +16,7 @@ module RuboCop
16
16
 
17
17
  CopConfig = Struct.new(:name, :metadata)
18
18
 
19
+ EMPTY_CONFIG = {}.freeze
19
20
  DEFAULT_RAILS_VERSION = 5.0
20
21
  attr_reader :loaded_path
21
22
 
@@ -44,6 +45,10 @@ module RuboCop
44
45
  end
45
46
  # rubocop:enable Metrics/AbcSize
46
47
 
48
+ def loaded_plugins
49
+ @loaded_plugins ||= ConfigLoader.loaded_plugins
50
+ end
51
+
47
52
  def loaded_features
48
53
  @loaded_features ||= ConfigLoader.loaded_features
49
54
  end
@@ -80,10 +85,7 @@ module RuboCop
80
85
 
81
86
  def make_excludes_absolute
82
87
  each_key do |key|
83
- @validator.validate_section_presence(key)
84
- next unless self[key]['Exclude']
85
-
86
- self[key]['Exclude'].map! do |exclude_elem|
88
+ dig(key, 'Exclude')&.map! do |exclude_elem|
87
89
  if exclude_elem.is_a?(String) && !absolute?(exclude_elem)
88
90
  File.expand_path(File.join(base_dir_for_path_parameters, exclude_elem))
89
91
  else
@@ -123,6 +125,13 @@ module RuboCop
123
125
  @for_cop[cop]
124
126
  end
125
127
 
128
+ # @return [Config, Hash] for the given cop / cop name.
129
+ # If the given cop is enabled, returns its configuration hash.
130
+ # Otherwise, returns an empty hash.
131
+ def for_enabled_cop(cop)
132
+ cop_enabled?(cop) ? for_cop(cop) : EMPTY_CONFIG
133
+ end
134
+
126
135
  # @return [Config] for the given cop merged with that of its department (if any)
127
136
  # Note: the 'Enabled' attribute is same as that returned by `for_cop`
128
137
  def for_badge(badge)
@@ -159,6 +168,10 @@ module RuboCop
159
168
  @for_all_cops ||= self['AllCops'] || {}
160
169
  end
161
170
 
171
+ def cop_enabled?(name)
172
+ !!for_cop(name)['Enabled']
173
+ end
174
+
162
175
  def disabled_new_cops?
163
176
  for_all_cops['NewCops'] == 'disable'
164
177
  end
@@ -33,22 +33,33 @@ module RuboCop
33
33
  attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
34
34
  :ignore_unrecognized_cops
35
35
  attr_writer :default_configuration
36
- attr_reader :loaded_features
36
+ attr_reader :loaded_plugins, :loaded_features
37
37
 
38
38
  alias debug? debug
39
39
  alias ignore_parent_exclusion? ignore_parent_exclusion
40
40
 
41
41
  def clear_options
42
42
  @debug = nil
43
+ @loaded_plugins = Set.new
43
44
  @loaded_features = Set.new
45
+ @disable_pending_cops = nil
46
+ @enable_pending_cops = nil
47
+ @ignore_parent_exclusion = nil
48
+ @ignore_unrecognized_cops = nil
44
49
  FileFinder.root_level = nil
45
50
  end
46
51
 
52
+ # rubocop:disable Metrics/AbcSize
47
53
  def load_file(file, check: true)
48
54
  path = file_path(file)
49
55
 
50
56
  hash = load_yaml_configuration(path)
51
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
+
52
63
  loaded_features = resolver.resolve_requires(path, hash)
53
64
  add_loaded_features(loaded_features)
54
65
 
@@ -63,6 +74,7 @@ module RuboCop
63
74
 
64
75
  Config.create(hash, path, check: check)
65
76
  end
77
+ # rubocop:enable Metrics/AbcSize
66
78
 
67
79
  def load_yaml_configuration(absolute_path)
68
80
  file_contents = read_file(absolute_path)
@@ -151,14 +163,35 @@ module RuboCop
151
163
  end
152
164
  end
153
165
 
154
- # @api private
155
- def inject_defaults!(project_root)
156
- path = File.join(project_root, 'config', 'default.yml')
157
- config = load_file(path)
158
- new_config = ConfigLoader.merge_with_default(config, path)
159
- puts "configuration from #{path}" if debug?
160
- @default_configuration = new_config
166
+ # This API is primarily intended for testing and documenting plugins.
167
+ # When testing a plugin using `rubocop/rspec/support`, the plugin is loaded automatically,
168
+ # so this API is usually not needed. It is intended to be used only when implementing tests
169
+ # that do not use `rubocop/rspec/support`.
170
+ # rubocop:disable Metrics/MethodLength
171
+ def inject_defaults!(config_yml_path)
172
+ if Pathname(config_yml_path).directory?
173
+ # TODO: Since the warning noise is expected to be high until some time after the release,
174
+ # warnings will only be issued when `RUBYOPT=-w` is specified.
175
+ # To proceed step by step, the next step is to remove `$VERBOSE` and always issue warning.
176
+ # Eventually, `project_root` will no longer be accepted.
177
+ if $VERBOSE
178
+ warn Rainbow(<<~MESSAGE).yellow, uplevel: 1
179
+ Use config YAML file path instead of project root directory.
180
+ e.g., `path/to/config/default.yml`
181
+ MESSAGE
182
+ end
183
+ # NOTE: For compatibility.
184
+ project_root = config_yml_path
185
+ path = File.join(project_root, 'config', 'default.yml')
186
+ config = load_file(path)
187
+ else
188
+ hash = ConfigLoader.load_yaml_configuration(config_yml_path.to_s)
189
+ config = Config.new(hash, config_yml_path).tap(&:make_excludes_absolute)
190
+ end
191
+
192
+ @default_configuration = ConfigLoader.merge_with_default(config, path)
161
193
  end
194
+ # rubocop:enable Metrics/MethodLength
162
195
 
163
196
  # Returns the path RuboCop inferred as the root of the project. No file
164
197
  # searches will go past this directory.
@@ -192,6 +225,13 @@ module RuboCop
192
225
  resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
193
226
  end
194
227
 
228
+ # @api private
229
+ # Used to add plugins that were required inside a config or from
230
+ # the CLI using `--plugin`.
231
+ def add_loaded_plugins(loaded_plugins)
232
+ @loaded_plugins.merge(Array(loaded_plugins))
233
+ end
234
+
195
235
  # @api private
196
236
  # Used to add features that were required inside a config or from
197
237
  # the CLI using `--require`.
@@ -2,16 +2,34 @@
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
+ return if (plugins = Array(plugins)).empty?
13
+
14
+ Plugin.integrate_plugins(rubocop_config, plugins)
15
+ end
16
+
10
17
  def resolve_requires(path, hash)
11
18
  config_dir = File.dirname(path)
12
19
  hash.delete('require').tap do |loaded_features|
13
20
  Array(loaded_features).each do |feature|
14
- FeatureLoader.load(config_directory_path: config_dir, feature: feature)
21
+ if Plugin.plugin_capable?(feature)
22
+ # NOTE: Compatibility for before plugins style.
23
+ warn Rainbow(<<~MESSAGE).yellow
24
+ #{feature} extension supports plugin, specify `plugins: #{feature}` instead of `require: #{feature}` in #{path}.
25
+ For more information, see https://docs.rubocop.org/rubocop/plugin_migration_guide.html.
26
+ MESSAGE
27
+ rubocop_config = Config.create(hash, path, check: false)
28
+
29
+ resolve_plugins(rubocop_config, feature)
30
+ else
31
+ FeatureLoader.load(config_directory_path: config_dir, feature: feature)
32
+ end
15
33
  end
16
34
  end
17
35
  end
@@ -157,20 +175,27 @@ module RuboCop
157
175
  return false if inherited_file.nil? # Not inheritance resolving merge
158
176
  return false if inherited_file.start_with?('..') # Legitimate override
159
177
  return false if base_hash[key] == derived_hash[key] # Same value
160
- return false if remote_file?(inherited_file) # Can't change
178
+ return false if PathUtil.remote_file?(inherited_file) # Can't change
161
179
 
162
180
  Gem.path.none? { |dir| inherited_file.start_with?(dir) } # Can change?
163
181
  end
164
182
 
165
183
  def warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
184
+ # If the file being considered is remote, don't bother checking for duplicates
185
+ return if remote_config?(opts[:file])
186
+
166
187
  return unless duplicate_setting?(base_hash, derived_hash, key, opts[:inherited_file])
167
188
 
168
189
  inherit_mode = opts[:inherit_mode]['merge'] || opts[:inherit_mode]['override']
169
190
  return if base_hash[key].is_a?(Array) && inherit_mode&.include?(key)
170
191
 
171
- puts "#{PathUtil.smart_path(opts[:file])}: " \
172
- "#{opts[:cop_name]}:#{key} overrides " \
173
- "the same parameter in #{opts[:inherited_file]}"
192
+ puts duplicate_setting_warning(opts, key)
193
+ end
194
+
195
+ def duplicate_setting_warning(opts, key)
196
+ "#{PathUtil.smart_path(opts[:file])}: " \
197
+ "#{opts[:cop_name]}:#{key} overrides " \
198
+ "the same parameter in #{opts[:inherited_file]}"
174
199
  end
175
200
 
176
201
  def determine_inherit_mode(hash, key)
@@ -218,7 +243,7 @@ module RuboCop
218
243
  end
219
244
 
220
245
  def inherited_file(path, inherit_from, file)
221
- if remote_file?(inherit_from)
246
+ if PathUtil.remote_file?(inherit_from)
222
247
  # A remote configuration, e.g. `inherit_from: http://example.com/rubocop.yml`.
223
248
  RemoteConfig.new(inherit_from, File.dirname(path))
224
249
  elsif Pathname.new(inherit_from).absolute?
@@ -238,8 +263,8 @@ module RuboCop
238
263
  end
239
264
  end
240
265
 
241
- def remote_file?(uri)
242
- uri.start_with?('http://', 'https://')
266
+ def remote_config?(file)
267
+ file.is_a?(RemoteConfig)
243
268
  end
244
269
 
245
270
  def handle_disabled_by_default(config, new_default_configuration)
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  # Handles validation of configuration, for example cop names, parameter
5
5
  # names, and Ruby versions.
6
+ # rubocop:disable Metrics/ClassLength
6
7
  class ConfigValidator
7
8
  extend SimpleForwardable
8
9
 
@@ -41,8 +42,9 @@ module RuboCop
41
42
  ConfigLoader.default_configuration.key?(key)
42
43
  end
43
44
 
44
- check_obsoletions
45
+ validate_parameter_shape(valid_cop_names)
45
46
 
47
+ check_obsoletions
46
48
  alert_about_unrecognized_cops(invalid_cop_names)
47
49
  validate_new_cops_parameter
48
50
  validate_parameter_names(valid_cop_names)
@@ -64,12 +66,6 @@ module RuboCop
64
66
  target_ruby.version
65
67
  end
66
68
 
67
- def validate_section_presence(name)
68
- return unless @config.key?(name) && @config[name].nil?
69
-
70
- raise ValidationError, "empty section #{name} found in #{smart_loaded_path}"
71
- end
72
-
73
69
  private
74
70
 
75
71
  attr_reader :target_ruby
@@ -177,9 +173,22 @@ module RuboCop
177
173
  raise ValidationError, message
178
174
  end
179
175
 
176
+ def validate_parameter_shape(valid_cop_names)
177
+ valid_cop_names.each do |name|
178
+ if @config[name].nil?
179
+ raise ValidationError, "empty section #{name.inspect} found in #{smart_loaded_path}"
180
+ elsif !@config[name].is_a?(Hash)
181
+ raise ValidationError, <<~MESSAGE
182
+ The configuration for #{name.inspect} in #{smart_loaded_path} is not a Hash.
183
+
184
+ Found: #{@config[name].inspect}
185
+ MESSAGE
186
+ end
187
+ end
188
+ end
189
+
180
190
  def validate_parameter_names(valid_cop_names)
181
191
  valid_cop_names.each do |name|
182
- validate_section_presence(name)
183
192
  each_invalid_parameter(name) do |param, supported_params|
184
193
  warn Rainbow(<<~MESSAGE).yellow
185
194
  Warning: #{name} does not support #{param} parameter.
@@ -277,4 +286,5 @@ module RuboCop
277
286
  "is supposed to be #{supposed_values} and #{Rainbow(value).yellow} is not."
278
287
  end
279
288
  end
289
+ # rubocop:enable Metrics/ClassLength
280
290
  end
@@ -102,7 +102,7 @@ module RuboCop
102
102
  end
103
103
 
104
104
  def string_continuation?(node)
105
- (node.str_type? || node.dstr_type? || node.xstr_type?) && node.source.match?(/\\\s*$/)
105
+ node.type?(:str, :dstr, :xstr) && node.source.match?(/\\\s*$/)
106
106
  end
107
107
 
108
108
  def multiline_string?(node)
@@ -261,6 +261,12 @@ module RuboCop
261
261
  @config.target_ruby_version
262
262
  end
263
263
 
264
+ # Returns a gems locked versions (i.e. from Gemfile.lock or gems.locked)
265
+ # @returns [Gem::Version | nil] The locked gem version, or nil if the gem is not present.
266
+ def target_gem_version(gem_name)
267
+ @config.gem_versions_in_target && @config.gem_versions_in_target[gem_name]
268
+ end
269
+
264
270
  def parser_engine
265
271
  @config.parser_engine
266
272
  end
@@ -66,7 +66,7 @@ module RuboCop
66
66
 
67
67
  def conditional_declaration?(nodes)
68
68
  parent = nodes[0].each_ancestor.find { |ancestor| !ancestor.begin_type? }
69
- return false unless parent&.if_type? || parent&.when_type?
69
+ return false unless parent&.type?(:if, :when)
70
70
 
71
71
  root_conditional_node = parent.if_type? ? parent : parent.parent
72
72
  nodes.all? { |node| within_conditional?(node, root_conditional_node) }
@@ -161,7 +161,7 @@ module RuboCop
161
161
  end
162
162
 
163
163
  def gem_options(node)
164
- return [] unless node.last_argument&.type == :hash
164
+ return [] unless node.last_argument&.hash_type?
165
165
 
166
166
  node.last_argument.keys.map(&:value)
167
167
  end