rubocop 1.72.1 → 1.81.7

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 (316) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -18
  3. data/config/default.yml +240 -65
  4. data/config/internal_affairs.yml +20 -0
  5. data/config/obsoletion.yml +8 -3
  6. data/exe/rubocop +1 -8
  7. data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
  8. data/lib/rubocop/cli.rb +19 -4
  9. data/lib/rubocop/config.rb +35 -6
  10. data/lib/rubocop/config_loader.rb +8 -40
  11. data/lib/rubocop/config_loader_resolver.rb +9 -7
  12. data/lib/rubocop/config_obsoletion/extracted_cop.rb +4 -3
  13. data/lib/rubocop/config_obsoletion/renamed_cop.rb +18 -3
  14. data/lib/rubocop/config_obsoletion.rb +46 -2
  15. data/lib/rubocop/config_store.rb +5 -0
  16. data/lib/rubocop/config_validator.rb +7 -6
  17. data/lib/rubocop/cop/autocorrect_logic.rb +22 -14
  18. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  19. data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
  20. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  21. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
  22. data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
  23. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
  24. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  25. data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
  26. data/lib/rubocop/cop/internal_affairs/example_description.rb +9 -5
  27. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
  28. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +6 -2
  29. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +92 -0
  30. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  31. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +6 -5
  32. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
  33. data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
  34. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  35. data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
  36. data/lib/rubocop/cop/layout/block_end_newline.rb +1 -0
  37. data/lib/rubocop/cop/layout/class_structure.rb +36 -1
  38. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -5
  39. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  40. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  41. data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
  42. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  43. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +32 -14
  44. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
  45. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +34 -4
  46. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
  47. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -0
  48. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  49. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  50. data/lib/rubocop/cop/layout/hash_alignment.rb +4 -7
  51. data/lib/rubocop/cop/layout/indentation_width.rb +1 -0
  52. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  53. data/lib/rubocop/cop/layout/line_length.rb +43 -10
  54. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -0
  55. data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +1 -0
  56. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +9 -5
  57. data/lib/rubocop/cop/layout/redundant_line_break.rb +9 -5
  58. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +11 -5
  59. data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
  60. data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
  61. data/lib/rubocop/cop/layout/space_around_operators.rb +12 -1
  62. data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -0
  63. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
  64. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
  65. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -0
  66. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  67. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  68. data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
  69. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  70. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  71. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  72. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
  73. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
  74. data/lib/rubocop/cop/lint/debugger.rb +2 -4
  75. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  76. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +5 -2
  77. data/lib/rubocop/cop/lint/duplicate_methods.rb +111 -23
  78. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  79. data/lib/rubocop/cop/lint/empty_conditional_body.rb +14 -64
  80. data/lib/rubocop/cop/lint/empty_interpolation.rb +14 -1
  81. data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -6
  82. data/lib/rubocop/cop/lint/float_comparison.rb +32 -10
  83. data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
  84. data/lib/rubocop/cop/lint/literal_as_condition.rb +124 -10
  85. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +17 -8
  86. data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -2
  87. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  88. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -3
  89. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
  90. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  91. data/lib/rubocop/cop/lint/raise_exception.rb +29 -10
  92. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  93. data/lib/rubocop/cop/lint/redundant_require_statement.rb +0 -21
  94. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
  95. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +43 -13
  96. data/lib/rubocop/cop/lint/redundant_with_index.rb +3 -0
  97. data/lib/rubocop/cop/lint/redundant_with_object.rb +3 -0
  98. data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
  99. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  100. data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
  101. data/lib/rubocop/cop/lint/return_in_void_context.rb +9 -11
  102. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
  103. data/lib/rubocop/cop/lint/self_assignment.rb +31 -5
  104. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  105. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -1
  106. data/lib/rubocop/cop/lint/shared_mutable_default.rb +12 -1
  107. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  108. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
  109. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  110. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +2 -0
  111. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -0
  112. data/lib/rubocop/cop/lint/unreachable_loop.rb +5 -5
  113. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  114. data/lib/rubocop/cop/lint/useless_access_modifier.rb +30 -4
  115. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  116. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +9 -12
  117. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
  118. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
  119. data/lib/rubocop/cop/lint/useless_or.rb +98 -0
  120. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  121. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
  122. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
  123. data/lib/rubocop/cop/lint/void.rb +16 -2
  124. data/lib/rubocop/cop/message_annotator.rb +7 -3
  125. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  126. data/lib/rubocop/cop/metrics/block_length.rb +1 -0
  127. data/lib/rubocop/cop/metrics/method_length.rb +1 -0
  128. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  129. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  130. data/lib/rubocop/cop/mixin/allowed_pattern.rb +4 -4
  131. data/lib/rubocop/cop/mixin/check_line_breakable.rb +3 -3
  132. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +2 -2
  133. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  134. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  135. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  136. data/lib/rubocop/cop/mixin/forbidden_identifiers.rb +20 -0
  137. data/lib/rubocop/cop/mixin/forbidden_pattern.rb +16 -0
  138. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
  139. data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
  140. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  141. data/lib/rubocop/cop/mixin/hash_subset.rb +19 -4
  142. data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
  143. data/lib/rubocop/cop/mixin/method_complexity.rb +1 -0
  144. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  145. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  146. data/lib/rubocop/cop/mixin/range_help.rb +12 -0
  147. data/lib/rubocop/cop/mixin/target_ruby_version.rb +1 -1
  148. data/lib/rubocop/cop/mixin/trailing_comma.rb +18 -2
  149. data/lib/rubocop/cop/naming/block_forwarding.rb +3 -3
  150. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  151. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  152. data/lib/rubocop/cop/naming/method_name.rb +187 -15
  153. data/lib/rubocop/cop/naming/predicate_method.rb +319 -0
  154. data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
  155. data/lib/rubocop/cop/naming/variable_name.rb +51 -6
  156. data/lib/rubocop/cop/registry.rb +9 -6
  157. data/lib/rubocop/cop/security/eval.rb +2 -1
  158. data/lib/rubocop/cop/security/json_load.rb +33 -11
  159. data/lib/rubocop/cop/security/open.rb +1 -0
  160. data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
  161. data/lib/rubocop/cop/style/accessor_grouping.rb +32 -6
  162. data/lib/rubocop/cop/style/arguments_forwarding.rb +21 -24
  163. data/lib/rubocop/cop/style/array_intersect.rb +113 -38
  164. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  165. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  166. data/lib/rubocop/cop/style/block_delimiters.rb +3 -2
  167. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  168. data/lib/rubocop/cop/style/class_and_module_children.rb +48 -10
  169. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
  170. data/lib/rubocop/cop/style/collection_methods.rb +1 -0
  171. data/lib/rubocop/cop/style/collection_querying.rb +167 -0
  172. data/lib/rubocop/cop/style/combinable_loops.rb +1 -0
  173. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  174. data/lib/rubocop/cop/style/commented_keyword.rb +12 -5
  175. data/lib/rubocop/cop/style/comparable_between.rb +78 -0
  176. data/lib/rubocop/cop/style/conditional_assignment.rb +26 -8
  177. data/lib/rubocop/cop/style/constant_visibility.rb +14 -9
  178. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  179. data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
  180. data/lib/rubocop/cop/style/dig_chain.rb +1 -1
  181. data/lib/rubocop/cop/style/double_negation.rb +3 -3
  182. data/lib/rubocop/cop/style/empty_literal.rb +4 -0
  183. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
  184. data/lib/rubocop/cop/style/endless_method.rb +176 -18
  185. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  186. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -7
  187. data/lib/rubocop/cop/style/explicit_block_argument.rb +3 -3
  188. data/lib/rubocop/cop/style/exponential_notation.rb +5 -4
  189. data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
  190. data/lib/rubocop/cop/style/float_division.rb +15 -1
  191. data/lib/rubocop/cop/style/for.rb +1 -0
  192. data/lib/rubocop/cop/style/format_string_token.rb +38 -11
  193. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  194. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  195. data/lib/rubocop/cop/style/guard_clause.rb +2 -1
  196. data/lib/rubocop/cop/style/hash_conversion.rb +16 -8
  197. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -2
  198. data/lib/rubocop/cop/style/hash_fetch_chain.rb +104 -0
  199. data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
  200. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  201. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  202. data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
  203. data/lib/rubocop/cop/style/if_inside_else.rb +10 -13
  204. data/lib/rubocop/cop/style/if_unless_modifier.rb +35 -8
  205. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
  206. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  207. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  208. data/lib/rubocop/cop/style/inverse_methods.rb +10 -6
  209. data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
  210. data/lib/rubocop/cop/style/ip_addresses.rb +2 -2
  211. data/lib/rubocop/cop/style/it_assignment.rb +69 -12
  212. data/lib/rubocop/cop/style/it_block_parameter.rb +121 -0
  213. data/lib/rubocop/cop/style/keyword_parameters_order.rb +13 -7
  214. data/lib/rubocop/cop/style/lambda.rb +1 -0
  215. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  216. data/lib/rubocop/cop/style/line_end_concatenation.rb +10 -4
  217. data/lib/rubocop/cop/style/map_into_array.rb +4 -1
  218. data/lib/rubocop/cop/style/map_to_hash.rb +12 -3
  219. data/lib/rubocop/cop/style/map_to_set.rb +1 -3
  220. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +9 -8
  221. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
  222. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -1
  223. data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
  224. data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
  225. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  226. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -9
  227. data/lib/rubocop/cop/style/next.rb +44 -0
  228. data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
  229. data/lib/rubocop/cop/style/object_then.rb +1 -0
  230. data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
  231. data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
  232. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  233. data/lib/rubocop/cop/style/proc.rb +1 -0
  234. data/lib/rubocop/cop/style/raise_args.rb +8 -8
  235. data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
  236. data/lib/rubocop/cop/style/redundant_begin.rb +35 -0
  237. data/lib/rubocop/cop/style/redundant_condition.rb +57 -0
  238. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +14 -4
  239. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  240. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
  241. data/lib/rubocop/cop/style/redundant_format.rb +79 -18
  242. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -2
  243. data/lib/rubocop/cop/style/redundant_interpolation.rb +12 -3
  244. data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -4
  245. data/lib/rubocop/cop/style/redundant_parentheses.rb +73 -18
  246. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
  247. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  248. data/lib/rubocop/cop/style/redundant_self.rb +9 -5
  249. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
  250. data/lib/rubocop/cop/style/redundant_sort_by.rb +17 -1
  251. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  252. data/lib/rubocop/cop/style/rescue_modifier.rb +3 -0
  253. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  254. data/lib/rubocop/cop/style/safe_navigation.rb +61 -14
  255. data/lib/rubocop/cop/style/select_by_regexp.rb +4 -1
  256. data/lib/rubocop/cop/style/semicolon.rb +23 -7
  257. data/lib/rubocop/cop/style/single_line_do_end_block.rb +3 -1
  258. data/lib/rubocop/cop/style/single_line_methods.rb +10 -7
  259. data/lib/rubocop/cop/style/sole_nested_conditional.rb +75 -101
  260. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
  261. data/lib/rubocop/cop/style/string_concatenation.rb +18 -15
  262. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  263. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  264. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  265. data/lib/rubocop/cop/style/symbol_proc.rb +3 -1
  266. data/lib/rubocop/cop/style/top_level_method_definition.rb +1 -0
  267. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +52 -1
  268. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +47 -6
  269. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  270. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +48 -6
  271. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  272. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  273. data/lib/rubocop/cop/team.rb +1 -1
  274. data/lib/rubocop/cop/util.rb +1 -1
  275. data/lib/rubocop/cop/utils/format_string.rb +15 -2
  276. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  277. data/lib/rubocop/cop/variable_force/scope.rb +1 -1
  278. data/lib/rubocop/cop/variable_force/variable.rb +3 -8
  279. data/lib/rubocop/cop/variable_force.rb +26 -9
  280. data/lib/rubocop/cops_documentation_generator.rb +23 -7
  281. data/lib/rubocop/directive_comment.rb +1 -1
  282. data/lib/rubocop/ext/regexp_node.rb +0 -1
  283. data/lib/rubocop/formatter/disabled_config_formatter.rb +19 -5
  284. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  285. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  286. data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
  287. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
  288. data/lib/rubocop/formatter/pacman_formatter.rb +2 -1
  289. data/lib/rubocop/lsp/diagnostic.rb +25 -24
  290. data/lib/rubocop/lsp/routes.rb +65 -9
  291. data/lib/rubocop/lsp/runtime.rb +5 -5
  292. data/lib/rubocop/lsp/server.rb +2 -2
  293. data/lib/rubocop/lsp/stdin_runner.rb +3 -17
  294. data/lib/rubocop/magic_comment.rb +8 -0
  295. data/lib/rubocop/pending_cops_reporter.rb +56 -0
  296. data/lib/rubocop/plugin/configuration_integrator.rb +2 -0
  297. data/lib/rubocop/plugin/load_error.rb +1 -1
  298. data/lib/rubocop/plugin.rb +9 -2
  299. data/lib/rubocop/result_cache.rb +14 -12
  300. data/lib/rubocop/rspec/cop_helper.rb +6 -1
  301. data/lib/rubocop/rspec/expect_offense.rb +9 -3
  302. data/lib/rubocop/rspec/shared_contexts.rb +34 -0
  303. data/lib/rubocop/rspec/support.rb +3 -0
  304. data/lib/rubocop/runner.rb +10 -4
  305. data/lib/rubocop/server/cache.rb +17 -12
  306. data/lib/rubocop/server/client_command/base.rb +10 -0
  307. data/lib/rubocop/server/client_command/exec.rb +2 -1
  308. data/lib/rubocop/server/client_command/start.rb +11 -1
  309. data/lib/rubocop/target_finder.rb +13 -9
  310. data/lib/rubocop/target_ruby.rb +11 -2
  311. data/lib/rubocop/version.rb +14 -7
  312. data/lib/rubocop.rb +17 -2
  313. data/lib/ruby_lsp/rubocop/addon.rb +25 -10
  314. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +57 -5
  315. metadata +24 -8
  316. data/lib/rubocop/cop/utils/regexp_ranges.rb +0 -113
data/config/default.yml CHANGED
@@ -146,12 +146,14 @@ AllCops:
146
146
  # Ruby version is still unresolved, RuboCop will use the oldest officially
147
147
  # supported Ruby version (currently Ruby 2.7).
148
148
  TargetRubyVersion: ~
149
- # You can specify the parser engine. There are two options available:
149
+ # RuboCop choses the parser engine automatically but you can also specify it yourself.
150
+ # These options are available:
151
+ # - `default`
150
152
  # - `parser_whitequark` ... https://github.com/whitequark/parser
151
153
  # - `parser_prism` ... https://github.com/ruby/prism (`Prism::Translation::Parser`)
152
- # By default, `parser` is used. For the `TargetRubyVersion` value, `parser` can be specified for versions `2.0` and above.
153
- # `parser_prism` can be specified for versions `3.3` and above. `parser_prism` is faster but still considered experimental.
154
- ParserEngine: parser_whitequark
154
+ # Not every parser engine can handle every `TargetRubyVersion`. `parser_whitequark`
155
+ # only works with versions 3.4 and below, `parser_prism` with versions 3.3 and above.
156
+ ParserEngine: default
155
157
  # Determines if a notification for extension libraries should be shown when
156
158
  # rubocop is run. Keys are the name of the extension, and values are an array
157
159
  # of gems in the Gemfile that the extension is suggested for, if not already
@@ -272,12 +274,20 @@ Bundler/OrderedGems:
272
274
  Gemspec/AddRuntimeDependency:
273
275
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
274
276
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
275
- Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
277
+ References:
278
+ - https://github.com/ruby/rubygems/issues/7799#issuecomment-2192720316
276
279
  Enabled: pending
277
280
  VersionAdded: '1.65'
278
281
  Include:
279
282
  - '**/*.gemspec'
280
283
 
284
+ Gemspec/AttributeAssignment:
285
+ Description: 'Use consistent style for Gemspec attributes assignment.'
286
+ Enabled: pending
287
+ VersionAdded: '1.77'
288
+ Include:
289
+ - '**/*.gemspec'
290
+
281
291
  Gemspec/DependencyVersion:
282
292
  Description: 'Requires or forbids specifying gem dependency versions.'
283
293
  Enabled: false
@@ -341,7 +351,7 @@ Gemspec/RequireMFA:
341
351
  Severity: warning
342
352
  VersionAdded: '1.23'
343
353
  VersionChanged: '1.40'
344
- Reference:
354
+ References:
345
355
  - https://guides.rubygems.org/mfa-requirement-opt-in/
346
356
  Include:
347
357
  - '**/*.gemspec'
@@ -368,7 +378,7 @@ Gemspec/RubyVersionGlobalsUsage:
368
378
  #################### Layout ###########################
369
379
 
370
380
  Layout/AccessModifierIndentation:
371
- Description: Check indentation of private/protected visibility modifiers.
381
+ Description: Checks indentation of private/protected visibility modifiers.
372
382
  StyleGuide: '#indent-public-private-protected'
373
383
  Enabled: true
374
384
  VersionAdded: '0.49'
@@ -602,7 +612,7 @@ Layout/EmptyLineAfterMultilineCondition:
602
612
  # This is disabled, because this style is not very common in practice.
603
613
  Enabled: false
604
614
  VersionAdded: '0.90'
605
- Reference:
615
+ References:
606
616
  - https://github.com/airbnb/ruby#multiline-if-newline
607
617
 
608
618
  Layout/EmptyLineBetweenDefs:
@@ -628,6 +638,12 @@ Layout/EmptyLines:
628
638
  Enabled: true
629
639
  VersionAdded: '0.49'
630
640
 
641
+ Layout/EmptyLinesAfterModuleInclusion:
642
+ Description: 'Keeps track of empty lines after module inclusion methods.'
643
+ StyleGuide: '#empty-lines-after-module-inclusion'
644
+ Enabled: pending
645
+ VersionAdded: '1.79'
646
+
631
647
  Layout/EmptyLinesAroundAccessModifier:
632
648
  Description: "Keep blank lines around access modifiers."
633
649
  StyleGuide: '#empty-lines-around-access-modifier'
@@ -637,7 +653,7 @@ Layout/EmptyLinesAroundAccessModifier:
637
653
  SupportedStyles:
638
654
  - around
639
655
  - only_before
640
- Reference:
656
+ References:
641
657
  # A reference to `EnforcedStyle: only_before`.
642
658
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
643
659
 
@@ -994,7 +1010,7 @@ Layout/IndentationConsistency:
994
1010
  SupportedStyles:
995
1011
  - normal
996
1012
  - indented_internal_methods
997
- Reference:
1013
+ References:
998
1014
  # A reference to `EnforcedStyle: indented_internal_methods`.
999
1015
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
1000
1016
 
@@ -1041,7 +1057,7 @@ Layout/LeadingCommentSpace:
1041
1057
  AllowSteepAnnotation: false
1042
1058
 
1043
1059
  Layout/LeadingEmptyLines:
1044
- Description: Check for unnecessary blank lines at the beginning of a file.
1060
+ Description: Checks for unnecessary blank lines at the beginning of a file.
1045
1061
  Enabled: true
1046
1062
  VersionAdded: '0.57'
1047
1063
  VersionChanged: '0.77'
@@ -1092,6 +1108,7 @@ Layout/LineLength:
1092
1108
  # To make it possible to copy or click on URIs in the code, we allow lines
1093
1109
  # containing a URI to be longer than Max.
1094
1110
  AllowURI: true
1111
+ AllowQualifiedName: true
1095
1112
  URISchemes:
1096
1113
  - http
1097
1114
  - https
@@ -1130,7 +1147,7 @@ Layout/MultilineArrayLineBreaks:
1130
1147
  AllowMultilineFinalElement: false
1131
1148
 
1132
1149
  Layout/MultilineAssignmentLayout:
1133
- Description: 'Check for a newline after the assignment operator in multi-line assignments.'
1150
+ Description: 'Checks for a newline after the assignment operator in multi-line assignments.'
1134
1151
  StyleGuide: '#indent-conditional-assignment'
1135
1152
  Enabled: false
1136
1153
  VersionAdded: '0.49'
@@ -1644,7 +1661,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
1644
1661
  VersionChanged: '1.69'
1645
1662
 
1646
1663
  Lint/BooleanSymbol:
1647
- Description: 'Check for `:true` and `:false` symbols.'
1664
+ Description: 'Checks for `:true` and `:false` symbols.'
1648
1665
  Enabled: true
1649
1666
  SafeAutoCorrect: false
1650
1667
  VersionAdded: '0.50'
@@ -1677,7 +1694,7 @@ Lint/ConstantReassignment:
1677
1694
  VersionAdded: '1.70'
1678
1695
 
1679
1696
  Lint/ConstantResolution:
1680
- Description: 'Check that constants are fully qualified with `::`.'
1697
+ Description: 'Checks that constants are fully qualified with `::`.'
1681
1698
  Enabled: false
1682
1699
  VersionAdded: '0.86'
1683
1700
  # Restrict this cop to only looking at certain names
@@ -1691,7 +1708,7 @@ Lint/CopDirectiveSyntax:
1691
1708
  VersionAdded: '1.72'
1692
1709
 
1693
1710
  Lint/Debugger:
1694
- Description: 'Check for debugger calls.'
1711
+ Description: 'Checks for debugger calls.'
1695
1712
  Enabled: true
1696
1713
  VersionAdded: '0.14'
1697
1714
  VersionChanged: '1.63'
@@ -1742,7 +1759,7 @@ Lint/Debugger:
1742
1759
  - debug/start
1743
1760
 
1744
1761
  Lint/DeprecatedClassMethods:
1745
- Description: 'Check for deprecated class method calls.'
1762
+ Description: 'Checks for deprecated class method calls.'
1746
1763
  Enabled: true
1747
1764
  VersionAdded: '0.19'
1748
1765
 
@@ -1816,13 +1833,13 @@ Lint/DuplicateElsifCondition:
1816
1833
  VersionAdded: '0.88'
1817
1834
 
1818
1835
  Lint/DuplicateHashKey:
1819
- Description: 'Check for duplicate keys in hash literals.'
1836
+ Description: 'Checks for duplicate keys in hash literals.'
1820
1837
  Enabled: true
1821
1838
  VersionAdded: '0.34'
1822
1839
  VersionChanged: '0.77'
1823
1840
 
1824
1841
  Lint/DuplicateMagicComment:
1825
- Description: 'Check for duplicated magic comments.'
1842
+ Description: 'Checks for duplicated magic comments.'
1826
1843
  Enabled: pending
1827
1844
  VersionAdded: '1.37'
1828
1845
 
@@ -1832,7 +1849,7 @@ Lint/DuplicateMatchPattern:
1832
1849
  VersionAdded: '1.50'
1833
1850
 
1834
1851
  Lint/DuplicateMethods:
1835
- Description: 'Check for duplicate method definitions.'
1852
+ Description: 'Checks for duplicate method definitions.'
1836
1853
  Enabled: true
1837
1854
  VersionAdded: '0.29'
1838
1855
 
@@ -1842,7 +1859,7 @@ Lint/DuplicateRegexpCharacterClassElement:
1842
1859
  VersionAdded: '1.1'
1843
1860
 
1844
1861
  Lint/DuplicateRequire:
1845
- Description: 'Check for duplicate `require`s and `require_relative`s.'
1862
+ Description: 'Checks for duplicate `require`s and `require_relative`s.'
1846
1863
  Enabled: true
1847
1864
  SafeAutoCorrect: false
1848
1865
  VersionAdded: '0.90'
@@ -1859,12 +1876,12 @@ Lint/DuplicateSetElement:
1859
1876
  VersionAdded: '1.67'
1860
1877
 
1861
1878
  Lint/EachWithObjectArgument:
1862
- Description: 'Check for immutable argument given to each_with_object.'
1879
+ Description: 'Checks for immutable argument given to each_with_object.'
1863
1880
  Enabled: true
1864
1881
  VersionAdded: '0.31'
1865
1882
 
1866
1883
  Lint/ElseLayout:
1867
- Description: 'Check for odd code arrangement in an else block.'
1884
+ Description: 'Checks for odd code arrangement in an else block.'
1868
1885
  Enabled: true
1869
1886
  VersionAdded: '0.17'
1870
1887
  VersionChanged: '1.2'
@@ -1887,10 +1904,9 @@ Lint/EmptyConditionalBody:
1887
1904
  Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1888
1905
  Enabled: true
1889
1906
  AutoCorrect: contextual
1890
- SafeAutoCorrect: false
1891
1907
  AllowComments: true
1892
1908
  VersionAdded: '0.89'
1893
- VersionChanged: '1.61'
1909
+ VersionChanged: '1.73'
1894
1910
 
1895
1911
  Lint/EmptyEnsure:
1896
1912
  Description: 'Checks for empty ensure block.'
@@ -1921,7 +1937,7 @@ Lint/EmptyInterpolation:
1921
1937
  Enabled: true
1922
1938
  AutoCorrect: contextual
1923
1939
  VersionAdded: '0.20'
1924
- VersionChanged: '1.61'
1940
+ VersionChanged: '1.76'
1925
1941
 
1926
1942
  Lint/EmptyWhen:
1927
1943
  Description: 'Checks for `when` branches with empty bodies.'
@@ -2034,7 +2050,8 @@ Lint/InterpolationCheck:
2034
2050
 
2035
2051
  Lint/ItWithoutArgumentsInBlock:
2036
2052
  Description: 'Checks uses of `it` calls without arguments in block.'
2037
- Reference: 'https://bugs.ruby-lang.org/issues/18980'
2053
+ References:
2054
+ - 'https://bugs.ruby-lang.org/issues/18980'
2038
2055
  Enabled: pending
2039
2056
  VersionAdded: '1.59'
2040
2057
 
@@ -2046,6 +2063,7 @@ Lint/LambdaWithoutLiteralBlock:
2046
2063
  Lint/LiteralAsCondition:
2047
2064
  Description: 'Checks of literals used in conditions.'
2048
2065
  Enabled: true
2066
+ AutoCorrect: contextual
2049
2067
  VersionAdded: '0.51'
2050
2068
 
2051
2069
  Lint/LiteralAssignmentInCondition:
@@ -2259,14 +2277,14 @@ Lint/RedundantRegexpQuantifiers:
2259
2277
  Lint/RedundantRequireStatement:
2260
2278
  Description: 'Checks for unnecessary `require` statement.'
2261
2279
  Enabled: true
2262
- SafeAutoCorrect: false
2263
2280
  VersionAdded: '0.76'
2264
- VersionChanged: '1.57'
2281
+ VersionChanged: '1.73'
2265
2282
 
2266
2283
  Lint/RedundantSafeNavigation:
2267
2284
  Description: 'Checks for redundant safe navigation calls.'
2268
2285
  Enabled: true
2269
2286
  VersionAdded: '0.93'
2287
+ VersionChanged: '1.79'
2270
2288
  AllowedMethods:
2271
2289
  - instance_of?
2272
2290
  - kind_of?
@@ -2274,6 +2292,12 @@ Lint/RedundantSafeNavigation:
2274
2292
  - eql?
2275
2293
  - respond_to?
2276
2294
  - equal?
2295
+ InferNonNilReceiver: false
2296
+ AdditionalNilMethods:
2297
+ - present?
2298
+ - blank?
2299
+ - try
2300
+ - try!
2277
2301
  Safe: false
2278
2302
 
2279
2303
  Lint/RedundantSplatExpansion:
@@ -2397,6 +2421,7 @@ Lint/SelfAssignment:
2397
2421
  Description: 'Checks for self-assignments.'
2398
2422
  Enabled: true
2399
2423
  VersionAdded: '0.89'
2424
+ AllowRBSInlineAnnotation: false
2400
2425
 
2401
2426
  Lint/SendWithMixinArgument:
2402
2427
  Description: 'Checks for `send` method when using mixin.'
@@ -2420,8 +2445,9 @@ Lint/ShadowingOuterLocalVariable:
2420
2445
  Description: >-
2421
2446
  Do not use the same name as outer local variable
2422
2447
  for block arguments or block local variables.
2423
- Enabled: true
2448
+ Enabled: false
2424
2449
  VersionAdded: '0.9'
2450
+ VersionChanged: '1.76'
2425
2451
 
2426
2452
  Lint/SharedMutableDefault:
2427
2453
  Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
@@ -2609,6 +2635,13 @@ Lint/UselessConstantScoping:
2609
2635
  Enabled: pending
2610
2636
  VersionAdded: '1.72'
2611
2637
 
2638
+ Lint/UselessDefaultValueArgument:
2639
+ Description: 'Checks for usage of `fetch` or `Array.new` with default value argument and block.'
2640
+ Enabled: pending
2641
+ VersionAdded: '1.76'
2642
+ Safe: false
2643
+ AllowedReceivers: []
2644
+
2612
2645
  Lint/UselessDefined:
2613
2646
  Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2614
2647
  Enabled: pending
@@ -2633,6 +2666,11 @@ Lint/UselessNumericOperation:
2633
2666
  Enabled: pending
2634
2667
  VersionAdded: '1.66'
2635
2668
 
2669
+ Lint/UselessOr:
2670
+ Description: 'Checks for useless OR expressions.'
2671
+ Enabled: pending
2672
+ VersionAdded: '1.76'
2673
+
2636
2674
  Lint/UselessRescue:
2637
2675
  Description: 'Checks for useless `rescue`s.'
2638
2676
  Enabled: pending
@@ -2672,8 +2710,8 @@ Metrics/AbcSize:
2672
2710
  Description: >-
2673
2711
  A calculated magnitude based on number of assignments,
2674
2712
  branches, and conditions.
2675
- Reference:
2676
- - http://c2.com/cgi/wiki?AbcMetric
2713
+ References:
2714
+ - https://wiki.c2.com/?AbcMetric
2677
2715
  - https://en.wikipedia.org/wiki/ABC_Software_Metric
2678
2716
  Enabled: true
2679
2717
  VersionAdded: '0.27'
@@ -2792,7 +2830,7 @@ Migration/DepartmentName:
2792
2830
  #################### Naming ##############################
2793
2831
 
2794
2832
  Naming/AccessorMethodName:
2795
- Description: Check the naming of accessor methods for get_/set_.
2833
+ Description: Checks the naming of accessor methods for get_/set_.
2796
2834
  StyleGuide: '#accessor_mutator_method_names'
2797
2835
  Enabled: true
2798
2836
  VersionAdded: '0.50'
@@ -2996,6 +3034,7 @@ Naming/MethodName:
2996
3034
  StyleGuide: '#snake-case-symbols-methods-vars'
2997
3035
  Enabled: true
2998
3036
  VersionAdded: '0.50'
3037
+ VersionChanged: '1.75'
2999
3038
  EnforcedStyle: snake_case
3000
3039
  SupportedStyles:
3001
3040
  - snake_case
@@ -3007,6 +3046,10 @@ Naming/MethodName:
3007
3046
  # - '\A\s*onSelectionCleared\s*'
3008
3047
  #
3009
3048
  AllowedPatterns: []
3049
+ ForbiddenIdentifiers:
3050
+ - __id__
3051
+ - __send__
3052
+ ForbiddenPatterns: []
3010
3053
 
3011
3054
  Naming/MethodParameterName:
3012
3055
  Description: >-
@@ -3038,22 +3081,42 @@ Naming/MethodParameterName:
3038
3081
  # Forbidden names that will register an offense
3039
3082
  ForbiddenNames: []
3040
3083
 
3041
- Naming/PredicateName:
3042
- Description: 'Check the names of predicate methods.'
3084
+ Naming/PredicateMethod:
3085
+ Description: 'Checks that predicate methods end with `?` and non-predicate methods do not.'
3086
+ Enabled: pending
3087
+ VersionAdded: '1.76'
3088
+ VersionChanged: '1.78'
3089
+ # In `aggressive` mode, the cop will register an offense for predicate methods that
3090
+ # may return a non-boolean value.
3091
+ # In `conservative` mode, the cop will *not* register an offense for predicate methods
3092
+ # that may return a non-boolean value.
3093
+ Mode: conservative
3094
+ AllowedMethods:
3095
+ - call
3096
+ AllowedPatterns: []
3097
+ AllowBangMethods: false
3098
+ # Methods that are known to not return a boolean value, despite ending in `?`.
3099
+ WaywardPredicates:
3100
+ - nonzero?
3101
+
3102
+ Naming/PredicatePrefix:
3103
+ Description: 'Predicate method names should not be prefixed and end with a `?`.'
3043
3104
  StyleGuide: '#bool-methods-qmark'
3044
3105
  Enabled: true
3045
3106
  VersionAdded: '0.50'
3046
- VersionChanged: '0.77'
3107
+ VersionChanged: '1.75'
3047
3108
  # Predicate name prefixes.
3048
3109
  NamePrefix:
3049
3110
  - is_
3050
3111
  - has_
3051
3112
  - have_
3113
+ - does_
3052
3114
  # Predicate name prefixes that should be removed.
3053
3115
  ForbiddenPrefixes:
3054
3116
  - is_
3055
3117
  - has_
3056
3118
  - have_
3119
+ - does_
3057
3120
  # Predicate names which, despite having a forbidden prefix, or no `?`,
3058
3121
  # should still be accepted
3059
3122
  AllowedMethods:
@@ -3081,13 +3144,15 @@ Naming/VariableName:
3081
3144
  StyleGuide: '#snake-case-symbols-methods-vars'
3082
3145
  Enabled: true
3083
3146
  VersionAdded: '0.50'
3084
- VersionChanged: '1.8'
3147
+ VersionChanged: '1.73'
3085
3148
  EnforcedStyle: snake_case
3086
3149
  SupportedStyles:
3087
3150
  - snake_case
3088
3151
  - camelCase
3089
3152
  AllowedIdentifiers: []
3090
3153
  AllowedPatterns: []
3154
+ ForbiddenIdentifiers: []
3155
+ ForbiddenPatterns: []
3091
3156
 
3092
3157
  Naming/VariableNumber:
3093
3158
  Description: 'Use the configured style when numbering symbols, methods and variables.'
@@ -3103,6 +3168,8 @@ Naming/VariableNumber:
3103
3168
  CheckMethodNames: true
3104
3169
  CheckSymbols: true
3105
3170
  AllowedIdentifiers:
3171
+ - TLS1_1 # OpenSSL::SSL::TLS1_1_VERSION
3172
+ - TLS1_2 # OpenSSL::SSL::TLS1_2_VERSION
3106
3173
  - capture3 # Open3.capture3
3107
3174
  - iso8601 # Time#iso8601
3108
3175
  - rfc1123_date # CGI.rfc1123_date
@@ -3138,7 +3205,9 @@ Security/JSONLoad:
3138
3205
  Description: >-
3139
3206
  Prefer usage of `JSON.parse` over `JSON.load` due to potential
3140
3207
  security issues. See reference for more information.
3141
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3208
+ References:
3209
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3210
+ - 'https://bugs.ruby-lang.org/issues/19528'
3142
3211
  Enabled: true
3143
3212
  VersionAdded: '0.43'
3144
3213
  VersionChanged: '1.22'
@@ -3150,7 +3219,8 @@ Security/MarshalLoad:
3150
3219
  Description: >-
3151
3220
  Avoid using of `Marshal.load` or `Marshal.restore` due to potential
3152
3221
  security issues. See reference for more information.
3153
- Reference: 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3222
+ References:
3223
+ - 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3154
3224
  Enabled: true
3155
3225
  VersionAdded: '0.47'
3156
3226
 
@@ -3165,7 +3235,8 @@ Security/YAMLLoad:
3165
3235
  Description: >-
3166
3236
  Prefer usage of `YAML.safe_load` over `YAML.load` due to potential
3167
3237
  security issues. See reference for more information.
3168
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3238
+ References:
3239
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3169
3240
  Enabled: true
3170
3241
  VersionAdded: '0.47'
3171
3242
  SafeAutoCorrect: false
@@ -3259,7 +3330,8 @@ Style/ArrayCoercion:
3259
3330
 
3260
3331
  Style/ArrayFirstLast:
3261
3332
  Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
3262
- Reference: '#first-and-last'
3333
+ References:
3334
+ - '#first-and-last'
3263
3335
  Enabled: false
3264
3336
  VersionAdded: '1.58'
3265
3337
  Safe: false
@@ -3270,6 +3342,12 @@ Style/ArrayIntersect:
3270
3342
  Safe: false
3271
3343
  VersionAdded: '1.40'
3272
3344
 
3345
+ Style/ArrayIntersectWithSingleElement:
3346
+ Description: 'Use `include?(element)` instead of `intersect?([element])`.'
3347
+ Enabled: 'pending'
3348
+ Safe: false
3349
+ VersionAdded: '1.81'
3350
+
3273
3351
  Style/ArrayJoin:
3274
3352
  Description: 'Use Array#join instead of Array#*.'
3275
3353
  StyleGuide: '#array-join'
@@ -3498,6 +3576,7 @@ Style/ClassAndModuleChildren:
3498
3576
  SafeAutoCorrect: false
3499
3577
  Enabled: true
3500
3578
  VersionAdded: '0.19'
3579
+ VersionChanged: '1.74'
3501
3580
  #
3502
3581
  # Basically there are two different styles:
3503
3582
  #
@@ -3513,7 +3592,21 @@ Style/ClassAndModuleChildren:
3513
3592
  #
3514
3593
  # The compact style is only forced, for classes or modules with one child.
3515
3594
  EnforcedStyle: nested
3516
- SupportedStyles:
3595
+ SupportedStyles: &supported_styles
3596
+ - nested
3597
+ - compact
3598
+ # Configure classes separately, if desired. If not set, or set to `nil`,
3599
+ # the `EnforcedStyle` value will be used.
3600
+ EnforcedStyleForClasses: ~
3601
+ SupportedStylesForClasses:
3602
+ - ~
3603
+ - nested
3604
+ - compact
3605
+ # Configure modules separately, if desired. If not set, or set to `nil`,
3606
+ # the `EnforcedStyle` value will be used.
3607
+ EnforcedStyleForModules: ~
3608
+ SupportedStylesForModules:
3609
+ - ~
3517
3610
  - nested
3518
3611
  - compact
3519
3612
 
@@ -3599,6 +3692,13 @@ Style/CollectionMethods:
3599
3692
  - inject
3600
3693
  - reduce
3601
3694
 
3695
+ Style/CollectionQuerying:
3696
+ Description: 'Prefer `Enumerable` predicate methods over expressions with `count`.'
3697
+ StyleGuide: '#collection-querying'
3698
+ Enabled: pending
3699
+ VersionAdded: '1.77'
3700
+ Safe: false
3701
+
3602
3702
  Style/ColonMethodCall:
3603
3703
  Description: 'Do not use :: for method call.'
3604
3704
  StyleGuide: '#double-colons'
@@ -3666,6 +3766,14 @@ Style/CommentedKeyword:
3666
3766
  VersionAdded: '0.51'
3667
3767
  VersionChanged: '1.19'
3668
3768
 
3769
+ Style/ComparableBetween:
3770
+ Description: 'Enforces the use of `Comparable#between?` instead of logical comparison.'
3771
+ Enabled: pending
3772
+ Safe: false
3773
+ VersionAdded: '1.74'
3774
+ VersionChanged: '1.75'
3775
+ StyleGuide: '#ranges-or-between'
3776
+
3669
3777
  Style/ComparableClamp:
3670
3778
  Description: 'Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum.'
3671
3779
  Enabled: pending
@@ -3898,6 +4006,16 @@ Style/EmptyMethod:
3898
4006
  - compact
3899
4007
  - expanded
3900
4008
 
4009
+ Style/EmptyStringInsideInterpolation:
4010
+ Description: 'Checks for empty strings being assigned inside string interpolation.'
4011
+ StyleGuide: '#empty-strings-in-interpolation'
4012
+ Enabled: pending
4013
+ EnforcedStyle: trailing_conditional
4014
+ SupportedStyles:
4015
+ - trailing_conditional
4016
+ - ternary
4017
+ VersionAdded: '1.76'
4018
+
3901
4019
  Style/Encoding:
3902
4020
  Description: 'Use UTF-8 as the source file encoding.'
3903
4021
  StyleGuide: '#utf-8'
@@ -3922,6 +4040,8 @@ Style/EndlessMethod:
3922
4040
  - allow_single_line
3923
4041
  - allow_always
3924
4042
  - disallow
4043
+ - require_single_line
4044
+ - require_always
3925
4045
 
3926
4046
  Style/EnvHome:
3927
4047
  Description: "Checks for consistent usage of `ENV['HOME']`."
@@ -3974,12 +4094,15 @@ Style/ExponentialNotation:
3974
4094
  Style/FetchEnvVar:
3975
4095
  Description: >-
3976
4096
  Suggests `ENV.fetch` for the replacement of `ENV[]`.
3977
- Reference:
4097
+ References:
3978
4098
  - https://rubystyle.guide/#hash-fetch-defaults
3979
4099
  Enabled: pending
3980
4100
  VersionAdded: '1.28'
3981
4101
  # Environment variables to be excluded from the inspection.
3982
4102
  AllowedVars: []
4103
+ # When `true`, autocorrects `ENV["key"]` to `ENV.fetch("key", nil)`.
4104
+ # When `false`, autocorrects `ENV["key"]` to `ENV.fetch("key")`.
4105
+ DefaultToNil: true
3983
4106
 
3984
4107
  Style/FileEmpty:
3985
4108
  Description: >-
@@ -4015,7 +4138,8 @@ Style/FileWrite:
4015
4138
  Style/FloatDivision:
4016
4139
  Description: 'For performing float division, coerce one side only.'
4017
4140
  StyleGuide: '#float-division'
4018
- Reference: 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4141
+ References:
4142
+ - 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4019
4143
  Enabled: true
4020
4144
  VersionAdded: '0.72'
4021
4145
  VersionChanged: '1.9'
@@ -4066,8 +4190,14 @@ Style/FormatStringToken:
4066
4190
  # style token in a format string to be allowed when enforced style is not
4067
4191
  # `unannotated`.
4068
4192
  MaxUnannotatedPlaceholdersAllowed: 1
4193
+ # The mode the cop operates in. Two values are allowed:
4194
+ # * aggressive (default): all strings are considered
4195
+ # * conservative:
4196
+ # only register offenses for strings given to `printf`, `sprintf`,
4197
+ # format` and `%` methods. Other strings are not considered.
4198
+ Mode: aggressive
4069
4199
  VersionAdded: '0.49'
4070
- VersionChanged: '1.0'
4200
+ VersionChanged: '1.74'
4071
4201
  AllowedMethods: []
4072
4202
  AllowedPatterns: []
4073
4203
 
@@ -4106,14 +4236,15 @@ Style/GlobalStdStream:
4106
4236
  Style/GlobalVars:
4107
4237
  Description: 'Do not introduce global variables.'
4108
4238
  StyleGuide: '#instance-vars'
4109
- Reference: 'https://www.zenspider.com/ruby/quickref.html'
4239
+ References:
4240
+ - 'https://www.zenspider.com/ruby/quickref.html'
4110
4241
  Enabled: true
4111
4242
  VersionAdded: '0.13'
4112
4243
  # Built-in global variables are allowed by default.
4113
4244
  AllowedVariables: []
4114
4245
 
4115
4246
  Style/GuardClause:
4116
- Description: 'Check for conditionals that can be replaced with guard clauses.'
4247
+ Description: 'Checks for conditionals that can be replaced with guard clauses.'
4117
4248
  StyleGuide: '#no-nested-conditionals'
4118
4249
  Enabled: true
4119
4250
  VersionAdded: '0.20'
@@ -4163,6 +4294,12 @@ Style/HashExcept:
4163
4294
  VersionAdded: '1.7'
4164
4295
  VersionChanged: '1.39'
4165
4296
 
4297
+ Style/HashFetchChain:
4298
+ Description: 'Use `Hash#dig` instead of chained `fetch` calls.'
4299
+ Enabled: pending
4300
+ Safe: false
4301
+ VersionAdded: '1.75'
4302
+
4166
4303
  Style/HashLikeCase:
4167
4304
  Description: >-
4168
4305
  Checks for places where `case-when` represents a simple 1:1
@@ -4369,10 +4506,22 @@ Style/IpAddresses:
4369
4506
  - '**/*.gemspec'
4370
4507
 
4371
4508
  Style/ItAssignment:
4372
- Description: 'Checks for assignment to `it` inside a block.'
4509
+ Description: 'Checks for local variables and method parameters named `it`.'
4373
4510
  Enabled: pending
4374
4511
  VersionAdded: '1.70'
4375
4512
 
4513
+ Style/ItBlockParameter:
4514
+ Description: 'Checks for blocks with one argument where `it` block parameter can be used.'
4515
+ Enabled: pending
4516
+ EnforcedStyle: allow_single_line
4517
+ SupportedStyles:
4518
+ - allow_single_line
4519
+ - only_numbered_parameters
4520
+ - always
4521
+ - disallow
4522
+ VersionAdded: '1.75'
4523
+ VersionChanged: '1.76'
4524
+
4376
4525
  Style/KeywordArgumentsMerging:
4377
4526
  Description: >-
4378
4527
  When passing an existing hash as keyword arguments, provide additional arguments
@@ -4404,8 +4553,9 @@ Style/LambdaCall:
4404
4553
  Description: 'Use lambda.call(...) instead of lambda.(...).'
4405
4554
  StyleGuide: '#proc-call'
4406
4555
  Enabled: true
4556
+ AutoCorrect: contextual
4407
4557
  VersionAdded: '0.13'
4408
- VersionChanged: '0.14'
4558
+ VersionChanged: '1.81'
4409
4559
  EnforcedStyle: call
4410
4560
  SupportedStyles:
4411
4561
  - call
@@ -4761,7 +4911,7 @@ Style/Next:
4761
4911
  StyleGuide: '#no-nested-conditionals'
4762
4912
  Enabled: true
4763
4913
  VersionAdded: '0.22'
4764
- VersionChanged: '0.35'
4914
+ VersionChanged: '1.75'
4765
4915
  # With `always` all conditions at the end of an iteration needs to be
4766
4916
  # replaced by next - with `skip_modifier_ifs` the modifier if like this one
4767
4917
  # are ignored: [1, 2].each { |a| return 'yes' if a == 1 }
@@ -4769,6 +4919,7 @@ Style/Next:
4769
4919
  # `MinBodyLength` defines the number of lines of the a body of an `if` or `unless`
4770
4920
  # needs to have to trigger this cop
4771
4921
  MinBodyLength: 3
4922
+ AllowConsecutiveConditionals: false
4772
4923
  SupportedStyles:
4773
4924
  - skip_modifier_ifs
4774
4925
  - always
@@ -4900,8 +5051,8 @@ Style/OpenStructUse:
4900
5051
  Description: >-
4901
5052
  Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4902
5053
  version compatibility, and potential security issues.
4903
- Reference:
4904
- - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
5054
+ References:
5055
+ - https://docs.ruby-lang.org/en/3.0/OpenStruct.html#class-OpenStruct-label-Caveats
4905
5056
 
4906
5057
  Enabled: pending
4907
5058
  Safe: false
@@ -5057,7 +5208,7 @@ Style/RandomWithOffset:
5057
5208
  VersionAdded: '0.52'
5058
5209
 
5059
5210
  Style/RedundantArgument:
5060
- Description: 'Check for a redundant argument passed to certain methods.'
5211
+ Description: 'Checks for a redundant argument passed to certain methods.'
5061
5212
  Enabled: pending
5062
5213
  Safe: false
5063
5214
  VersionAdded: '1.4'
@@ -5083,6 +5234,12 @@ Style/RedundantArrayConstructor:
5083
5234
  Enabled: pending
5084
5235
  VersionAdded: '1.52'
5085
5236
 
5237
+ Style/RedundantArrayFlatten:
5238
+ Description: 'Checks for redundant calls of `Array#flatten`.'
5239
+ Enabled: pending
5240
+ Safe: false
5241
+ VersionAdded: '1.76'
5242
+
5086
5243
  Style/RedundantAssignment:
5087
5244
  Description: 'Checks for redundant assignment before returning.'
5088
5245
  Enabled: true
@@ -5104,6 +5261,9 @@ Style/RedundantCondition:
5104
5261
  Description: 'Checks for unnecessary conditional expressions.'
5105
5262
  Enabled: true
5106
5263
  VersionAdded: '0.76'
5264
+ VersionChanged: '1.73'
5265
+ AllowedMethods:
5266
+ - nonzero?
5107
5267
 
5108
5268
  Style/RedundantConditional:
5109
5269
  Description: "Don't return true/false from a conditional."
@@ -5142,7 +5302,8 @@ Style/RedundantFetchBlock:
5142
5302
  Description: >-
5143
5303
  Use `fetch(key, value)` instead of `fetch(key) { value }`
5144
5304
  when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.
5145
- Reference: 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5305
+ References:
5306
+ - 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5146
5307
  Enabled: true
5147
5308
  Safe: false
5148
5309
  # If enabled, this cop will autocorrect usages of
@@ -5171,7 +5332,9 @@ Style/RedundantFilterChain:
5171
5332
  Style/RedundantFormat:
5172
5333
  Description: 'Checks for usages of `Kernel#format` or `Kernel#sprintf` with only a single argument.'
5173
5334
  Enabled: pending
5335
+ SafeAutoCorrect: false
5174
5336
  VersionAdded: '1.72'
5337
+ VersionChanged: '1.72'
5175
5338
 
5176
5339
  Style/RedundantFreeze:
5177
5340
  Description: "Checks usages of Object#freeze on immutable objects."
@@ -5206,7 +5369,7 @@ Style/RedundantInterpolationUnfreeze:
5206
5369
  VersionAdded: '1.66'
5207
5370
 
5208
5371
  Style/RedundantLineContinuation:
5209
- Description: 'Check for redundant line continuation.'
5372
+ Description: 'Checks for redundant line continuation.'
5210
5373
  Enabled: pending
5211
5374
  VersionAdded: '1.49'
5212
5375
 
@@ -5382,7 +5545,8 @@ Style/Sample:
5382
5545
  Description: >-
5383
5546
  Use `sample` instead of `shuffle.first`,
5384
5547
  `shuffle.last`, and `shuffle[Integer]`.
5385
- Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5548
+ References:
5549
+ - 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5386
5550
  Enabled: true
5387
5551
  VersionAdded: '0.30'
5388
5552
 
@@ -5499,7 +5663,7 @@ Style/SpecialGlobalVars:
5499
5663
  - use_builtin_english_names
5500
5664
 
5501
5665
  Style/StabbyLambdaParentheses:
5502
- Description: 'Check for the usage of parentheses around stabby lambda arguments.'
5666
+ Description: 'Checks for the usage of parentheses around stabby lambda arguments.'
5503
5667
  StyleGuide: '#stabby-lambda-with-args'
5504
5668
  Enabled: true
5505
5669
  VersionAdded: '0.35'
@@ -5688,10 +5852,14 @@ Style/TrailingCommaInArguments:
5688
5852
  # parenthesized method calls where each argument is on its own line.
5689
5853
  # If `consistent_comma`, the cop requires a comma after the last argument,
5690
5854
  # for all parenthesized method calls with arguments.
5855
+ # If `diff_comma`, the cop requires a comma after the last argument, but only
5856
+ # when that argument is followed by an immediate newline, even if
5857
+ # there is an inline comment.
5691
5858
  EnforcedStyleForMultiline: no_comma
5692
5859
  SupportedStylesForMultiline:
5693
5860
  - comma
5694
5861
  - consistent_comma
5862
+ - diff_comma
5695
5863
  - no_comma
5696
5864
 
5697
5865
  Style/TrailingCommaInArrayLiteral:
@@ -5699,14 +5867,17 @@ Style/TrailingCommaInArrayLiteral:
5699
5867
  StyleGuide: '#no-trailing-array-commas'
5700
5868
  Enabled: true
5701
5869
  VersionAdded: '0.53'
5702
- # If `comma`, the cop requires a comma after the last item in an array,
5703
- # but only when each item is on its own line.
5704
- # If `consistent_comma`, the cop requires a comma after the last item of all
5705
- # non-empty, multiline array literals.
5870
+ # If `comma`, the cop requires a comma after the last item in an array, but only when each item is
5871
+ # on its own line.
5872
+ # If `consistent_comma`, the cop requires a comma after the last item of all non-empty, multiline
5873
+ # array literals.
5874
+ # If `diff_comma`, the cop requires a comma after the last item of all non-empty, multiline array
5875
+ # literals, but only when that last item immediately precedes a newline.
5706
5876
  EnforcedStyleForMultiline: no_comma
5707
5877
  SupportedStylesForMultiline:
5708
5878
  - comma
5709
5879
  - consistent_comma
5880
+ - diff_comma
5710
5881
  - no_comma
5711
5882
 
5712
5883
  Style/TrailingCommaInBlockArgs:
@@ -5718,14 +5889,17 @@ Style/TrailingCommaInBlockArgs:
5718
5889
  Style/TrailingCommaInHashLiteral:
5719
5890
  Description: 'Checks for trailing comma in hash literals.'
5720
5891
  Enabled: true
5721
- # If `comma`, the cop requires a comma after the last item in a hash,
5722
- # but only when each item is on its own line.
5723
- # If `consistent_comma`, the cop requires a comma after the last item of all
5724
- # non-empty, multiline hash literals.
5892
+ # If `comma`, the cop requires a comma after the last item in a hash, but only when each item is
5893
+ # on its own line.
5894
+ # If `consistent_comma`, the cop requires a comma after the last item of all non-empty, multiline
5895
+ # hash literals.
5896
+ # If `diff_comma`, the cop requires a comma after the last item of all non-empty, multiline hash
5897
+ # literals, but only when that last item immediately precedes a newline.
5725
5898
  EnforcedStyleForMultiline: no_comma
5726
5899
  SupportedStylesForMultiline:
5727
5900
  - comma
5728
5901
  - consistent_comma
5902
+ - diff_comma
5729
5903
  - no_comma
5730
5904
  VersionAdded: '0.53'
5731
5905
 
@@ -5871,7 +6045,8 @@ Style/YAMLFileRead:
5871
6045
 
5872
6046
  Style/YodaCondition:
5873
6047
  Description: 'Forbid or enforce yoda conditions.'
5874
- Reference: 'https://en.wikipedia.org/wiki/Yoda_conditions'
6048
+ References:
6049
+ - 'https://en.wikipedia.org/wiki/Yoda_conditions'
5875
6050
  Enabled: true
5876
6051
  EnforcedStyle: forbid_for_all_comparison_operators
5877
6052
  SupportedStyles: