rubocop 1.69.2 → 1.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +36 -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/comment_config.rb +1 -1
  8. data/lib/rubocop/config.rb +13 -4
  9. data/lib/rubocop/config_loader.rb +4 -0
  10. data/lib/rubocop/config_loader_resolver.rb +14 -3
  11. data/lib/rubocop/config_validator.rb +18 -8
  12. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  13. data/lib/rubocop/cop/base.rb +6 -0
  14. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  15. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  16. data/lib/rubocop/cop/internal_affairs/cop_enabled.rb +85 -0
  17. data/lib/rubocop/cop/internal_affairs/location_expression.rb +2 -1
  18. data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +3 -2
  19. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  20. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_processor.rb +63 -0
  21. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +131 -0
  22. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +229 -0
  23. data/lib/rubocop/cop/internal_affairs/node_type_multiple_predicates.rb +126 -0
  24. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +4 -3
  25. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +90 -0
  26. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +3 -1
  27. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +5 -4
  28. data/lib/rubocop/cop/internal_affairs.rb +4 -0
  29. data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -1
  30. data/lib/rubocop/cop/layout/argument_alignment.rb +2 -8
  31. data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
  32. data/lib/rubocop/cop/layout/class_structure.rb +9 -9
  33. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  34. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +7 -5
  35. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -0
  36. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -1
  37. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  38. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  39. data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -8
  40. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -7
  41. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -7
  42. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
  43. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
  44. data/lib/rubocop/cop/layout/hash_alignment.rb +6 -4
  45. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -0
  46. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +7 -1
  47. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -2
  48. data/lib/rubocop/cop/layout/line_length.rb +1 -0
  49. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
  50. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +25 -0
  51. data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -0
  52. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
  53. data/lib/rubocop/cop/layout/redundant_line_break.rb +7 -6
  54. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
  55. data/lib/rubocop/cop/layout/single_line_block_chain.rb +1 -1
  56. data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
  57. data/lib/rubocop/cop/layout/space_after_comma.rb +1 -1
  58. data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -1
  59. data/lib/rubocop/cop/layout/space_after_semicolon.rb +1 -1
  60. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -0
  61. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -3
  62. data/lib/rubocop/cop/layout/space_before_comma.rb +1 -1
  63. data/lib/rubocop/cop/layout/space_before_semicolon.rb +1 -1
  64. data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -3
  65. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +1 -1
  66. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +119 -0
  67. data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -3
  68. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +1 -1
  69. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +3 -3
  70. data/lib/rubocop/cop/lint/constant_reassignment.rb +148 -0
  71. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  72. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +1 -1
  73. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -1
  74. data/lib/rubocop/cop/lint/duplicate_set_element.rb +20 -7
  75. data/lib/rubocop/cop/lint/float_comparison.rb +5 -2
  76. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  77. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -1
  78. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  79. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +24 -6
  80. data/lib/rubocop/cop/lint/missing_super.rb +2 -2
  81. data/lib/rubocop/cop/lint/mixed_case_range.rb +1 -1
  82. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -1
  83. data/lib/rubocop/cop/lint/nested_method_definition.rb +8 -4
  84. data/lib/rubocop/cop/lint/next_without_accumulator.rb +1 -1
  85. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +4 -3
  86. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +1 -1
  87. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +18 -31
  88. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -1
  89. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -5
  90. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  91. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +2 -2
  92. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
  93. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +8 -1
  94. data/lib/rubocop/cop/lint/shared_mutable_default.rb +65 -0
  95. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  96. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  97. data/lib/rubocop/cop/lint/syntax.rb +4 -1
  98. data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +1 -4
  99. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +1 -1
  100. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  101. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
  102. data/lib/rubocop/cop/lint/useless_access_modifier.rb +4 -4
  103. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
  104. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  105. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +2 -1
  106. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +2 -2
  107. data/lib/rubocop/cop/lint/void.rb +4 -3
  108. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  109. data/lib/rubocop/cop/metrics/collection_literal_length.rb +7 -0
  110. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  111. data/lib/rubocop/cop/metrics/method_length.rb +8 -1
  112. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  113. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  114. data/lib/rubocop/cop/mixin/check_line_breakable.rb +11 -11
  115. data/lib/rubocop/cop/mixin/comments_help.rb +3 -1
  116. data/lib/rubocop/cop/mixin/dig_help.rb +1 -1
  117. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  118. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
  119. data/lib/rubocop/cop/mixin/hash_subset.rb +188 -0
  120. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -1
  121. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +48 -24
  122. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  123. data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -3
  124. data/lib/rubocop/cop/mixin/string_help.rb +1 -1
  125. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  126. data/lib/rubocop/cop/mixin/trailing_comma.rb +3 -3
  127. data/lib/rubocop/cop/naming/block_forwarding.rb +19 -15
  128. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -3
  129. data/lib/rubocop/cop/security/compound_hash.rb +1 -0
  130. data/lib/rubocop/cop/style/access_modifier_declarations.rb +34 -5
  131. data/lib/rubocop/cop/style/and_or.rb +1 -1
  132. data/lib/rubocop/cop/style/arguments_forwarding.rb +39 -23
  133. data/lib/rubocop/cop/style/array_first_last.rb +18 -2
  134. data/lib/rubocop/cop/style/block_delimiters.rb +7 -20
  135. data/lib/rubocop/cop/style/class_and_module_children.rb +6 -3
  136. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  137. data/lib/rubocop/cop/style/combinable_defined.rb +1 -1
  138. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  139. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -1
  140. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -4
  141. data/lib/rubocop/cop/style/documentation.rb +1 -1
  142. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  143. data/lib/rubocop/cop/style/each_for_simple_loop.rb +4 -7
  144. data/lib/rubocop/cop/style/empty_else.rb +4 -2
  145. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  146. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  147. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  148. data/lib/rubocop/cop/style/exact_regexp_match.rb +3 -10
  149. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  150. data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
  151. data/lib/rubocop/cop/style/fetch_env_var.rb +1 -1
  152. data/lib/rubocop/cop/style/float_division.rb +8 -4
  153. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  154. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -6
  155. data/lib/rubocop/cop/style/hash_except.rb +24 -148
  156. data/lib/rubocop/cop/style/hash_slice.rb +80 -0
  157. data/lib/rubocop/cop/style/hash_syntax.rb +6 -3
  158. data/lib/rubocop/cop/style/identical_conditional_branches.rb +22 -3
  159. data/lib/rubocop/cop/style/if_unless_modifier.rb +3 -3
  160. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  161. data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
  162. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  163. data/lib/rubocop/cop/style/inverse_methods.rb +6 -6
  164. data/lib/rubocop/cop/style/it_assignment.rb +36 -0
  165. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  166. data/lib/rubocop/cop/style/map_into_array.rb +1 -1
  167. data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
  168. data/lib/rubocop/cop/style/map_to_set.rb +3 -2
  169. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +19 -12
  170. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -0
  171. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -1
  172. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -4
  173. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  174. data/lib/rubocop/cop/style/missing_else.rb +2 -0
  175. data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
  176. data/lib/rubocop/cop/style/multiple_comparison.rb +26 -20
  177. data/lib/rubocop/cop/style/mutable_constant.rb +3 -3
  178. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -1
  179. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
  180. data/lib/rubocop/cop/style/object_then.rb +13 -15
  181. data/lib/rubocop/cop/style/open_struct_use.rb +5 -5
  182. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -5
  183. data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
  184. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  185. data/lib/rubocop/cop/style/proc.rb +1 -2
  186. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  187. data/lib/rubocop/cop/style/raise_args.rb +6 -4
  188. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  189. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  190. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  191. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +2 -1
  192. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +6 -10
  193. data/lib/rubocop/cop/style/redundant_each.rb +1 -1
  194. data/lib/rubocop/cop/style/redundant_exception.rb +2 -2
  195. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
  196. data/lib/rubocop/cop/style/redundant_initialize.rb +12 -3
  197. data/lib/rubocop/cop/style/redundant_line_continuation.rb +34 -13
  198. data/lib/rubocop/cop/style/redundant_parentheses.rb +10 -10
  199. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +3 -0
  200. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
  201. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  202. data/lib/rubocop/cop/style/redundant_self_assignment.rb +14 -28
  203. data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
  204. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
  205. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  206. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  207. data/lib/rubocop/cop/style/semicolon.rb +1 -1
  208. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +2 -1
  209. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  210. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -2
  211. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  212. data/lib/rubocop/cop/style/slicing_with_range.rb +40 -11
  213. data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
  214. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  215. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  216. data/lib/rubocop/cop/style/string_methods.rb +1 -1
  217. data/lib/rubocop/cop/style/super_arguments.rb +65 -17
  218. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  219. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -1
  220. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -1
  221. data/lib/rubocop/cop/style/yoda_condition.rb +8 -4
  222. data/lib/rubocop/cop/style/yoda_expression.rb +2 -1
  223. data/lib/rubocop/cop/util.rb +11 -4
  224. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  225. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -3
  226. data/lib/rubocop/cops_documentation_generator.rb +13 -13
  227. data/lib/rubocop/directive_comment.rb +9 -8
  228. data/lib/rubocop/formatter/formatter_set.rb +1 -1
  229. data/lib/rubocop/lsp/diagnostic.rb +189 -0
  230. data/lib/rubocop/lsp/logger.rb +2 -2
  231. data/lib/rubocop/lsp/routes.rb +7 -23
  232. data/lib/rubocop/lsp/runtime.rb +15 -49
  233. data/lib/rubocop/lsp/stdin_runner.rb +83 -0
  234. data/lib/rubocop/options.rb +2 -1
  235. data/lib/rubocop/path_util.rb +11 -8
  236. data/lib/rubocop/result_cache.rb +13 -13
  237. data/lib/rubocop/rspec/expect_offense.rb +6 -2
  238. data/lib/rubocop/rspec/shared_contexts.rb +4 -1
  239. data/lib/rubocop/rspec/support.rb +1 -2
  240. data/lib/rubocop/runner.rb +5 -6
  241. data/lib/rubocop/target_finder.rb +1 -0
  242. data/lib/rubocop/target_ruby.rb +15 -0
  243. data/lib/rubocop/version.rb +1 -1
  244. data/lib/rubocop.rb +6 -0
  245. data/lib/ruby_lsp/rubocop/addon.rb +78 -0
  246. data/lib/ruby_lsp/rubocop/wraps_built_in_lsp_runtime.rb +50 -0
  247. metadata +23 -11
  248. 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: a6e4d1daf086c733bdbc26101d597970c6db01884a84b1688fcdcb1d35790a93
4
+ data.tar.gz: d21d0251334f815c178e4f3654e0884857a4bfb9f13395c96c27dc26d44b735a
5
5
  SHA512:
6
- metadata.gz: aa6eb7a2cbf39d99cbda0faff3dfe690a61e9665847c21669bc9a005f9ac316e9404a8babc8cadf7f033bf82afcf317c8c503ede2306e8b3a8c211abaa878cb9
7
- data.tar.gz: 126f20d27ebf2e0098d0a1039230fea4178d2a196693db8c75326a7f3fdc797b1f030af3d116f2d74f69bb70cc033372ede6836962b2c47632a9ecf4f524dd56
6
+ metadata.gz: befa7c474d65523d27c5a309f66d5c9b90d8656c2aff30f153ef764b6ce489ece67f6851e9be3484111cf4da59cea023eedfa502ccd9407814bf0ea6e21fa146
7
+ data.tar.gz: '088876817707413c841fb293784228563caa287ac7785a53d7b60322762c2bf971f36c1d8d5ede445d2fbaaaf48360eef9a2196be154696572af820a07576a2d'
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.71', 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
@@ -2402,6 +2413,12 @@ Lint/ShadowingOuterLocalVariable:
2402
2413
  Enabled: true
2403
2414
  VersionAdded: '0.9'
2404
2415
 
2416
+ Lint/SharedMutableDefault:
2417
+ Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
2418
+ StyleGuide: '#no-mutable-defaults'
2419
+ Enabled: pending
2420
+ VersionAdded: '1.70'
2421
+
2405
2422
  Lint/StructNewOverride:
2406
2423
  Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
2407
2424
  Enabled: true
@@ -3136,13 +3153,14 @@ Style/AccessModifierDeclarations:
3136
3153
  Description: 'Checks style of how access modifiers are used.'
3137
3154
  Enabled: true
3138
3155
  VersionAdded: '0.57'
3139
- VersionChanged: '0.81'
3156
+ VersionChanged: '1.70'
3140
3157
  EnforcedStyle: group
3141
3158
  SupportedStyles:
3142
3159
  - inline
3143
3160
  - group
3144
3161
  AllowModifiersOnSymbols: true
3145
3162
  AllowModifiersOnAttrs: true
3163
+ AllowModifiersOnAliasMethod: true
3146
3164
  SafeAutoCorrect: false
3147
3165
 
3148
3166
  Style/AccessorGrouping:
@@ -4051,6 +4069,9 @@ Style/FrozenStringLiteralComment:
4051
4069
  # exist in a file.
4052
4070
  - never
4053
4071
  SafeAutoCorrect: false
4072
+ Exclude:
4073
+ # Prevent the Ruby warning: `'frozen_string_literal' is ignored after any tokens` when using Active Admin.
4074
+ - '**/*.arb'
4054
4075
 
4055
4076
  Style/GlobalStdStream:
4056
4077
  Description: 'Enforces the use of `$stdout/$stderr/$stdin` instead of `STDOUT/STDERR/STDIN`.'
@@ -4129,6 +4150,14 @@ Style/HashLikeCase:
4129
4150
  # to trigger this cop
4130
4151
  MinBranchesCount: 3
4131
4152
 
4153
+ Style/HashSlice:
4154
+ Description: >-
4155
+ Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
4156
+ that can be replaced with `Hash#slice` method.
4157
+ Enabled: pending
4158
+ Safe: false
4159
+ VersionAdded: '1.71'
4160
+
4132
4161
  Style/HashSyntax:
4133
4162
  Description: >-
4134
4163
  Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
@@ -4316,6 +4345,11 @@ Style/IpAddresses:
4316
4345
  - '**/gems.rb'
4317
4346
  - '**/*.gemspec'
4318
4347
 
4348
+ Style/ItAssignment:
4349
+ Description: 'Checks for assignment to `it` inside a block.'
4350
+ Enabled: pending
4351
+ VersionAdded: '1.70'
4352
+
4319
4353
  Style/KeywordArgumentsMerging:
4320
4354
  Description: >-
4321
4355
  When passing an existing hash as keyword arguments, provide additional arguments
@@ -5059,7 +5093,7 @@ Style/RedundantConstantBase:
5059
5093
  VersionAdded: '1.40'
5060
5094
 
5061
5095
  Style/RedundantCurrentDirectoryInPath:
5062
- Description: 'Checks for uses a redundant current directory in path.'
5096
+ Description: 'Checks for a redundant current directory in a path given to `require_relative`.'
5063
5097
  Enabled: pending
5064
5098
  VersionAdded: '1.53'
5065
5099
 
@@ -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
 
@@ -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
@@ -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
 
@@ -80,10 +81,7 @@ module RuboCop
80
81
 
81
82
  def make_excludes_absolute
82
83
  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|
84
+ dig(key, 'Exclude')&.map! do |exclude_elem|
87
85
  if exclude_elem.is_a?(String) && !absolute?(exclude_elem)
88
86
  File.expand_path(File.join(base_dir_for_path_parameters, exclude_elem))
89
87
  else
@@ -123,6 +121,13 @@ module RuboCop
123
121
  @for_cop[cop]
124
122
  end
125
123
 
124
+ # @return [Config, Hash] for the given cop / cop name.
125
+ # If the given cop is enabled, returns its configuration hash.
126
+ # Otherwise, returns an empty hash.
127
+ def for_enabled_cop(cop)
128
+ cop_enabled?(cop) ? for_cop(cop) : EMPTY_CONFIG
129
+ end
130
+
126
131
  # @return [Config] for the given cop merged with that of its department (if any)
127
132
  # Note: the 'Enabled' attribute is same as that returned by `for_cop`
128
133
  def for_badge(badge)
@@ -159,6 +164,10 @@ module RuboCop
159
164
  @for_all_cops ||= self['AllCops'] || {}
160
165
  end
161
166
 
167
+ def cop_enabled?(name)
168
+ !!for_cop(name)['Enabled']
169
+ end
170
+
162
171
  def disabled_new_cops?
163
172
  for_all_cops['NewCops'] == 'disable'
164
173
  end
@@ -41,6 +41,10 @@ module RuboCop
41
41
  def clear_options
42
42
  @debug = nil
43
43
  @loaded_features = Set.new
44
+ @disable_pending_cops = nil
45
+ @enable_pending_cops = nil
46
+ @ignore_parent_exclusion = nil
47
+ @ignore_unrecognized_cops = nil
44
48
  FileFinder.root_level = nil
45
49
  end
46
50
 
@@ -163,14 +163,21 @@ module RuboCop
163
163
  end
164
164
 
165
165
  def warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
166
+ # If the file being considered is remote, don't bother checking for duplicates
167
+ return if remote_config?(opts[:file])
168
+
166
169
  return unless duplicate_setting?(base_hash, derived_hash, key, opts[:inherited_file])
167
170
 
168
171
  inherit_mode = opts[:inherit_mode]['merge'] || opts[:inherit_mode]['override']
169
172
  return if base_hash[key].is_a?(Array) && inherit_mode&.include?(key)
170
173
 
171
- puts "#{PathUtil.smart_path(opts[:file])}: " \
172
- "#{opts[:cop_name]}:#{key} overrides " \
173
- "the same parameter in #{opts[:inherited_file]}"
174
+ puts duplicate_setting_warning(opts, key)
175
+ end
176
+
177
+ def duplicate_setting_warning(opts, key)
178
+ "#{PathUtil.smart_path(opts[:file])}: " \
179
+ "#{opts[:cop_name]}:#{key} overrides " \
180
+ "the same parameter in #{opts[:inherited_file]}"
174
181
  end
175
182
 
176
183
  def determine_inherit_mode(hash, key)
@@ -242,6 +249,10 @@ module RuboCop
242
249
  uri.start_with?('http://', 'https://')
243
250
  end
244
251
 
252
+ def remote_config?(file)
253
+ file.is_a?(RemoteConfig)
254
+ end
255
+
245
256
  def handle_disabled_by_default(config, new_default_configuration)
246
257
  department_config = config.to_hash.reject { |cop| cop.include?('/') }
247
258
  department_config.each do |dept, dept_params|
@@ -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
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # Use `config.cop_enabled?('Department/CopName')` instead of
7
+ # traversing the config hash.
8
+ #
9
+ # @example
10
+ # # `for_cop(...)['Enabled']
11
+ #
12
+ # # bad
13
+ # config.for_cop('Department/CopName')['Enabled']
14
+ #
15
+ # # good
16
+ # config.cop_enabled?('Department/CopName')
17
+ #
18
+ # @example
19
+ # # when keeping a cop's config in a local and then checking the `Enabled` key
20
+ #
21
+ # # bad
22
+ # cop_config = config.for_cop('Department/CopName')
23
+ # cop_config['Enabled'] && cop_config['Foo']
24
+ #
25
+ # # good
26
+ # config.for_enabled_cop('Department/CopName')['Foo']
27
+ #
28
+ class CopEnabled < Base
29
+ extend AutoCorrector
30
+
31
+ MSG = 'Use `%<replacement>s` instead of `%<source>s`.'
32
+ MSG_HASH = 'Consider replacing uses of `%<hash_name>s` with `config.for_enabled_cop`.'
33
+
34
+ RESTRICT_ON_SEND = [:[]].freeze
35
+
36
+ # @!method for_cop_enabled?(node)
37
+ def_node_matcher :for_cop_enabled?, <<~PATTERN
38
+ (send
39
+ (send
40
+ ${(send nil? :config) (ivar :@config)} :for_cop
41
+ $(str _)) :[]
42
+ (str "Enabled"))
43
+ PATTERN
44
+
45
+ # @!method config_enabled_lookup?(node)
46
+ def_node_matcher :config_enabled_lookup?, <<~PATTERN
47
+ (send
48
+ {(lvar $_) (ivar $_) (send nil? $_)} :[]
49
+ (str "Enabled"))
50
+ PATTERN
51
+
52
+ def on_send(node)
53
+ if (config_var, cop_name = for_cop_enabled?(node))
54
+ handle_for_cop(node, config_var, cop_name)
55
+ elsif (config_var = config_enabled_lookup?(node))
56
+ return unless config_var.end_with?('_config')
57
+
58
+ handle_hash(node, config_var)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def handle_for_cop(node, config_var, cop_name)
65
+ source = node.source
66
+ quote = cop_name.loc.begin.source
67
+ cop_name = cop_name.value
68
+
69
+ replacement = "#{config_var.source}.cop_enabled?(#{quote}#{cop_name}#{quote})"
70
+ message = format(MSG, source: source, replacement: replacement)
71
+
72
+ add_offense(node, message: message) do |corrector|
73
+ corrector.replace(node, replacement)
74
+ end
75
+ end
76
+
77
+ def handle_hash(node, config_var)
78
+ message = format(MSG_HASH, hash_name: config_var)
79
+
80
+ add_offense(node, message: message)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -22,7 +22,7 @@ module RuboCop
22
22
 
23
23
  def on_send(node)
24
24
  return unless (parent = node.parent)
25
- return unless parent.send_type? && parent.method?(:expression)
25
+ return unless parent.call_type? && parent.method?(:expression)
26
26
  return unless parent.receiver.receiver
27
27
 
28
28
  offense = node.loc.selector.join(parent.source_range.end)
@@ -31,6 +31,7 @@ module RuboCop
31
31
  corrector.replace(offense, 'source_range')
32
32
  end
33
33
  end
34
+ alias on_csend on_send
34
35
  end
35
36
  end
36
37
  end
@@ -27,8 +27,8 @@ module RuboCop
27
27
  # @!method arguments_first_or_last?(node)
28
28
  def_node_matcher :arguments_first_or_last?, <<~PATTERN
29
29
  {
30
- (send (send !nil? :arguments) ${:first :last})
31
- (send (send !nil? :arguments) :[] (int ${0 -1}))
30
+ (call (call !nil? :arguments) ${:first :last})
31
+ (call (call !nil? :arguments) :[] (int ${0 -1}))
32
32
  }
33
33
  PATTERN
34
34
 
@@ -47,6 +47,7 @@ module RuboCop
47
47
  end
48
48
  end
49
49
  end
50
+ alias on_csend on_send
50
51
  end
51
52
  end
52
53
  end
@@ -62,7 +62,7 @@ module RuboCop
62
62
  private
63
63
 
64
64
  def valid_method_name?(node)
65
- node.first_argument.str_type? || node.first_argument.sym_type?
65
+ node.first_argument.type?(:str, :sym)
66
66
  end
67
67
 
68
68
  def method_directives(node)
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ class NodePatternGroups
7
+ # AST Processor for NodePattern ASTs, for use with `InternalAffairs/NodePatternGroups`.
8
+ #
9
+ # Looks for sequences and subsequences where the first item is a `node_type` node,
10
+ # and converts them to `node_sequence` nodes (not a true `Rubocop::AST::NodePattern`
11
+ # node type).
12
+ #
13
+ # The resulting AST will be walked by `InternalAffairs::NodePatternGroups::ASTWalker`
14
+ # in order to find node types in a `union` node that can be rewritten as a node group.
15
+ #
16
+ # NOTE: The `on_*` methods in this class relate not to the normal node types but
17
+ # rather to the Node Pattern node types. Not every node type is handled.
18
+ #
19
+ class ASTProcessor
20
+ include ::AST::Processor::Mixin
21
+
22
+ def handler_missing(node)
23
+ node.updated(nil, process_children(node))
24
+ end
25
+
26
+ # Look for `sequence` and `subsequence` nodes that contain a `node_type` node as
27
+ # their first child. These are rewritten as `node_sequence` nodes so that it is
28
+ # possible to compare nodes while looking for replacement candidates for node groups.
29
+ # This is necessary so that extended patterns can be matched and replaced.
30
+ # ie. `{(send _ :foo ...) (csend _ :foo ...)}` can become `(call _ :foo ...)`
31
+ def on_sequence(node)
32
+ first_child = node.child
33
+
34
+ if first_child.type == :node_type
35
+ children = [first_child.child, *process_children(node, 1..)]
36
+
37
+ # The `node_sequence` node contains the `node_type` symbol as its first child,
38
+ # followed by all the other nodes contained in the `sequence` node.
39
+ # The location is copied from the sequence, so that the entire sequence can
40
+ # eventually be corrected in the cop.
41
+ n(:node_sequence, children, location: node.location)
42
+ else
43
+ node.updated(nil, process_children(node))
44
+ end
45
+ end
46
+ alias on_subsequence on_sequence
47
+
48
+ private
49
+
50
+ def n(type, children = [], properties = {})
51
+ NodePattern::Node.new(type, children, properties)
52
+ end
53
+
54
+ def process_children(node, range = 0..-1)
55
+ node.children[range].map do |child|
56
+ child.is_a?(::AST::Node) ? process(child) : child
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end