rubocop 1.75.1 → 1.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -14
  3. data/config/default.yml +103 -25
  4. data/config/obsoletion.yml +6 -3
  5. data/lib/rubocop/config_validator.rb +6 -6
  6. data/lib/rubocop/cop/autocorrect_logic.rb +18 -10
  7. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  8. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
  9. data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
  10. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
  11. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  12. data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
  13. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  14. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
  15. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +2 -0
  16. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
  17. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  18. data/lib/rubocop/cop/layout/class_structure.rb +35 -0
  19. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  20. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  21. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  22. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
  23. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -3
  24. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  25. data/lib/rubocop/cop/layout/hash_alignment.rb +2 -2
  26. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  27. data/lib/rubocop/cop/layout/line_length.rb +26 -5
  28. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  29. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -4
  30. data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
  31. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
  32. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +12 -3
  33. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  34. data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
  35. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  36. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  37. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  38. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  39. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  40. data/lib/rubocop/cop/lint/duplicate_methods.rb +86 -5
  41. data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
  42. data/lib/rubocop/cop/lint/float_comparison.rb +31 -4
  43. data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
  44. data/lib/rubocop/cop/lint/literal_as_condition.rb +31 -25
  45. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
  46. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  47. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  48. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  49. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  50. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +7 -4
  51. data/lib/rubocop/cop/lint/return_in_void_context.rb +7 -2
  52. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
  53. data/lib/rubocop/cop/lint/self_assignment.rb +25 -0
  54. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -0
  55. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  56. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
  57. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  58. data/lib/rubocop/cop/lint/useless_access_modifier.rb +29 -4
  59. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  60. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
  61. data/lib/rubocop/cop/lint/useless_or.rb +98 -0
  62. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  63. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
  64. data/lib/rubocop/cop/lint/void.rb +2 -2
  65. data/lib/rubocop/cop/message_annotator.rb +7 -3
  66. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  67. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  68. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  69. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +1 -1
  70. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  71. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  72. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -2
  73. data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
  74. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  75. data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
  76. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  77. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  78. data/lib/rubocop/cop/mixin/trailing_comma.rb +9 -5
  79. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  80. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  81. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  82. data/lib/rubocop/cop/naming/predicate_method.rb +281 -0
  83. data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
  84. data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
  85. data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -5
  86. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  87. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -3
  88. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
  89. data/lib/rubocop/cop/style/collection_querying.rb +167 -0
  90. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  91. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  92. data/lib/rubocop/cop/style/comparable_between.rb +5 -2
  93. data/lib/rubocop/cop/style/conditional_assignment.rb +18 -4
  94. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  95. data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
  96. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  97. data/lib/rubocop/cop/style/empty_literal.rb +4 -0
  98. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
  99. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  100. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  101. data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
  102. data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
  103. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  104. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  105. data/lib/rubocop/cop/style/hash_conversion.rb +12 -3
  106. data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
  107. data/lib/rubocop/cop/style/hash_syntax.rb +3 -0
  108. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  109. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  110. data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
  111. data/lib/rubocop/cop/style/if_unless_modifier.rb +33 -6
  112. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
  113. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  114. data/lib/rubocop/cop/style/it_block_parameter.rb +33 -14
  115. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  116. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  117. data/lib/rubocop/cop/style/map_into_array.rb +3 -1
  118. data/lib/rubocop/cop/style/map_to_hash.rb +11 -0
  119. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -3
  120. data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
  121. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  122. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  123. data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
  124. data/lib/rubocop/cop/style/redundant_condition.rb +13 -1
  125. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
  126. data/lib/rubocop/cop/style/redundant_format.rb +6 -1
  127. data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
  128. data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
  129. data/lib/rubocop/cop/style/redundant_parentheses.rb +41 -3
  130. data/lib/rubocop/cop/style/redundant_self.rb +8 -5
  131. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  132. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  133. data/lib/rubocop/cop/style/safe_navigation.rb +42 -14
  134. data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -3
  135. data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
  136. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  137. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  138. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  139. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
  140. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  141. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  142. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  143. data/lib/rubocop/cop/team.rb +1 -1
  144. data/lib/rubocop/cop/util.rb +1 -1
  145. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  146. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  147. data/lib/rubocop/cops_documentation_generator.rb +6 -2
  148. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
  149. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  150. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  151. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
  152. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  153. data/lib/rubocop/lsp/diagnostic.rb +4 -4
  154. data/lib/rubocop/magic_comment.rb +8 -0
  155. data/lib/rubocop/rspec/cop_helper.rb +2 -2
  156. data/lib/rubocop/rspec/expect_offense.rb +9 -3
  157. data/lib/rubocop/rspec/shared_contexts.rb +1 -2
  158. data/lib/rubocop/server/cache.rb +13 -10
  159. data/lib/rubocop/target_finder.rb +6 -2
  160. data/lib/rubocop/version.rb +1 -1
  161. data/lib/rubocop.rb +8 -1
  162. data/lib/ruby_lsp/rubocop/addon.rb +2 -2
  163. metadata +14 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a064330786019e0efee6b496e761b05bea0286f0afdcbb4fffad2f07433aef9d
4
- data.tar.gz: eb1ee00d5fe060ea49203635df3c7457df6f416de93c9801a687386aa02f4768
3
+ metadata.gz: 871a632c96e6a5c92e57b651037eaf7efd7412e64ac77440d5275027ef791d4e
4
+ data.tar.gz: f375ec6479b1f90193cd39e863411707d60cd071e170888005339d89a19ea65b
5
5
  SHA512:
6
- metadata.gz: 336c6e38cc6162a00ca4c9780dcc71fb4b03a785af0eb6abb6c30baf2e1c8512af12e921a2036564102290324e418278cb83ceb06d7a1ec44ddf314923275f89
7
- data.tar.gz: cbe9d5ab5685dbab70de2b281ecc807494631a294273260d87315d6875b753d9c2b60f6d7c14379eaf5b384894a4400c747ef91a57323c418c66a51076b33f06
6
+ metadata.gz: f8dac3eb5cb12741c110c8726ec64595cefb89700527144cc590d7febb676164e3902dff171594278f7895d1c3df336dea3e14f869d285a0c7080b1467bd6362
7
+ data.tar.gz: 4aadc7a712774810e1815f4f31bea43fc6d9e121a547621f57894c7df848a6459dfc962af0fb725f4fef6e2017b6a499c203cc05a4d2879d0e50aceaee156b95
data/README.md CHANGED
@@ -36,10 +36,11 @@ Working on RuboCop is often fun, but it also requires a great deal of time and e
36
36
  **RuboCop**'s installation is pretty standard:
37
37
 
38
38
  ```sh
39
- $ gem install rubocop
39
+ gem install rubocop
40
40
  ```
41
41
 
42
- If you'd rather install RuboCop using `bundler`, add a line for it in your `Gemfile` (but set the `require` option to `false`, as it is a standalone tool):
42
+ If you'd rather install RuboCop using `bundler`, add a line for it in your
43
+ `Gemfile` (but set the `require` option to `false`, as it is a standalone tool):
43
44
 
44
45
  ```rb
45
46
  gem 'rubocop', require: false
@@ -52,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
52
53
  in your `Gemfile`:
53
54
 
54
55
  ```rb
55
- gem 'rubocop', '~> 1.75', require: false
56
+ gem 'rubocop', '~> 1.77', require: false
56
57
  ```
57
58
 
58
59
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -61,12 +62,15 @@ See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) fo
61
62
 
62
63
  Just type `rubocop` in a Ruby project's folder and watch the magic happen.
63
64
 
64
- ```
65
- $ cd my/cool/ruby/project
66
- $ rubocop
65
+ ```sh
66
+ cd my/cool/ruby/project
67
+ rubocop
67
68
  ```
68
69
 
69
- You can also use this magic in your favorite editor with RuboCop's [built-in LSP server](https://docs.rubocop.org/rubocop/usage/lsp.html).
70
+ > [!TIP]
71
+ >
72
+ > You can also use this magic in your favorite editor with RuboCop's
73
+ > [built-in LSP server](https://docs.rubocop.org/rubocop/usage/lsp.html).
70
74
 
71
75
  ## Documentation
72
76
 
@@ -79,7 +83,7 @@ RuboCop officially supports the following runtime Ruby implementations:
79
83
  * MRI 2.7+
80
84
  * JRuby 9.4+
81
85
 
82
- Targets Ruby 2.0+ code analysis.
86
+ It targets Ruby 2.0+ for code analysis.
83
87
 
84
88
  See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
85
89
 
@@ -91,7 +95,6 @@ If you use RuboCop in your project, you can include one of these badges in your
91
95
 
92
96
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
93
97
 
94
-
95
98
  Here are the Markdown snippets for the two badges:
96
99
 
97
100
  ``` markdown
@@ -109,7 +112,7 @@ Here's a list of RuboCop's core developers:
109
112
  * [Yuji Nakayama](https://github.com/yujinakayama) (retired)
110
113
  * [Evgeni Dzhelyov](https://github.com/edzhelyov) (retired)
111
114
  * [Ted Johansson](https://github.com/drenmi)
112
- * [Masataka Kuwabara](https://github.com/pocke)
115
+ * [Masataka Kuwabara](https://github.com/pocke) (retired)
113
116
  * [Koichi Ito](https://github.com/koic)
114
117
  * [Maxim Krizhanovski](https://github.com/darhazer)
115
118
  * [Benjamin Quorning](https://github.com/bquorning)
@@ -157,8 +160,8 @@ wide array of funding channels to account for your preferences
157
160
  currently [Open Collective](https://opencollective.com/rubocop) is our
158
161
  preferred funding platform).
159
162
 
160
- **If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company
161
- to become a RuboCop sponsor.**
163
+ **If you're working in a company that's making significant use of RuboCop we'd
164
+ appreciate it if you suggest to your company to become a RuboCop sponsor.**
162
165
 
163
166
  You can support the development of RuboCop via
164
167
  [GitHub Sponsors](https://github.com/sponsors/bbatsov),
@@ -168,8 +171,11 @@ You can support the development of RuboCop via
168
171
  and [Tidelift](https://tidelift.com/subscription/pkg/rubygems-rubocop?utm_source=rubygems-rubocop&utm_medium=referral&utm_campaign=readme)
169
172
  .
170
173
 
171
- **Note:** If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend
172
- the use of Tidelift, where you can get a support-like subscription instead.
174
+ > [!NOTE]
175
+ >
176
+ > If doing a sponsorship in the form of donation is problematic for your company
177
+ > from an accounting standpoint, we'd recommend the use of Tidelift, where you
178
+ > can get a support-like subscription instead.
173
179
 
174
180
  ### Open Collective for Individuals
175
181
 
data/config/default.yml CHANGED
@@ -274,12 +274,20 @@ Bundler/OrderedGems:
274
274
  Gemspec/AddRuntimeDependency:
275
275
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
276
276
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
277
- Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
277
+ References:
278
+ - https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
278
279
  Enabled: pending
279
280
  VersionAdded: '1.65'
280
281
  Include:
281
282
  - '**/*.gemspec'
282
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
+
283
291
  Gemspec/DependencyVersion:
284
292
  Description: 'Requires or forbids specifying gem dependency versions.'
285
293
  Enabled: false
@@ -343,7 +351,7 @@ Gemspec/RequireMFA:
343
351
  Severity: warning
344
352
  VersionAdded: '1.23'
345
353
  VersionChanged: '1.40'
346
- Reference:
354
+ References:
347
355
  - https://guides.rubygems.org/mfa-requirement-opt-in/
348
356
  Include:
349
357
  - '**/*.gemspec'
@@ -604,7 +612,7 @@ Layout/EmptyLineAfterMultilineCondition:
604
612
  # This is disabled, because this style is not very common in practice.
605
613
  Enabled: false
606
614
  VersionAdded: '0.90'
607
- Reference:
615
+ References:
608
616
  - https://github.com/airbnb/ruby#multiline-if-newline
609
617
 
610
618
  Layout/EmptyLineBetweenDefs:
@@ -639,7 +647,7 @@ Layout/EmptyLinesAroundAccessModifier:
639
647
  SupportedStyles:
640
648
  - around
641
649
  - only_before
642
- Reference:
650
+ References:
643
651
  # A reference to `EnforcedStyle: only_before`.
644
652
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
645
653
 
@@ -996,7 +1004,7 @@ Layout/IndentationConsistency:
996
1004
  SupportedStyles:
997
1005
  - normal
998
1006
  - indented_internal_methods
999
- Reference:
1007
+ References:
1000
1008
  # A reference to `EnforcedStyle: indented_internal_methods`.
1001
1009
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
1002
1010
 
@@ -1094,6 +1102,7 @@ Layout/LineLength:
1094
1102
  # To make it possible to copy or click on URIs in the code, we allow lines
1095
1103
  # containing a URI to be longer than Max.
1096
1104
  AllowURI: true
1105
+ AllowQualifiedName: true
1097
1106
  URISchemes:
1098
1107
  - http
1099
1108
  - https
@@ -1922,7 +1931,7 @@ Lint/EmptyInterpolation:
1922
1931
  Enabled: true
1923
1932
  AutoCorrect: contextual
1924
1933
  VersionAdded: '0.20'
1925
- VersionChanged: '1.61'
1934
+ VersionChanged: '1.76'
1926
1935
 
1927
1936
  Lint/EmptyWhen:
1928
1937
  Description: 'Checks for `when` branches with empty bodies.'
@@ -2035,7 +2044,8 @@ Lint/InterpolationCheck:
2035
2044
 
2036
2045
  Lint/ItWithoutArgumentsInBlock:
2037
2046
  Description: 'Checks uses of `it` calls without arguments in block.'
2038
- Reference: 'https://bugs.ruby-lang.org/issues/18980'
2047
+ References:
2048
+ - 'https://bugs.ruby-lang.org/issues/18980'
2039
2049
  Enabled: pending
2040
2050
  VersionAdded: '1.59'
2041
2051
 
@@ -2398,6 +2408,7 @@ Lint/SelfAssignment:
2398
2408
  Description: 'Checks for self-assignments.'
2399
2409
  Enabled: true
2400
2410
  VersionAdded: '0.89'
2411
+ AllowRBSInlineAnnotation: false
2401
2412
 
2402
2413
  Lint/SendWithMixinArgument:
2403
2414
  Description: 'Checks for `send` method when using mixin.'
@@ -2421,8 +2432,9 @@ Lint/ShadowingOuterLocalVariable:
2421
2432
  Description: >-
2422
2433
  Do not use the same name as outer local variable
2423
2434
  for block arguments or block local variables.
2424
- Enabled: true
2435
+ Enabled: false
2425
2436
  VersionAdded: '0.9'
2437
+ VersionChanged: '1.76'
2426
2438
 
2427
2439
  Lint/SharedMutableDefault:
2428
2440
  Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
@@ -2610,6 +2622,13 @@ Lint/UselessConstantScoping:
2610
2622
  Enabled: pending
2611
2623
  VersionAdded: '1.72'
2612
2624
 
2625
+ Lint/UselessDefaultValueArgument:
2626
+ Description: 'Checks for usage of `fetch` or `Array.new` with default value argument and block.'
2627
+ Enabled: pending
2628
+ VersionAdded: '1.76'
2629
+ Safe: false
2630
+ AllowedReceivers: []
2631
+
2613
2632
  Lint/UselessDefined:
2614
2633
  Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2615
2634
  Enabled: pending
@@ -2634,6 +2653,11 @@ Lint/UselessNumericOperation:
2634
2653
  Enabled: pending
2635
2654
  VersionAdded: '1.66'
2636
2655
 
2656
+ Lint/UselessOr:
2657
+ Description: 'Checks for useless OR expressions.'
2658
+ Enabled: pending
2659
+ VersionAdded: '1.76'
2660
+
2637
2661
  Lint/UselessRescue:
2638
2662
  Description: 'Checks for useless `rescue`s.'
2639
2663
  Enabled: pending
@@ -2673,8 +2697,8 @@ Metrics/AbcSize:
2673
2697
  Description: >-
2674
2698
  A calculated magnitude based on number of assignments,
2675
2699
  branches, and conditions.
2676
- Reference:
2677
- - http://c2.com/cgi/wiki?AbcMetric
2700
+ References:
2701
+ - https://wiki.c2.com/?AbcMetric
2678
2702
  - https://en.wikipedia.org/wiki/ABC_Software_Metric
2679
2703
  Enabled: true
2680
2704
  VersionAdded: '0.27'
@@ -3044,8 +3068,23 @@ Naming/MethodParameterName:
3044
3068
  # Forbidden names that will register an offense
3045
3069
  ForbiddenNames: []
3046
3070
 
3047
- Naming/PredicateName:
3048
- Description: 'Check the names of predicate methods.'
3071
+ Naming/PredicateMethod:
3072
+ Description: 'Checks that predicate methods end with `?` and non-predicate methods do not.'
3073
+ Enabled: pending
3074
+ VersionAdded: '1.76'
3075
+ VersionChanged: '1.76'
3076
+ # In `aggressive` mode, the cop will register an offense for predicate methods that
3077
+ # may return a non-boolean value.
3078
+ # In `conservative` mode, the cop will *not* register an offense for predicate methods
3079
+ # that may return a non-boolean value.
3080
+ Mode: conservative
3081
+ AllowedMethods:
3082
+ - call
3083
+ AllowedPatterns: []
3084
+ AllowBangMethods: false
3085
+
3086
+ Naming/PredicatePrefix:
3087
+ Description: 'Predicate method names should not be prefixed and end with a `?`.'
3049
3088
  StyleGuide: '#bool-methods-qmark'
3050
3089
  Enabled: true
3051
3090
  VersionAdded: '0.50'
@@ -3150,7 +3189,8 @@ Security/JSONLoad:
3150
3189
  Description: >-
3151
3190
  Prefer usage of `JSON.parse` over `JSON.load` due to potential
3152
3191
  security issues. See reference for more information.
3153
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3192
+ References:
3193
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3154
3194
  Enabled: true
3155
3195
  VersionAdded: '0.43'
3156
3196
  VersionChanged: '1.22'
@@ -3162,7 +3202,8 @@ Security/MarshalLoad:
3162
3202
  Description: >-
3163
3203
  Avoid using of `Marshal.load` or `Marshal.restore` due to potential
3164
3204
  security issues. See reference for more information.
3165
- Reference: 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3205
+ References:
3206
+ - 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3166
3207
  Enabled: true
3167
3208
  VersionAdded: '0.47'
3168
3209
 
@@ -3177,7 +3218,8 @@ Security/YAMLLoad:
3177
3218
  Description: >-
3178
3219
  Prefer usage of `YAML.safe_load` over `YAML.load` due to potential
3179
3220
  security issues. See reference for more information.
3180
- Reference: 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3221
+ References:
3222
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3181
3223
  Enabled: true
3182
3224
  VersionAdded: '0.47'
3183
3225
  SafeAutoCorrect: false
@@ -3271,7 +3313,8 @@ Style/ArrayCoercion:
3271
3313
 
3272
3314
  Style/ArrayFirstLast:
3273
3315
  Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
3274
- Reference: '#first-and-last'
3316
+ References:
3317
+ - '#first-and-last'
3275
3318
  Enabled: false
3276
3319
  VersionAdded: '1.58'
3277
3320
  Safe: false
@@ -3626,6 +3669,13 @@ Style/CollectionMethods:
3626
3669
  - inject
3627
3670
  - reduce
3628
3671
 
3672
+ Style/CollectionQuerying:
3673
+ Description: 'Prefer `Enumerable` predicate methods over expressions with `count`.'
3674
+ StyleGuide: '#collection-querying'
3675
+ Enabled: pending
3676
+ VersionAdded: '1.77'
3677
+ Safe: false
3678
+
3629
3679
  Style/ColonMethodCall:
3630
3680
  Description: 'Do not use :: for method call.'
3631
3681
  StyleGuide: '#double-colons'
@@ -3696,7 +3746,9 @@ Style/CommentedKeyword:
3696
3746
  Style/ComparableBetween:
3697
3747
  Description: 'Enforces the use of `Comparable#between?` instead of logical comparison.'
3698
3748
  Enabled: pending
3749
+ Safe: false
3699
3750
  VersionAdded: '1.74'
3751
+ VersionChanged: '1.75'
3700
3752
  StyleGuide: '#ranges-or-between'
3701
3753
 
3702
3754
  Style/ComparableClamp:
@@ -3931,6 +3983,16 @@ Style/EmptyMethod:
3931
3983
  - compact
3932
3984
  - expanded
3933
3985
 
3986
+ Style/EmptyStringInsideInterpolation:
3987
+ Description: 'Checks for empty strings being assigned inside string interpolation.'
3988
+ StyleGuide: '#empty-strings-in-interpolation'
3989
+ Enabled: pending
3990
+ EnforcedStyle: trailing_conditional
3991
+ SupportedStyles:
3992
+ - trailing_conditional
3993
+ - ternary
3994
+ VersionAdded: '1.76'
3995
+
3934
3996
  Style/Encoding:
3935
3997
  Description: 'Use UTF-8 as the source file encoding.'
3936
3998
  StyleGuide: '#utf-8'
@@ -4009,12 +4071,15 @@ Style/ExponentialNotation:
4009
4071
  Style/FetchEnvVar:
4010
4072
  Description: >-
4011
4073
  Suggests `ENV.fetch` for the replacement of `ENV[]`.
4012
- Reference:
4074
+ References:
4013
4075
  - https://rubystyle.guide/#hash-fetch-defaults
4014
4076
  Enabled: pending
4015
4077
  VersionAdded: '1.28'
4016
4078
  # Environment variables to be excluded from the inspection.
4017
4079
  AllowedVars: []
4080
+ # When `true`, autocorrects `ENV["key"]` to `ENV.fetch("key", nil)`.
4081
+ # When `false`, autocorrects `ENV["key"]` to `ENV.fetch("key")`.
4082
+ DefaultToNil: true
4018
4083
 
4019
4084
  Style/FileEmpty:
4020
4085
  Description: >-
@@ -4050,7 +4115,8 @@ Style/FileWrite:
4050
4115
  Style/FloatDivision:
4051
4116
  Description: 'For performing float division, coerce one side only.'
4052
4117
  StyleGuide: '#float-division'
4053
- Reference: 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4118
+ References:
4119
+ - 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4054
4120
  Enabled: true
4055
4121
  VersionAdded: '0.72'
4056
4122
  VersionChanged: '1.9'
@@ -4147,7 +4213,8 @@ Style/GlobalStdStream:
4147
4213
  Style/GlobalVars:
4148
4214
  Description: 'Do not introduce global variables.'
4149
4215
  StyleGuide: '#instance-vars'
4150
- Reference: 'https://www.zenspider.com/ruby/quickref.html'
4216
+ References:
4217
+ - 'https://www.zenspider.com/ruby/quickref.html'
4151
4218
  Enabled: true
4152
4219
  VersionAdded: '0.13'
4153
4220
  # Built-in global variables are allowed by default.
@@ -4423,12 +4490,14 @@ Style/ItAssignment:
4423
4490
  Style/ItBlockParameter:
4424
4491
  Description: 'Checks for blocks with one argument where `it` block parameter can be used.'
4425
4492
  Enabled: pending
4426
- EnforcedStyle: only_numbered_parameters
4493
+ EnforcedStyle: allow_single_line
4427
4494
  SupportedStyles:
4495
+ - allow_single_line
4428
4496
  - only_numbered_parameters
4429
4497
  - always
4430
4498
  - disallow
4431
4499
  VersionAdded: '1.75'
4500
+ VersionChanged: '1.76'
4432
4501
 
4433
4502
  Style/KeywordArgumentsMerging:
4434
4503
  Description: >-
@@ -4958,8 +5027,8 @@ Style/OpenStructUse:
4958
5027
  Description: >-
4959
5028
  Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4960
5029
  version compatibility, and potential security issues.
4961
- Reference:
4962
- - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
5030
+ References:
5031
+ - https://docs.ruby-lang.org/en/3.0/OpenStruct.html#class-OpenStruct-label-Caveats
4963
5032
 
4964
5033
  Enabled: pending
4965
5034
  Safe: false
@@ -5141,6 +5210,12 @@ Style/RedundantArrayConstructor:
5141
5210
  Enabled: pending
5142
5211
  VersionAdded: '1.52'
5143
5212
 
5213
+ Style/RedundantArrayFlatten:
5214
+ Description: 'Checks for redundant calls of `Array#flatten`.'
5215
+ Enabled: pending
5216
+ Safe: false
5217
+ VersionAdded: '1.76'
5218
+
5144
5219
  Style/RedundantAssignment:
5145
5220
  Description: 'Checks for redundant assignment before returning.'
5146
5221
  Enabled: true
@@ -5203,7 +5278,8 @@ Style/RedundantFetchBlock:
5203
5278
  Description: >-
5204
5279
  Use `fetch(key, value)` instead of `fetch(key) { value }`
5205
5280
  when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.
5206
- Reference: 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5281
+ References:
5282
+ - 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5207
5283
  Enabled: true
5208
5284
  Safe: false
5209
5285
  # If enabled, this cop will autocorrect usages of
@@ -5445,7 +5521,8 @@ Style/Sample:
5445
5521
  Description: >-
5446
5522
  Use `sample` instead of `shuffle.first`,
5447
5523
  `shuffle.last`, and `shuffle[Integer]`.
5448
- Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5524
+ References:
5525
+ - 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5449
5526
  Enabled: true
5450
5527
  VersionAdded: '0.30'
5451
5528
 
@@ -5940,7 +6017,8 @@ Style/YAMLFileRead:
5940
6017
 
5941
6018
  Style/YodaCondition:
5942
6019
  Description: 'Forbid or enforce yoda conditions.'
5943
- Reference: 'https://en.wikipedia.org/wiki/Yoda_conditions'
6020
+ References:
6021
+ - 'https://en.wikipedia.org/wiki/Yoda_conditions'
5944
6022
  Enabled: true
5945
6023
  EnforcedStyle: forbid_for_all_comparison_operators
5946
6024
  SupportedStyles:
@@ -31,6 +31,9 @@ renamed:
31
31
  Lint/UnneededRequireStatement: Lint/RedundantRequireStatement
32
32
  Lint/UnneededSplatExpansion: Lint/RedundantSplatExpansion
33
33
  Metrics/LineLength: Layout/LineLength
34
+ Naming/PredicateName:
35
+ new_name: Naming/PredicatePrefix
36
+ severity: warning
34
37
  Naming/UncommunicativeBlockParamName: Naming/BlockParameterName
35
38
  Naming/UncommunicativeMethodParamName: Naming/MethodParameterName
36
39
  Style/AccessorMethodName: Naming/AccessorMethodName
@@ -44,7 +47,7 @@ renamed:
44
47
  Style/MethodName: Naming/MethodName
45
48
  Style/OpMethod: Naming/BinaryOperatorParameterName
46
49
  Style/PredicateName:
47
- new_name: Naming/PredicateName
50
+ new_name: Naming/PredicatePrefix
48
51
  severity: warning
49
52
  Style/SingleSpaceBeforeFirstArg: Layout/SpaceBeforeFirstArg
50
53
  Style/UnneededCapitalW: Style/RedundantCapitalW
@@ -179,10 +182,10 @@ changed_parameters:
179
182
  - cops: Naming/HeredocDelimiterNaming
180
183
  parameters: Blacklist
181
184
  alternative: ForbiddenDelimiters
182
- - cops: Naming/PredicateName
185
+ - cops: Naming/PredicatePrefix
183
186
  parameters: NamePrefixBlacklist
184
187
  alternative: ForbiddenPrefixes
185
- - cops: Naming/PredicateName
188
+ - cops: Naming/PredicatePrefix
186
189
  parameters: NameWhitelist
187
190
  alternative: AllowedMethods
188
191
  - cops:
@@ -9,16 +9,16 @@ module RuboCop
9
9
 
10
10
  # @api private
11
11
  COMMON_PARAMS = %w[Exclude Include Severity inherit_mode AutoCorrect StyleGuide Details
12
- Enabled Reference].freeze
12
+ Enabled Reference References].freeze
13
13
  # @api private
14
14
  INTERNAL_PARAMS = %w[Description StyleGuide
15
15
  VersionAdded VersionChanged VersionRemoved
16
- Reference Safe SafeAutoCorrect].freeze
16
+ Reference References Safe SafeAutoCorrect].freeze
17
17
  # @api private
18
18
  NEW_COPS_VALUES = %w[pending disable enable].freeze
19
19
 
20
20
  # @api private
21
- CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect].to_set.freeze
21
+ CONFIG_CHECK_KEYS = %w[Enabled Safe SafeAutoCorrect AutoCorrect References].to_set.freeze
22
22
  CONFIG_CHECK_DEPARTMENTS = %w[pending override_department].freeze
23
23
  CONFIG_CHECK_AUTOCORRECTS = %w[always contextual disabled].freeze
24
24
  private_constant :CONFIG_CHECK_KEYS, :CONFIG_CHECK_DEPARTMENTS
@@ -260,8 +260,7 @@ module RuboCop
260
260
  end
261
261
  end
262
262
 
263
- # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
264
- def check_cop_config_value(hash, parent = nil)
263
+ def check_cop_config_value(hash, parent = nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
265
264
  hash.each do |key, value|
266
265
  check_cop_config_value(value, key) if value.is_a?(Hash)
267
266
 
@@ -271,6 +270,8 @@ module RuboCop
271
270
  supposed_values = 'a boolean'
272
271
  elsif key == 'AutoCorrect' && !CONFIG_CHECK_AUTOCORRECTS.include?(value)
273
272
  supposed_values = '`always`, `contextual`, `disabled`, or a boolean'
273
+ elsif key == 'References'
274
+ supposed_values = 'an array of strings'
274
275
  else
275
276
  next
276
277
  end
@@ -278,7 +279,6 @@ module RuboCop
278
279
  raise ValidationError, param_error_message(parent, key, value, supposed_values)
279
280
  end
280
281
  end
281
- # rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
282
282
 
283
283
  # FIXME: Handling colors in exception messages like this is ugly.
284
284
  def param_error_message(parent, key, value, supposed_values)
@@ -50,7 +50,7 @@ module RuboCop
50
50
 
51
51
  def disable_offense(offense_range)
52
52
  unbreakable_range = multiline_ranges(offense_range)&.find do |range|
53
- range_overlaps_offense?(offense_range, range)
53
+ eol_comment_would_be_inside_literal?(offense_range, range)
54
54
  end
55
55
 
56
56
  if unbreakable_range
@@ -75,18 +75,22 @@ module RuboCop
75
75
  end
76
76
 
77
77
  def disable_offense_with_eol_or_surround_comment(range)
78
- eol_comment = " # rubocop:todo #{cop_name}"
79
- needed_line_length = (range.source_line + eol_comment).length
80
-
81
- if needed_line_length <= max_line_length
82
- disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
83
- else
78
+ if line_with_eol_comment_too_long?(range)
84
79
  disable_offense_before_and_after(range_by_lines(range))
80
+ else
81
+ disable_offense_at_end_of_line(range_of_first_line(range))
85
82
  end
86
83
  end
87
84
 
88
- def range_overlaps_offense?(offense_range, range)
89
- offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
85
+ def eol_comment_would_be_inside_literal?(offense_range, literal_range)
86
+ return true if line_with_eol_comment_too_long?(offense_range)
87
+
88
+ offense_line = offense_range.line
89
+ offense_line >= literal_range.first_line && offense_line < literal_range.last_line
90
+ end
91
+
92
+ def line_with_eol_comment_too_long?(range)
93
+ (range.source_line + eol_comment).length > max_line_length
90
94
  end
91
95
 
92
96
  def surrounding_heredoc?(node)
@@ -132,10 +136,14 @@ module RuboCop
132
136
  config.for_cop('Layout/LineLength')['Max'] || 120
133
137
  end
134
138
 
135
- def disable_offense_at_end_of_line(range, eol_comment)
139
+ def disable_offense_at_end_of_line(range)
136
140
  Corrector.new(range).insert_after(range, eol_comment)
137
141
  end
138
142
 
143
+ def eol_comment
144
+ " # rubocop:todo #{cop_name}"
145
+ end
146
+
139
147
  def disable_offense_before_and_after(range_by_lines)
140
148
  range_with_newline = range_by_lines.resize(range_by_lines.size + 1)
141
149
  leading_whitespace = range_by_lines.source_line[/^\s*/]
@@ -45,7 +45,7 @@ module RuboCop
45
45
 
46
46
  gem_declarations(processed_source.ast)
47
47
  .each_cons(2) do |previous, current|
48
- next unless consecutive_lines(previous, current)
48
+ next unless consecutive_lines?(previous, current)
49
49
  next unless case_insensitive_out_of_order?(gem_name(current), gem_name(previous))
50
50
 
51
51
  register_offense(previous, current)
@@ -10,8 +10,11 @@ module RuboCop
10
10
  COMMA_REGEXP = /(?<=\))\s*,/.freeze
11
11
 
12
12
  def correct(corrector, node)
13
- corrector.remove(node.loc.begin)
14
- corrector.remove(node.loc.end)
13
+ buffer = node.source_range.source_buffer
14
+ corrector.remove(range_with_surrounding_space(range: node.loc.begin, buffer: buffer,
15
+ side: :right, whitespace: true))
16
+ corrector.remove(range_with_surrounding_space(range: node.loc.end, buffer: buffer,
17
+ side: :left))
15
18
  handle_orphaned_comma(corrector, node)
16
19
 
17
20
  return unless ternary_condition?(node) && next_char_is_question_mark?(node)