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.
- checksums.yaml +4 -4
- data/README.md +19 -13
- data/config/default.yml +79 -23
- data/config/obsoletion.yml +6 -3
- data/lib/rubocop/config_validator.rb +6 -6
- data/lib/rubocop/cop/autocorrect_logic.rb +18 -10
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +50 -6
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
- data/lib/rubocop/cop/layout/class_structure.rb +35 -0
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -2
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/leading_comment_space.rb +13 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +10 -0
- data/lib/rubocop/cop/layout/space_before_brackets.rb +6 -32
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +5 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +3 -0
- data/lib/rubocop/cop/lint/array_literal_in_regexp.rb +2 -3
- data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +84 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +27 -0
- data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
- data/lib/rubocop/cop/lint/literal_as_condition.rb +31 -25
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +87 -0
- data/lib/rubocop/cop/lint/useless_or.rb +98 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +2 -2
- data/lib/rubocop/cop/message_annotator.rb +7 -3
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +15 -14
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +9 -5
- data/lib/rubocop/cop/naming/predicate_method.rb +216 -0
- data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
- data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +19 -3
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/comparable_between.rb +5 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +15 -6
- data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
- data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
- data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
- data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
- data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +3 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +22 -4
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
- data/lib/rubocop/cop/style/it_block_parameter.rb +33 -14
- data/lib/rubocop/cop/style/lambda_call.rb +7 -2
- data/lib/rubocop/cop/style/map_into_array.rb +3 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +11 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -1
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/redundant_array_flatten.rb +48 -0
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
- data/lib/rubocop/cop/style/redundant_format.rb +6 -1
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
- data/lib/rubocop/cop/style/redundant_parentheses.rb +31 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +28 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
- data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
- data/lib/rubocop/cop/team.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
- data/lib/rubocop/cops_documentation_generator.rb +6 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +2 -2
- data/lib/rubocop/rspec/shared_contexts.rb +1 -2
- data/lib/rubocop/target_finder.rb +5 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +6 -1
- metadata +12 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 236bdf0fa5879274099388142e17b886fc852cdc1e762d50c74a31254c7c6136
|
|
4
|
+
data.tar.gz: 03011b196c686aa5ce1cc617d56c19041dbdc76ba237626316048be9e75dc62c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
39
|
+
gem install rubocop
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
If you'd rather install RuboCop using `bundler`, add a line for it in your
|
|
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.
|
|
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
|
-
|
|
66
|
-
|
|
65
|
+
```sh
|
|
66
|
+
cd my/cool/ruby/project
|
|
67
|
+
rubocop
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
|
|
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
|
-
|
|
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
|
[](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
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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/
|
|
3048
|
-
Description: '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
data/config/obsoletion.yml
CHANGED
|
@@ -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/
|
|
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/
|
|
185
|
+
- cops: Naming/PredicatePrefix
|
|
183
186
|
parameters: NamePrefixBlacklist
|
|
184
187
|
alternative: ForbiddenPrefixes
|
|
185
|
-
- cops: Naming/
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
89
|
-
|
|
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
|
|
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 =`
|
|
10
|
-
# an unintended usage. On the other hand,
|
|
11
|
-
# as `spec.requirements`,
|
|
12
|
-
# permitted because it is
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
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` ' \
|