rubocop 1.75.2 → 1.76.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -13
  3. data/config/default.yml +79 -23
  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/gemspec/duplicated_assignment.rb +50 -6
  9. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  10. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  11. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
  12. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
  13. data/lib/rubocop/cop/layout/class_structure.rb +35 -0
  14. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  15. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -2
  16. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  17. data/lib/rubocop/cop/layout/hash_alignment.rb +2 -2
  18. data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
  19. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  20. data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
  21. data/lib/rubocop/cop/layout/space_before_brackets.rb +6 -32
  22. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +5 -1
  23. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
  24. data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
  25. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  26. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  27. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  28. data/lib/rubocop/cop/lint/duplicate_methods.rb +84 -2
  29. data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
  30. data/lib/rubocop/cop/lint/float_comparison.rb +27 -0
  31. data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
  32. data/lib/rubocop/cop/lint/literal_as_condition.rb +31 -25
  33. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
  34. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -0
  35. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  36. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +87 -0
  37. data/lib/rubocop/cop/lint/useless_or.rb +98 -0
  38. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  39. data/lib/rubocop/cop/lint/void.rb +2 -2
  40. data/lib/rubocop/cop/message_annotator.rb +7 -3
  41. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  42. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
  43. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  44. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  45. data/lib/rubocop/cop/mixin/trailing_comma.rb +9 -5
  46. data/lib/rubocop/cop/naming/predicate_method.rb +216 -0
  47. data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +2 -2
  48. data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
  49. data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -5
  50. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -3
  51. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  52. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  53. data/lib/rubocop/cop/style/comparable_between.rb +5 -2
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +15 -6
  55. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  56. data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
  57. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
  58. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  59. data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
  60. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  61. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  62. data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
  63. data/lib/rubocop/cop/style/if_unless_modifier.rb +22 -4
  64. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
  65. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  66. data/lib/rubocop/cop/style/it_block_parameter.rb +33 -14
  67. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  68. data/lib/rubocop/cop/style/map_into_array.rb +3 -1
  69. data/lib/rubocop/cop/style/map_to_hash.rb +11 -0
  70. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -1
  71. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  72. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  73. data/lib/rubocop/cop/style/redundant_array_flatten.rb +48 -0
  74. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
  75. data/lib/rubocop/cop/style/redundant_format.rb +6 -1
  76. data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
  77. data/lib/rubocop/cop/style/redundant_parentheses.rb +31 -3
  78. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  79. data/lib/rubocop/cop/style/safe_navigation.rb +28 -10
  80. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
  81. data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
  82. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  83. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
  84. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  85. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  86. data/lib/rubocop/cop/team.rb +1 -1
  87. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  88. data/lib/rubocop/cops_documentation_generator.rb +6 -2
  89. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
  90. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  91. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  92. data/lib/rubocop/rspec/cop_helper.rb +2 -2
  93. data/lib/rubocop/rspec/shared_contexts.rb +1 -2
  94. data/lib/rubocop/target_finder.rb +5 -1
  95. data/lib/rubocop/version.rb +1 -1
  96. data/lib/rubocop.rb +6 -1
  97. metadata +12 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 707ab6b769b30dc2f2c34c7e879fde41cab6dd694820d8f071db17a1ef0ef48f
4
- data.tar.gz: abafc2d95cd2c358b4699211ce58e544852707630c55ec2950a3fd01899b8dd4
3
+ metadata.gz: 236bdf0fa5879274099388142e17b886fc852cdc1e762d50c74a31254c7c6136
4
+ data.tar.gz: 03011b196c686aa5ce1cc617d56c19041dbdc76ba237626316048be9e75dc62c
5
5
  SHA512:
6
- metadata.gz: 290274c929ba840ebf66f9e2978f5853e04732ef05bfaee7dd45ab445ae4cc41e7913bc6204ef1e11618ec9bfb8fe1c234bc6febbcb3e65e7c651f73f31936ba
7
- data.tar.gz: 56f21668db3004f7a6846319911b3c7fe37d71a1d0ee43c9eee0f032ba324fc4745693fc4996907efd81975b23e1926c65f8129182e1f57e1b4c2e910af32984
6
+ metadata.gz: 91eb23282705c816206704923efdea2cb45ad09677a5d72a8741a565d9ed96146ad688aa54c1dc5be7f6d83c6e4d099605bdd91cb941d0d2b1fb36ace05b02a8
7
+ data.tar.gz: 6ff783d52e62e4dda5cae1c78f8648ef8af4078c5f052134a23c9229018e33d29a21d3ecaa80bfdc74d382b73a1a666f67d9e1b3436b1dfb5745a96861cf92ec
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.76', 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
@@ -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,7 +274,8 @@ 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:
@@ -343,7 +344,7 @@ Gemspec/RequireMFA:
343
344
  Severity: warning
344
345
  VersionAdded: '1.23'
345
346
  VersionChanged: '1.40'
346
- Reference:
347
+ References:
347
348
  - https://guides.rubygems.org/mfa-requirement-opt-in/
348
349
  Include:
349
350
  - '**/*.gemspec'
@@ -604,7 +605,7 @@ Layout/EmptyLineAfterMultilineCondition:
604
605
  # This is disabled, because this style is not very common in practice.
605
606
  Enabled: false
606
607
  VersionAdded: '0.90'
607
- Reference:
608
+ References:
608
609
  - https://github.com/airbnb/ruby#multiline-if-newline
609
610
 
610
611
  Layout/EmptyLineBetweenDefs:
@@ -639,7 +640,7 @@ Layout/EmptyLinesAroundAccessModifier:
639
640
  SupportedStyles:
640
641
  - around
641
642
  - only_before
642
- Reference:
643
+ References:
643
644
  # A reference to `EnforcedStyle: only_before`.
644
645
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
645
646
 
@@ -996,7 +997,7 @@ Layout/IndentationConsistency:
996
997
  SupportedStyles:
997
998
  - normal
998
999
  - indented_internal_methods
999
- Reference:
1000
+ References:
1000
1001
  # A reference to `EnforcedStyle: indented_internal_methods`.
1001
1002
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
1002
1003
 
@@ -1922,7 +1923,7 @@ Lint/EmptyInterpolation:
1922
1923
  Enabled: true
1923
1924
  AutoCorrect: contextual
1924
1925
  VersionAdded: '0.20'
1925
- VersionChanged: '1.61'
1926
+ VersionChanged: '1.76'
1926
1927
 
1927
1928
  Lint/EmptyWhen:
1928
1929
  Description: 'Checks for `when` branches with empty bodies.'
@@ -2035,7 +2036,8 @@ Lint/InterpolationCheck:
2035
2036
 
2036
2037
  Lint/ItWithoutArgumentsInBlock:
2037
2038
  Description: 'Checks uses of `it` calls without arguments in block.'
2038
- Reference: 'https://bugs.ruby-lang.org/issues/18980'
2039
+ References:
2040
+ - 'https://bugs.ruby-lang.org/issues/18980'
2039
2041
  Enabled: pending
2040
2042
  VersionAdded: '1.59'
2041
2043
 
@@ -2421,8 +2423,9 @@ Lint/ShadowingOuterLocalVariable:
2421
2423
  Description: >-
2422
2424
  Do not use the same name as outer local variable
2423
2425
  for block arguments or block local variables.
2424
- Enabled: true
2426
+ Enabled: false
2425
2427
  VersionAdded: '0.9'
2428
+ VersionChanged: '1.76'
2426
2429
 
2427
2430
  Lint/SharedMutableDefault:
2428
2431
  Description: 'Checks for mutable literals used as default arguments during Hash initialization.'
@@ -2610,6 +2613,13 @@ Lint/UselessConstantScoping:
2610
2613
  Enabled: pending
2611
2614
  VersionAdded: '1.72'
2612
2615
 
2616
+ Lint/UselessDefaultValueArgument:
2617
+ Description: 'Checks for usage of `fetch` or `Array.new` with default value argument and block.'
2618
+ Enabled: pending
2619
+ VersionAdded: '1.76'
2620
+ Safe: false
2621
+ AllowedReceivers: []
2622
+
2613
2623
  Lint/UselessDefined:
2614
2624
  Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
2615
2625
  Enabled: pending
@@ -2634,6 +2644,11 @@ Lint/UselessNumericOperation:
2634
2644
  Enabled: pending
2635
2645
  VersionAdded: '1.66'
2636
2646
 
2647
+ Lint/UselessOr:
2648
+ Description: 'Checks for useless OR expressions.'
2649
+ Enabled: pending
2650
+ VersionAdded: '1.76'
2651
+
2637
2652
  Lint/UselessRescue:
2638
2653
  Description: 'Checks for useless `rescue`s.'
2639
2654
  Enabled: pending
@@ -2673,7 +2688,7 @@ Metrics/AbcSize:
2673
2688
  Description: >-
2674
2689
  A calculated magnitude based on number of assignments,
2675
2690
  branches, and conditions.
2676
- Reference:
2691
+ References:
2677
2692
  - http://c2.com/cgi/wiki?AbcMetric
2678
2693
  - https://en.wikipedia.org/wiki/ABC_Software_Metric
2679
2694
  Enabled: true
@@ -3044,8 +3059,20 @@ Naming/MethodParameterName:
3044
3059
  # Forbidden names that will register an offense
3045
3060
  ForbiddenNames: []
3046
3061
 
3047
- Naming/PredicateName:
3048
- Description: 'Check the names of predicate methods.'
3062
+ Naming/PredicateMethod:
3063
+ Description: 'Checks that predicate methods end with `?` and non-predicate methods do not.'
3064
+ Enabled: pending
3065
+ VersionAdded: '1.76'
3066
+ # In `aggressive` mode, the cop will register an offense for predicate methods that
3067
+ # may return a non-boolean value.
3068
+ # In `conservative` mode, the cop will *not* register an offense for predicate methods
3069
+ # that may return a non-boolean value.
3070
+ Mode: conservative
3071
+ AllowedMethods:
3072
+ - call
3073
+
3074
+ Naming/PredicatePrefix:
3075
+ Description: 'Predicate method names should not be prefixed and end with a `?`.'
3049
3076
  StyleGuide: '#bool-methods-qmark'
3050
3077
  Enabled: true
3051
3078
  VersionAdded: '0.50'
@@ -3150,7 +3177,8 @@ Security/JSONLoad:
3150
3177
  Description: >-
3151
3178
  Prefer usage of `JSON.parse` over `JSON.load` due to potential
3152
3179
  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'
3180
+ References:
3181
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3154
3182
  Enabled: true
3155
3183
  VersionAdded: '0.43'
3156
3184
  VersionChanged: '1.22'
@@ -3162,7 +3190,8 @@ Security/MarshalLoad:
3162
3190
  Description: >-
3163
3191
  Avoid using of `Marshal.load` or `Marshal.restore` due to potential
3164
3192
  security issues. See reference for more information.
3165
- Reference: 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3193
+ References:
3194
+ - 'https://ruby-doc.org/core-2.7.0/Marshal.html#module-Marshal-label-Security+considerations'
3166
3195
  Enabled: true
3167
3196
  VersionAdded: '0.47'
3168
3197
 
@@ -3177,7 +3206,8 @@ Security/YAMLLoad:
3177
3206
  Description: >-
3178
3207
  Prefer usage of `YAML.safe_load` over `YAML.load` due to potential
3179
3208
  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'
3209
+ References:
3210
+ - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/yaml/rdoc/YAML.html#module-YAML-label-Security'
3181
3211
  Enabled: true
3182
3212
  VersionAdded: '0.47'
3183
3213
  SafeAutoCorrect: false
@@ -3271,7 +3301,8 @@ Style/ArrayCoercion:
3271
3301
 
3272
3302
  Style/ArrayFirstLast:
3273
3303
  Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
3274
- Reference: '#first-and-last'
3304
+ References:
3305
+ - '#first-and-last'
3275
3306
  Enabled: false
3276
3307
  VersionAdded: '1.58'
3277
3308
  Safe: false
@@ -3696,7 +3727,9 @@ Style/CommentedKeyword:
3696
3727
  Style/ComparableBetween:
3697
3728
  Description: 'Enforces the use of `Comparable#between?` instead of logical comparison.'
3698
3729
  Enabled: pending
3730
+ Safe: false
3699
3731
  VersionAdded: '1.74'
3732
+ VersionChanged: '1.75'
3700
3733
  StyleGuide: '#ranges-or-between'
3701
3734
 
3702
3735
  Style/ComparableClamp:
@@ -3931,6 +3964,16 @@ Style/EmptyMethod:
3931
3964
  - compact
3932
3965
  - expanded
3933
3966
 
3967
+ Style/EmptyStringInsideInterpolation:
3968
+ Description: 'Checks for empty strings being assigned inside string interpolation.'
3969
+ StyleGuide: '#empty-strings-in-interpolation'
3970
+ Enabled: pending
3971
+ EnforcedStyle: trailing_conditional
3972
+ SupportedStyles:
3973
+ - trailing_conditional
3974
+ - ternary
3975
+ VersionAdded: '1.76'
3976
+
3934
3977
  Style/Encoding:
3935
3978
  Description: 'Use UTF-8 as the source file encoding.'
3936
3979
  StyleGuide: '#utf-8'
@@ -4009,7 +4052,7 @@ Style/ExponentialNotation:
4009
4052
  Style/FetchEnvVar:
4010
4053
  Description: >-
4011
4054
  Suggests `ENV.fetch` for the replacement of `ENV[]`.
4012
- Reference:
4055
+ References:
4013
4056
  - https://rubystyle.guide/#hash-fetch-defaults
4014
4057
  Enabled: pending
4015
4058
  VersionAdded: '1.28'
@@ -4050,7 +4093,8 @@ Style/FileWrite:
4050
4093
  Style/FloatDivision:
4051
4094
  Description: 'For performing float division, coerce one side only.'
4052
4095
  StyleGuide: '#float-division'
4053
- Reference: 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4096
+ References:
4097
+ - 'https://blog.rubystyle.guide/ruby/2019/06/21/float-division.html'
4054
4098
  Enabled: true
4055
4099
  VersionAdded: '0.72'
4056
4100
  VersionChanged: '1.9'
@@ -4147,7 +4191,8 @@ Style/GlobalStdStream:
4147
4191
  Style/GlobalVars:
4148
4192
  Description: 'Do not introduce global variables.'
4149
4193
  StyleGuide: '#instance-vars'
4150
- Reference: 'https://www.zenspider.com/ruby/quickref.html'
4194
+ References:
4195
+ - 'https://www.zenspider.com/ruby/quickref.html'
4151
4196
  Enabled: true
4152
4197
  VersionAdded: '0.13'
4153
4198
  # Built-in global variables are allowed by default.
@@ -4423,12 +4468,14 @@ Style/ItAssignment:
4423
4468
  Style/ItBlockParameter:
4424
4469
  Description: 'Checks for blocks with one argument where `it` block parameter can be used.'
4425
4470
  Enabled: pending
4426
- EnforcedStyle: only_numbered_parameters
4471
+ EnforcedStyle: allow_single_line
4427
4472
  SupportedStyles:
4473
+ - allow_single_line
4428
4474
  - only_numbered_parameters
4429
4475
  - always
4430
4476
  - disallow
4431
4477
  VersionAdded: '1.75'
4478
+ VersionChanged: '1.76'
4432
4479
 
4433
4480
  Style/KeywordArgumentsMerging:
4434
4481
  Description: >-
@@ -4958,7 +5005,7 @@ Style/OpenStructUse:
4958
5005
  Description: >-
4959
5006
  Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4960
5007
  version compatibility, and potential security issues.
4961
- Reference:
5008
+ References:
4962
5009
  - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
4963
5010
 
4964
5011
  Enabled: pending
@@ -5141,6 +5188,12 @@ Style/RedundantArrayConstructor:
5141
5188
  Enabled: pending
5142
5189
  VersionAdded: '1.52'
5143
5190
 
5191
+ Style/RedundantArrayFlatten:
5192
+ Description: 'Checks for redundant calls of `Array#flatten`.'
5193
+ Enabled: pending
5194
+ Safe: false
5195
+ VersionAdded: '1.76'
5196
+
5144
5197
  Style/RedundantAssignment:
5145
5198
  Description: 'Checks for redundant assignment before returning.'
5146
5199
  Enabled: true
@@ -5203,7 +5256,8 @@ Style/RedundantFetchBlock:
5203
5256
  Description: >-
5204
5257
  Use `fetch(key, value)` instead of `fetch(key) { value }`
5205
5258
  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'
5259
+ References:
5260
+ - 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
5207
5261
  Enabled: true
5208
5262
  Safe: false
5209
5263
  # If enabled, this cop will autocorrect usages of
@@ -5445,7 +5499,8 @@ Style/Sample:
5445
5499
  Description: >-
5446
5500
  Use `sample` instead of `shuffle.first`,
5447
5501
  `shuffle.last`, and `shuffle[Integer]`.
5448
- Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5502
+ References:
5503
+ - 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
5449
5504
  Enabled: true
5450
5505
  VersionAdded: '0.30'
5451
5506
 
@@ -5940,7 +5995,8 @@ Style/YAMLFileRead:
5940
5995
 
5941
5996
  Style/YodaCondition:
5942
5997
  Description: 'Forbid or enforce yoda conditions.'
5943
- Reference: 'https://en.wikipedia.org/wiki/Yoda_conditions'
5998
+ References:
5999
+ - 'https://en.wikipedia.org/wiki/Yoda_conditions'
5944
6000
  Enabled: true
5945
6001
  EnforcedStyle: forbid_for_all_comparison_operators
5946
6002
  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)
@@ -6,10 +6,11 @@ module RuboCop
6
6
  # An attribute assignment method calls should be listed only once
7
7
  # in a gemspec.
8
8
  #
9
- # Assigning to an attribute with the same name using `spec.foo =` will be
10
- # an unintended usage. On the other hand, duplication of methods such
11
- # as `spec.requirements`, `spec.add_runtime_dependency`, and others are
12
- # permitted because it is the intended use of appending values.
9
+ # Assigning to an attribute with the same name using `spec.foo =` or
10
+ # `spec.attribute#[]=` will be an unintended usage. On the other hand,
11
+ # duplication of methods such # as `spec.requirements`,
12
+ # `spec.add_runtime_dependency`, and others are permitted because it is
13
+ # the intended use of appending values.
13
14
  #
14
15
  # @example
15
16
  # # bad
@@ -34,6 +35,18 @@ module RuboCop
34
35
  # spec.add_dependency('parallel', '~> 1.10')
35
36
  # spec.add_dependency('parser', '>= 2.3.3.1', '< 3.0')
36
37
  # end
38
+ #
39
+ # # bad
40
+ # Gem::Specification.new do |spec|
41
+ # spec.metadata["key"] = "value"
42
+ # spec.metadata["key"] = "value"
43
+ # end
44
+ #
45
+ # # good
46
+ # Gem::Specification.new do |spec|
47
+ # spec.metadata["key"] = "value"
48
+ # end
49
+ #
37
50
  class DuplicatedAssignment < Base
38
51
  include RangeHelp
39
52
  include GemspecHelp
@@ -44,12 +57,29 @@ module RuboCop
44
57
  # @!method assignment_method_declarations(node)
45
58
  def_node_search :assignment_method_declarations, <<~PATTERN
46
59
  (send
47
- (lvar #match_block_variable_name?) _ ...)
60
+ (lvar {#match_block_variable_name? :_1 :it}) _ ...)
61
+ PATTERN
62
+
63
+ # @!method indexed_assignment_method_declarations(node)
64
+ def_node_search :indexed_assignment_method_declarations, <<~PATTERN
65
+ (send
66
+ (send (lvar {#match_block_variable_name? :_1 :it}) _)
67
+ :[]=
68
+ literal?
69
+ _
70
+ )
48
71
  PATTERN
49
72
 
50
73
  def on_new_investigation
51
74
  return if processed_source.blank?
52
75
 
76
+ process_assignment_method_nodes
77
+ process_indexed_assignment_method_nodes
78
+ end
79
+
80
+ private
81
+
82
+ def process_assignment_method_nodes
53
83
  duplicated_assignment_method_nodes.each do |nodes|
54
84
  nodes[1..].each do |node|
55
85
  register_offense(node, node.method_name, nodes.first.first_line)
@@ -57,7 +87,14 @@ module RuboCop
57
87
  end
58
88
  end
59
89
 
60
- private
90
+ def process_indexed_assignment_method_nodes
91
+ duplicated_indexed_assignment_method_nodes.each do |nodes|
92
+ nodes[1..].each do |node|
93
+ assignment = "#{node.children.first.method_name}[#{node.first_argument.source}]="
94
+ register_offense(node, assignment, nodes.first.first_line)
95
+ end
96
+ end
97
+ end
61
98
 
62
99
  def match_block_variable_name?(receiver_name)
63
100
  gem_specification(processed_source.ast) do |block_variable_name|
@@ -73,6 +110,13 @@ module RuboCop
73
110
  .select { |nodes| nodes.size > 1 }
74
111
  end
75
112
 
113
+ def duplicated_indexed_assignment_method_nodes
114
+ indexed_assignment_method_declarations(processed_source.ast)
115
+ .group_by { |node| [node.children.first.method_name, node.first_argument] }
116
+ .values
117
+ .select { |nodes| nodes.size > 1 }
118
+ end
119
+
76
120
  def register_offense(node, assignment, line_of_first_occurrence)
77
121
  line_range = node.loc.column...node.loc.last_column
78
122
  offense_location = source_range(processed_source.buffer, node.first_line, line_range)
@@ -71,7 +71,7 @@ module RuboCop
71
71
 
72
72
  dependency_declarations(processed_source.ast)
73
73
  .each_cons(2) do |previous, current|
74
- next unless consecutive_lines(previous, current)
74
+ next unless consecutive_lines?(previous, current)
75
75
  next unless case_insensitive_out_of_order?(gem_name(current), gem_name(previous))
76
76
  next unless get_dependency_name(previous) == get_dependency_name(current)
77
77
 
@@ -69,7 +69,7 @@ module RuboCop
69
69
  # @!method offense_example(node)
70
70
  def_node_matcher :offense_example, <<~PATTERN
71
71
  (block
72
- (send _ {:it :specify} $...)
72
+ (send _ {:it :specify :xit :fit} $...)
73
73
  _args
74
74
  `(send nil? %RESTRICT_ON_SEND ...)
75
75
  )
@@ -29,6 +29,7 @@ module RuboCop
29
29
  NODE_GROUPS = {
30
30
  any_block: %i[block numblock itblock],
31
31
  any_def: %i[def defs],
32
+ any_match_pattern: %i[match_pattern match_pattern_p],
32
33
  argument: %i[arg optarg restarg kwarg kwoptarg kwrestarg blockarg forward_arg shadowarg],
33
34
  boolean: %i[true false],
34
35
  call: %i[send csend],
@@ -10,7 +10,12 @@ module RuboCop
10
10
  extend FileFinder
11
11
 
12
12
  ALLOWED_CONFIGURATIONS = %w[
13
- Safe SafeAutoCorrect AutoCorrect Severity StyleGuide Details Reference Include Exclude
13
+ Safe SafeAutoCorrect AutoCorrect
14
+ Severity
15
+ StyleGuide
16
+ Details
17
+ Reference References
18
+ Include Exclude
14
19
  ].freeze
15
20
  RESTRICT_ON_SEND = %i[[] fetch].freeze
16
21
  MSG = '`%<name>s` is not defined in the configuration for `%<cop>s` ' \