rubocop 1.53.0 → 1.60.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/LICENSE.txt +1 -1
- data/README.md +5 -3
- data/config/default.yml +80 -11
- data/config/obsoletion.yml +5 -0
- data/lib/rubocop/cli/command/auto_generate_config.rb +10 -5
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +0 -2
- data/lib/rubocop/config_finder.rb +2 -2
- data/lib/rubocop/config_loader.rb +0 -1
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +9 -1
- data/lib/rubocop/config_obsoletion.rb +11 -8
- data/lib/rubocop/config_validator.rb +0 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +3 -1
- data/lib/rubocop/cop/base.rb +7 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -0
- data/lib/rubocop/cop/bundler/duplicated_group.rb +127 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +7 -4
- data/lib/rubocop/cop/exclude_limit.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -1
- data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +42 -21
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +3 -1
- data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +19 -20
- data/lib/rubocop/cop/internal_affairs/node_first_or_last_argument.rb +53 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
- data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +2 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -5
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +42 -9
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +26 -3
- data/lib/rubocop/cop/layout/end_alignment.rb +12 -2
- data/lib/rubocop/cop/layout/extra_spacing.rb +4 -10
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +22 -7
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +4 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +17 -9
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +18 -3
- data/lib/rubocop/cop/layout/redundant_line_break.rb +15 -4
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +4 -4
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +5 -0
- data/lib/rubocop/cop/layout/space_after_comma.rb +9 -1
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +53 -21
- data/lib/rubocop/cop/layout/space_inside_parens.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +5 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +4 -4
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -2
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +18 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -3
- data/lib/rubocop/cop/lint/float_comparison.rb +10 -0
- data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +2 -1
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +56 -0
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +85 -0
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_case_range.rb +3 -1
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +6 -21
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +10 -7
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +3 -5
- data/lib/rubocop/cop/lint/number_conversion.rb +9 -4
- data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +10 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +4 -0
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +63 -4
- data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
- data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +14 -8
- data/lib/rubocop/cop/lint/self_assignment.rb +38 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +7 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +12 -12
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/symbol_conversion.rb +8 -3
- data/lib/rubocop/cop/lint/syntax.rb +6 -3
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +5 -3
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +2 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -2
- data/lib/rubocop/cop/lint/useless_assignment.rb +38 -12
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +46 -21
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -3
- data/lib/rubocop/cop/metrics/block_length.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +8 -3
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +32 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +16 -12
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/def_node.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +14 -11
- data/lib/rubocop/cop/mixin/heredoc.rb +6 -2
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +6 -8
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/string_help.rb +4 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +12 -4
- data/lib/rubocop/cop/naming/constant_name.rb +1 -2
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +3 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +4 -4
- data/lib/rubocop/cop/security/open.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +2 -2
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +9 -8
- data/lib/rubocop/cop/style/arguments_forwarding.rb +355 -63
- data/lib/rubocop/cop/style/array_first_last.rb +64 -0
- data/lib/rubocop/cop/style/array_intersect.rb +13 -5
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +21 -14
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +2 -2
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
- data/lib/rubocop/cop/style/case_like_if.rb +4 -4
- data/lib/rubocop/cop/style/class_check.rb +1 -0
- data/lib/rubocop/cop/style/class_equality_comparison.rb +7 -0
- data/lib/rubocop/cop/style/collection_compact.rb +7 -6
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/combinable_loops.rb +17 -9
- data/lib/rubocop/cop/style/concat_array_literals.rb +2 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
- data/lib/rubocop/cop/style/date_time.rb +5 -4
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +7 -7
- data/lib/rubocop/cop/style/each_with_object.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +3 -14
- data/lib/rubocop/cop/style/exact_regexp_match.rb +2 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
- data/lib/rubocop/cop/style/for.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +24 -3
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -1
- data/lib/rubocop/cop/style/guard_clause.rb +26 -0
- data/lib/rubocop/cop/style/hash_conversion.rb +10 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +83 -10
- data/lib/rubocop/cop/style/hash_except.rb +2 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +28 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +6 -5
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +39 -2
- data/lib/rubocop/cop/style/lambda.rb +3 -3
- data/lib/rubocop/cop/style/lambda_call.rb +5 -0
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +3 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +17 -7
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +22 -6
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -4
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +20 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +2 -2
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -4
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -11
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
- data/lib/rubocop/cop/style/open_struct_use.rb +1 -1
- data/lib/rubocop/cop/style/operator_method_call.rb +8 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -0
- data/lib/rubocop/cop/style/redundant_argument.rb +9 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +9 -1
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -9
- data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +93 -5
- data/lib/rubocop/cop/style/redundant_each.rb +7 -4
- data/lib/rubocop/cop/style/redundant_exception.rb +32 -12
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +3 -3
- data/lib/rubocop/cop/style/redundant_filter_chain.rb +22 -5
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +10 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +63 -21
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +18 -4
- data/lib/rubocop/cop/style/redundant_return.rb +8 -3
- data/lib/rubocop/cop/style/redundant_self.rb +17 -2
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +5 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +9 -8
- data/lib/rubocop/cop/style/redundant_sort_by.rb +2 -2
- data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -1
- data/lib/rubocop/cop/style/return_nil.rb +6 -2
- data/lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb +23 -9
- data/lib/rubocop/cop/style/sample.rb +2 -1
- data/lib/rubocop/cop/style/select_by_regexp.rb +7 -6
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +8 -3
- data/lib/rubocop/cop/style/single_argument_dig.rb +7 -3
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +67 -0
- data/lib/rubocop/cop/style/slicing_with_range.rb +76 -10
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
- data/lib/rubocop/cop/style/string_chars.rb +1 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +30 -5
- data/lib/rubocop/cop/style/strip.rb +7 -4
- data/lib/rubocop/cop/style/super_with_args_parentheses.rb +35 -0
- data/lib/rubocop/cop/style/symbol_array.rb +35 -15
- data/lib/rubocop/cop/style/symbol_proc.rb +36 -0
- data/lib/rubocop/cop/style/unpack_first.rb +11 -14
- data/lib/rubocop/cop/style/yoda_condition.rb +4 -2
- data/lib/rubocop/cop/style/yoda_expression.rb +8 -7
- data/lib/rubocop/cop/utils/regexp_ranges.rb +26 -13
- data/lib/rubocop/cop/variable_force/assignment.rb +14 -5
- data/lib/rubocop/cops_documentation_generator.rb +11 -1
- data/lib/rubocop/ext/regexp_node.rb +9 -4
- data/lib/rubocop/file_finder.rb +4 -7
- data/lib/rubocop/formatter/disabled_config_formatter.rb +17 -6
- data/lib/rubocop/formatter/html_formatter.rb +5 -4
- data/lib/rubocop/formatter/json_formatter.rb +0 -1
- data/lib/rubocop/formatter/junit_formatter.rb +1 -1
- data/lib/rubocop/formatter.rb +1 -1
- data/lib/rubocop/lsp/routes.rb +42 -19
- data/lib/rubocop/lsp/runtime.rb +22 -2
- data/lib/rubocop/lsp/server.rb +10 -4
- data/lib/rubocop/magic_comment.rb +12 -10
- data/lib/rubocop/options.rb +0 -8
- data/lib/rubocop/result_cache.rb +4 -1
- data/lib/rubocop/rspec/shared_contexts.rb +8 -3
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/runner.rb +6 -4
- data/lib/rubocop/server/client_command/exec.rb +1 -1
- data/lib/rubocop/string_interpreter.rb +3 -3
- data/lib/rubocop/target_finder.rb +7 -3
- data/lib/rubocop/target_ruby.rb +9 -5
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +6 -0
- metadata +20 -13
- /data/lib/rubocop/formatter/{git_hub_actions_formatter.rb → github_actions_formatter.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8154c812a06c819d2014cca8c0967d9b9eb01ff0481b33318accfb61781b04ce
|
|
4
|
+
data.tar.gz: d39b524c83cd84df683815b59ac1377fb9dc235dcce337507a56bf611eaa90af
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz: '
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0787d7ca9354c20ef1fbbee33dc551cd2e45e8c3ea4aac96a51f8348b3a03a3ae1cc5262e0e6d00f61591f48ce4ffbf9140d7f1ddd19b9716d0596df3bbaa55c'
|
|
7
|
+
data.tar.gz: de7a48105e8126e9f2c323dc516d4c9862b8c239d881e8285496eb3e79cefdecf487a37e0cb3e0b98fc25264f33c3a2d104fb1e6a4e382d1619f21dace50cc99
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/rubocop/rubocop/master/logo/rubo-logo-horizontal.png" alt="RuboCop Logo"/>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/rubocop/rubocop/master/logo/rubo-logo-horizontal-white.png" alt="RuboCop Logo"/>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
----------
|
|
@@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
|
53
53
|
in your `Gemfile`:
|
|
54
54
|
|
|
55
55
|
```rb
|
|
56
|
-
gem 'rubocop', '~> 1.
|
|
56
|
+
gem 'rubocop', '~> 1.60', require: false
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
|
@@ -67,6 +67,8 @@ $ cd my/cool/ruby/project
|
|
|
67
67
|
$ rubocop
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
+
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).
|
|
71
|
+
|
|
70
72
|
## Documentation
|
|
71
73
|
|
|
72
74
|
You can read a lot more about RuboCop in its [official docs](https://docs.rubocop.org).
|
|
@@ -246,5 +248,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
|
|
|
246
248
|
|
|
247
249
|
## Copyright
|
|
248
250
|
|
|
249
|
-
Copyright (c) 2012-
|
|
251
|
+
Copyright (c) 2012-2024 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
|
|
250
252
|
further details.
|
data/config/default.yml
CHANGED
|
@@ -30,6 +30,7 @@ AllCops:
|
|
|
30
30
|
- '**/*.rbx'
|
|
31
31
|
- '**/*.ru'
|
|
32
32
|
- '**/*.ruby'
|
|
33
|
+
- '**/*.schema'
|
|
33
34
|
- '**/*.spec'
|
|
34
35
|
- '**/*.thor'
|
|
35
36
|
- '**/*.watchr'
|
|
@@ -55,6 +56,7 @@ AllCops:
|
|
|
55
56
|
- '**/Puppetfile'
|
|
56
57
|
- '**/Rakefile'
|
|
57
58
|
- '**/rakefile'
|
|
59
|
+
- '**/Schemafile'
|
|
58
60
|
- '**/Snapfile'
|
|
59
61
|
- '**/Steepfile'
|
|
60
62
|
- '**/Thorfile'
|
|
@@ -171,6 +173,16 @@ Bundler/DuplicatedGem:
|
|
|
171
173
|
- '**/Gemfile'
|
|
172
174
|
- '**/gems.rb'
|
|
173
175
|
|
|
176
|
+
Bundler/DuplicatedGroup:
|
|
177
|
+
Description: 'Checks for duplicate group entries in Gemfile.'
|
|
178
|
+
Enabled: true
|
|
179
|
+
Severity: warning
|
|
180
|
+
VersionAdded: '1.56'
|
|
181
|
+
Include:
|
|
182
|
+
- '**/*.gemfile'
|
|
183
|
+
- '**/Gemfile'
|
|
184
|
+
- '**/gems.rb'
|
|
185
|
+
|
|
174
186
|
Bundler/GemComment:
|
|
175
187
|
Description: 'Add a comment describing each gem.'
|
|
176
188
|
Enabled: false
|
|
@@ -577,6 +589,8 @@ Layout/EmptyLineBetweenDefs:
|
|
|
577
589
|
EmptyLineBetweenMethodDefs: true
|
|
578
590
|
EmptyLineBetweenClassDefs: true
|
|
579
591
|
EmptyLineBetweenModuleDefs: true
|
|
592
|
+
# `DefLikeMacros` takes the name of any macro that you want to treat like a def.
|
|
593
|
+
DefLikeMacros: []
|
|
580
594
|
# `AllowAdjacentOneLineDefs` means that single line method definitions don't
|
|
581
595
|
# need an empty line between them. `true` by default.
|
|
582
596
|
AllowAdjacentOneLineDefs: true
|
|
@@ -1337,6 +1351,10 @@ Layout/SpaceAroundOperators:
|
|
|
1337
1351
|
SupportedStylesForExponentOperator:
|
|
1338
1352
|
- space
|
|
1339
1353
|
- no_space
|
|
1354
|
+
EnforcedStyleForRationalLiterals: no_space
|
|
1355
|
+
SupportedStylesForRationalLiterals:
|
|
1356
|
+
- space
|
|
1357
|
+
- no_space
|
|
1340
1358
|
|
|
1341
1359
|
Layout/SpaceBeforeBlockBraces:
|
|
1342
1360
|
Description: >-
|
|
@@ -1945,6 +1963,12 @@ Lint/InterpolationCheck:
|
|
|
1945
1963
|
VersionAdded: '0.50'
|
|
1946
1964
|
VersionChanged: '1.40'
|
|
1947
1965
|
|
|
1966
|
+
Lint/ItWithoutArgumentsInBlock:
|
|
1967
|
+
Description: 'Checks uses of `it` calls without arguments in block.'
|
|
1968
|
+
Reference: 'https://bugs.ruby-lang.org/issues/18980'
|
|
1969
|
+
Enabled: pending
|
|
1970
|
+
VersionAdded: '1.59'
|
|
1971
|
+
|
|
1948
1972
|
Lint/LambdaWithoutLiteralBlock:
|
|
1949
1973
|
Description: 'Checks uses of lambda without a literal block.'
|
|
1950
1974
|
Enabled: pending
|
|
@@ -1955,6 +1979,11 @@ Lint/LiteralAsCondition:
|
|
|
1955
1979
|
Enabled: true
|
|
1956
1980
|
VersionAdded: '0.51'
|
|
1957
1981
|
|
|
1982
|
+
Lint/LiteralAssignmentInCondition:
|
|
1983
|
+
Description: 'Checks for literal assignments in the conditions.'
|
|
1984
|
+
Enabled: pending
|
|
1985
|
+
VersionAdded: '1.58'
|
|
1986
|
+
|
|
1958
1987
|
Lint/LiteralInInterpolation:
|
|
1959
1988
|
Description: 'Checks for literals used in interpolation.'
|
|
1960
1989
|
Enabled: true
|
|
@@ -2156,7 +2185,9 @@ Lint/RedundantRegexpQuantifiers:
|
|
|
2156
2185
|
Lint/RedundantRequireStatement:
|
|
2157
2186
|
Description: 'Checks for unnecessary `require` statement.'
|
|
2158
2187
|
Enabled: true
|
|
2188
|
+
SafeAutoCorrect: false
|
|
2159
2189
|
VersionAdded: '0.76'
|
|
2190
|
+
VersionChanged: '1.57'
|
|
2160
2191
|
|
|
2161
2192
|
Lint/RedundantSafeNavigation:
|
|
2162
2193
|
Description: 'Checks for redundant safe navigation calls.'
|
|
@@ -3068,7 +3099,20 @@ Style/ArgumentsForwarding:
|
|
|
3068
3099
|
StyleGuide: '#arguments-forwarding'
|
|
3069
3100
|
Enabled: pending
|
|
3070
3101
|
AllowOnlyRestArgument: true
|
|
3102
|
+
UseAnonymousForwarding: true
|
|
3103
|
+
RedundantRestArgumentNames:
|
|
3104
|
+
- args
|
|
3105
|
+
- arguments
|
|
3106
|
+
RedundantKeywordRestArgumentNames:
|
|
3107
|
+
- kwargs
|
|
3108
|
+
- options
|
|
3109
|
+
- opts
|
|
3110
|
+
RedundantBlockArgumentNames:
|
|
3111
|
+
- blk
|
|
3112
|
+
- block
|
|
3113
|
+
- proc
|
|
3071
3114
|
VersionAdded: '1.1'
|
|
3115
|
+
VersionChanged: '1.58'
|
|
3072
3116
|
|
|
3073
3117
|
Style/ArrayCoercion:
|
|
3074
3118
|
Description: >-
|
|
@@ -3079,6 +3123,13 @@ Style/ArrayCoercion:
|
|
|
3079
3123
|
Enabled: false
|
|
3080
3124
|
VersionAdded: '0.88'
|
|
3081
3125
|
|
|
3126
|
+
Style/ArrayFirstLast:
|
|
3127
|
+
Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
|
|
3128
|
+
Reference: '#first-and-last'
|
|
3129
|
+
Enabled: false
|
|
3130
|
+
VersionAdded: '1.58'
|
|
3131
|
+
Safe: false
|
|
3132
|
+
|
|
3082
3133
|
Style/ArrayIntersect:
|
|
3083
3134
|
Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
|
|
3084
3135
|
Enabled: 'pending'
|
|
@@ -3339,7 +3390,9 @@ Style/ClassEqualityComparison:
|
|
|
3339
3390
|
Description: 'Enforces the use of `Object#instance_of?` instead of class comparison for equality.'
|
|
3340
3391
|
StyleGuide: '#instance-of-vs-class-comparison'
|
|
3341
3392
|
Enabled: true
|
|
3393
|
+
SafeAutoCorrect: false
|
|
3342
3394
|
VersionAdded: '0.93'
|
|
3395
|
+
VersionChanged: '1.57'
|
|
3343
3396
|
AllowedMethods:
|
|
3344
3397
|
- ==
|
|
3345
3398
|
- equal?
|
|
@@ -3394,6 +3447,7 @@ Style/CollectionMethods:
|
|
|
3394
3447
|
PreferredMethods:
|
|
3395
3448
|
collect: 'map'
|
|
3396
3449
|
collect!: 'map!'
|
|
3450
|
+
collect_concat: 'flat_map'
|
|
3397
3451
|
inject: 'reduce'
|
|
3398
3452
|
detect: 'find'
|
|
3399
3453
|
find_all: 'select'
|
|
@@ -3912,8 +3966,9 @@ Style/HashConversion:
|
|
|
3912
3966
|
Description: 'Avoid Hash[] in favor of ary.to_h or literal hashes.'
|
|
3913
3967
|
StyleGuide: '#avoid-hash-constructor'
|
|
3914
3968
|
Enabled: pending
|
|
3969
|
+
SafeAutoCorrect: false
|
|
3915
3970
|
VersionAdded: '1.10'
|
|
3916
|
-
VersionChanged: '1.
|
|
3971
|
+
VersionChanged: '1.55'
|
|
3917
3972
|
AllowSplatArgument: true
|
|
3918
3973
|
|
|
3919
3974
|
Style/HashEachMethods:
|
|
@@ -4114,12 +4169,6 @@ Style/InvertibleUnlessCondition:
|
|
|
4114
4169
|
:none?: :any?
|
|
4115
4170
|
:even?: :odd?
|
|
4116
4171
|
:odd?: :even?
|
|
4117
|
-
# `ActiveSupport` defines some common inverse methods. They are listed below,
|
|
4118
|
-
# and not enabled by default.
|
|
4119
|
-
# :present?: :blank?
|
|
4120
|
-
# :blank?: :present?
|
|
4121
|
-
# :include?: :exclude?
|
|
4122
|
-
# :exclude?: :include?
|
|
4123
4172
|
|
|
4124
4173
|
Style/IpAddresses:
|
|
4125
4174
|
Description: "Don't include literal IP addresses in code."
|
|
@@ -4663,6 +4712,7 @@ Style/OperatorMethodCall:
|
|
|
4663
4712
|
|
|
4664
4713
|
Style/OptionHash:
|
|
4665
4714
|
Description: "Don't use option hashes when you can use keyword arguments."
|
|
4715
|
+
StyleGuide: '#keyword-arguments-vs-option-hashes'
|
|
4666
4716
|
Enabled: false
|
|
4667
4717
|
VersionAdded: '0.33'
|
|
4668
4718
|
VersionChanged: '0.34'
|
|
@@ -4806,12 +4856,16 @@ Style/RedundantArgument:
|
|
|
4806
4856
|
Enabled: pending
|
|
4807
4857
|
Safe: false
|
|
4808
4858
|
VersionAdded: '1.4'
|
|
4809
|
-
VersionChanged: '1.
|
|
4859
|
+
VersionChanged: '1.55'
|
|
4810
4860
|
Methods:
|
|
4811
4861
|
# Array#join
|
|
4812
4862
|
join: ''
|
|
4813
4863
|
# Array#sum
|
|
4814
4864
|
sum: 0
|
|
4865
|
+
# Kernel.#exit
|
|
4866
|
+
exit: true
|
|
4867
|
+
# Kernel.#exit!
|
|
4868
|
+
exit!: false
|
|
4815
4869
|
# String#split
|
|
4816
4870
|
split: ' '
|
|
4817
4871
|
# String#chomp
|
|
@@ -4883,7 +4937,7 @@ Style/RedundantFetchBlock:
|
|
|
4883
4937
|
Description: >-
|
|
4884
4938
|
Use `fetch(key, value)` instead of `fetch(key) { value }`
|
|
4885
4939
|
when value has Numeric, Rational, Complex, Symbol or String type, `false`, `true`, `nil` or is a constant.
|
|
4886
|
-
Reference: 'https://github.com/
|
|
4940
|
+
Reference: 'https://github.com/fastruby/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code'
|
|
4887
4941
|
Enabled: true
|
|
4888
4942
|
Safe: false
|
|
4889
4943
|
# If enabled, this cop will autocorrect usages of
|
|
@@ -4905,7 +4959,9 @@ Style/RedundantFilterChain:
|
|
|
4905
4959
|
Identifies usages of `any?`, `empty?`, `none?` or `one?` predicate methods chained to
|
|
4906
4960
|
`select`/`filter`/`find_all` and change them to use predicate method instead.
|
|
4907
4961
|
Enabled: pending
|
|
4962
|
+
SafeAutoCorrect: false
|
|
4908
4963
|
VersionAdded: '1.52'
|
|
4964
|
+
VersionChanged: '1.57'
|
|
4909
4965
|
|
|
4910
4966
|
Style/RedundantFreeze:
|
|
4911
4967
|
Description: "Checks usages of Object#freeze on immutable objects."
|
|
@@ -5102,7 +5158,7 @@ Style/Sample:
|
|
|
5102
5158
|
Description: >-
|
|
5103
5159
|
Use `sample` instead of `shuffle.first`,
|
|
5104
5160
|
`shuffle.last`, and `shuffle[Integer]`.
|
|
5105
|
-
Reference: 'https://github.com/
|
|
5161
|
+
Reference: 'https://github.com/fastruby/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
|
5106
5162
|
Enabled: true
|
|
5107
5163
|
VersionAdded: '0.30'
|
|
5108
5164
|
|
|
@@ -5167,6 +5223,12 @@ Style/SingleLineBlockParams:
|
|
|
5167
5223
|
- acc
|
|
5168
5224
|
- elem
|
|
5169
5225
|
|
|
5226
|
+
Style/SingleLineDoEndBlock:
|
|
5227
|
+
Description: 'Checks for single-line `do`...`end` blocks.'
|
|
5228
|
+
StyleGuide: '#single-line-do-end-block'
|
|
5229
|
+
Enabled: pending
|
|
5230
|
+
VersionAdded: '1.57'
|
|
5231
|
+
|
|
5170
5232
|
Style/SingleLineMethods:
|
|
5171
5233
|
Description: 'Avoid single-line methods.'
|
|
5172
5234
|
StyleGuide: '#no-single-line-methods'
|
|
@@ -5176,7 +5238,8 @@ Style/SingleLineMethods:
|
|
|
5176
5238
|
AllowIfMethodIsEmpty: true
|
|
5177
5239
|
|
|
5178
5240
|
Style/SlicingWithRange:
|
|
5179
|
-
Description: 'Checks array slicing is done with endless ranges when suitable.'
|
|
5241
|
+
Description: 'Checks array slicing is done with redundant, endless, and beginless ranges when suitable.'
|
|
5242
|
+
StyleGuide: '#slicing-with-ranges'
|
|
5180
5243
|
Enabled: true
|
|
5181
5244
|
VersionAdded: '0.83'
|
|
5182
5245
|
Safe: false
|
|
@@ -5303,6 +5366,12 @@ Style/StructInheritance:
|
|
|
5303
5366
|
VersionAdded: '0.29'
|
|
5304
5367
|
VersionChanged: '1.20'
|
|
5305
5368
|
|
|
5369
|
+
Style/SuperWithArgsParentheses:
|
|
5370
|
+
Description: 'Use parentheses for `super` with arguments.'
|
|
5371
|
+
StyleGuide: '#super-with-args'
|
|
5372
|
+
Enabled: pending
|
|
5373
|
+
VersionAdded: '1.58'
|
|
5374
|
+
|
|
5306
5375
|
Style/SwapValues:
|
|
5307
5376
|
Description: 'Enforces the use of shorthand-style swapping of 2 variables.'
|
|
5308
5377
|
StyleGuide: '#values-swapping'
|
data/config/obsoletion.yml
CHANGED
|
@@ -224,6 +224,11 @@ changed_parameters:
|
|
|
224
224
|
- AllowedMethods
|
|
225
225
|
- AllowedPatterns
|
|
226
226
|
severity: warning
|
|
227
|
+
- cops: Style/ArgumentsForwarding
|
|
228
|
+
parameters: AllowOnlyRestArgument
|
|
229
|
+
reason: "`AllowOnlyRestArgument` has no effect with TargetRubyVersion >= 3.2."
|
|
230
|
+
severity: warning
|
|
231
|
+
minimum_ruby_version: 3.2
|
|
227
232
|
|
|
228
233
|
# Enforced styles that have been removed or replaced
|
|
229
234
|
changed_enforced_styles:
|
|
@@ -10,6 +10,7 @@ module RuboCop
|
|
|
10
10
|
|
|
11
11
|
AUTO_GENERATED_FILE = '.rubocop_todo.yml'
|
|
12
12
|
YAML_OPTIONAL_DOC_START = /\A---(\s+#|\s*\z)/.freeze
|
|
13
|
+
PLACEHOLDER = '###rubocop:inherit_here'
|
|
13
14
|
|
|
14
15
|
PHASE_1 = 'Phase 1 of 2: run Layout/LineLength cop'
|
|
15
16
|
PHASE_2 = 'Phase 2 of 2: run all cops'
|
|
@@ -125,15 +126,19 @@ module RuboCop
|
|
|
125
126
|
|
|
126
127
|
def existing_configuration(config_file)
|
|
127
128
|
File.read(config_file, encoding: Encoding::UTF_8)
|
|
128
|
-
.sub(/^inherit_from: *[^\n]+/,
|
|
129
|
-
.sub(/^inherit_from: *(\n *- *[^\n]+)+/,
|
|
129
|
+
.sub(/^inherit_from: *[^\n]+/, PLACEHOLDER)
|
|
130
|
+
.sub(/^inherit_from: *(\n *- *[^\n]+)+/, PLACEHOLDER)
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
def write_config_file(file_name, file_string, rubocop_yml_contents)
|
|
133
134
|
lines = /\S/.match?(rubocop_yml_contents) ? rubocop_yml_contents.split("\n", -1) : []
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
unless rubocop_yml_contents&.include?(PLACEHOLDER)
|
|
136
|
+
doc_start_index = lines.index { |line| YAML_OPTIONAL_DOC_START.match?(line) } || -1
|
|
137
|
+
lines.insert(doc_start_index + 1, PLACEHOLDER)
|
|
138
|
+
end
|
|
139
|
+
File.write(file_name, lines.join("\n")
|
|
140
|
+
.sub(/#{PLACEHOLDER}\n*/o, "inherit_from:#{file_string}\n\n")
|
|
141
|
+
.sub(/\n\n+\Z/, "\n"))
|
|
137
142
|
end
|
|
138
143
|
|
|
139
144
|
def relative_path_to_todo_from_options_config
|
data/lib/rubocop/cli.rb
CHANGED
|
@@ -11,7 +11,7 @@ module RuboCop
|
|
|
11
11
|
STATUS_ERROR = 2
|
|
12
12
|
STATUS_INTERRUPTED = Signal.list['INT'] + 128
|
|
13
13
|
DEFAULT_PARALLEL_OPTIONS = %i[
|
|
14
|
-
color debug display_style_guide display_time display_only_fail_level_offenses
|
|
14
|
+
color config debug display_style_guide display_time display_only_fail_level_offenses
|
|
15
15
|
display_only_failed except extra_details fail_level fix_layout format
|
|
16
16
|
ignore_disable_comments lint only only_guide_cops require safe
|
|
17
17
|
autocorrect safe_autocorrect autocorrect_all
|
data/lib/rubocop/config.rb
CHANGED
|
@@ -46,14 +46,14 @@ module RuboCop
|
|
|
46
46
|
|
|
47
47
|
file = File.join(Dir.home, DOTFILE)
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
file if File.exist?(file)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def find_user_xdg_config
|
|
53
53
|
xdg_config_home = expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
|
54
54
|
xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG)
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
xdg_config if File.exist?(xdg_config)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def expand_path(path)
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def violated?
|
|
22
|
-
config[cop]&.key?(parameter)
|
|
22
|
+
applies_to_current_ruby_version? && config[cop]&.key?(parameter)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def warning?
|
|
@@ -28,6 +28,14 @@ module RuboCop
|
|
|
28
28
|
|
|
29
29
|
private
|
|
30
30
|
|
|
31
|
+
def applies_to_current_ruby_version?
|
|
32
|
+
minimum_ruby_version = metadata['minimum_ruby_version']
|
|
33
|
+
|
|
34
|
+
return true unless minimum_ruby_version
|
|
35
|
+
|
|
36
|
+
config.target_ruby_version >= minimum_ruby_version
|
|
37
|
+
end
|
|
38
|
+
|
|
31
39
|
def alternative
|
|
32
40
|
metadata['alternative']
|
|
33
41
|
end
|
|
@@ -15,6 +15,8 @@ module RuboCop
|
|
|
15
15
|
'changed_parameters' => ChangedParameter,
|
|
16
16
|
'changed_enforced_styles' => ChangedEnforcedStyles
|
|
17
17
|
}.freeze
|
|
18
|
+
LOAD_RULES_CACHE = {} # rubocop:disable Style/MutableConstant
|
|
19
|
+
private_constant :LOAD_RULES_CACHE
|
|
18
20
|
|
|
19
21
|
attr_reader :rules, :warnings
|
|
20
22
|
|
|
@@ -48,16 +50,17 @@ module RuboCop
|
|
|
48
50
|
# Default rules for obsoletions are in config/obsoletion.yml
|
|
49
51
|
# Additional rules files can be added with `RuboCop::ConfigObsoletion.files << filename`
|
|
50
52
|
def load_rules # rubocop:disable Metrics/AbcSize
|
|
51
|
-
rules = self.class.files
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
rules = LOAD_RULES_CACHE[self.class.files] ||=
|
|
54
|
+
self.class.files.each_with_object({}) do |filename, hash|
|
|
55
|
+
hash.merge!(YAML.safe_load(File.read(filename))) do |_key, first, second|
|
|
56
|
+
case first
|
|
57
|
+
when Hash
|
|
58
|
+
first.merge(second)
|
|
59
|
+
when Array
|
|
60
|
+
first.concat(second)
|
|
61
|
+
end
|
|
58
62
|
end
|
|
59
63
|
end
|
|
60
|
-
end
|
|
61
64
|
|
|
62
65
|
cop_rules = rules.slice(*COP_RULE_CLASSES.keys)
|
|
63
66
|
parameter_rules = rules.slice(*PARAMETER_RULE_CLASSES.keys)
|
|
@@ -82,7 +82,9 @@ module RuboCop
|
|
|
82
82
|
node.array_type? && node.percent_literal?
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
percent_array.map(&:source_range).find
|
|
85
|
+
percent_array.map(&:source_range).find do |range|
|
|
86
|
+
offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
|
|
87
|
+
end
|
|
86
88
|
end
|
|
87
89
|
|
|
88
90
|
def range_of_first_line(range)
|
data/lib/rubocop/cop/base.rb
CHANGED
|
@@ -53,7 +53,7 @@ module RuboCop
|
|
|
53
53
|
# List of cops that should not try to autocorrect at the same
|
|
54
54
|
# time as this cop
|
|
55
55
|
#
|
|
56
|
-
# @return [Array<RuboCop::Cop::
|
|
56
|
+
# @return [Array<RuboCop::Cop::Base>]
|
|
57
57
|
#
|
|
58
58
|
# @api public
|
|
59
59
|
def self.autocorrect_incompatible_with
|
|
@@ -481,6 +481,12 @@ module RuboCop
|
|
|
481
481
|
range.end_pos + @current_offset
|
|
482
482
|
)
|
|
483
483
|
end
|
|
484
|
+
|
|
485
|
+
# This experimental feature has been under consideration for a while.
|
|
486
|
+
# @api private
|
|
487
|
+
def lsp_mode?
|
|
488
|
+
ARGV.include?('--lsp')
|
|
489
|
+
end
|
|
484
490
|
end
|
|
485
491
|
end
|
|
486
492
|
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Bundler
|
|
6
|
+
# A Gem group, or a set of groups, should be listed only once in a Gemfile.
|
|
7
|
+
#
|
|
8
|
+
# For example, if the values of `source`, `git`, `platforms`, or `path`
|
|
9
|
+
# surrounding `group` are different, no offense will be registered:
|
|
10
|
+
#
|
|
11
|
+
# [source,ruby]
|
|
12
|
+
# -----
|
|
13
|
+
# platforms :ruby do
|
|
14
|
+
# group :default do
|
|
15
|
+
# gem 'openssl'
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# platforms :jruby do
|
|
20
|
+
# group :default do
|
|
21
|
+
# gem 'jruby-openssl'
|
|
22
|
+
# end
|
|
23
|
+
# end
|
|
24
|
+
# -----
|
|
25
|
+
#
|
|
26
|
+
# @example
|
|
27
|
+
# # bad
|
|
28
|
+
# group :development do
|
|
29
|
+
# gem 'rubocop'
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
# group :development do
|
|
33
|
+
# gem 'rubocop-rails'
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
36
|
+
# # bad (same set of groups declared twice)
|
|
37
|
+
# group :development, :test do
|
|
38
|
+
# gem 'rubocop'
|
|
39
|
+
# end
|
|
40
|
+
#
|
|
41
|
+
# group :test, :development do
|
|
42
|
+
# gem 'rspec'
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# # good
|
|
46
|
+
# group :development do
|
|
47
|
+
# gem 'rubocop'
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# group :development, :test do
|
|
51
|
+
# gem 'rspec'
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# # good
|
|
55
|
+
# gem 'rubocop', groups: [:development, :test]
|
|
56
|
+
# gem 'rspec', groups: [:development, :test]
|
|
57
|
+
#
|
|
58
|
+
class DuplicatedGroup < Base
|
|
59
|
+
include RangeHelp
|
|
60
|
+
|
|
61
|
+
MSG = 'Gem group `%<group_name>s` already defined on line ' \
|
|
62
|
+
'%<line_of_first_occurrence>d of the Gemfile.'
|
|
63
|
+
SOURCE_BLOCK_NAMES = %i[source git platforms path].freeze
|
|
64
|
+
|
|
65
|
+
# @!method group_declarations(node)
|
|
66
|
+
def_node_search :group_declarations, '(send nil? :group ...)'
|
|
67
|
+
|
|
68
|
+
def on_new_investigation
|
|
69
|
+
return if processed_source.blank?
|
|
70
|
+
|
|
71
|
+
duplicated_group_nodes.each do |nodes|
|
|
72
|
+
nodes[1..].each do |node|
|
|
73
|
+
group_name = node.arguments.map(&:source).join(', ')
|
|
74
|
+
|
|
75
|
+
register_offense(node, group_name, nodes.first.first_line)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def duplicated_group_nodes
|
|
83
|
+
group_declarations = group_declarations(processed_source.ast)
|
|
84
|
+
group_keys = group_declarations.group_by do |node|
|
|
85
|
+
source_key = find_source_key(node)
|
|
86
|
+
group_attributes = group_attributes(node).sort.join
|
|
87
|
+
|
|
88
|
+
"#{source_key}#{group_attributes}"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
group_keys.values.select { |nodes| nodes.size > 1 }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def register_offense(node, group_name, line_of_first_occurrence)
|
|
95
|
+
line_range = node.loc.column...node.loc.last_column
|
|
96
|
+
offense_location = source_range(processed_source.buffer, node.first_line, line_range)
|
|
97
|
+
message = format(
|
|
98
|
+
MSG,
|
|
99
|
+
group_name: group_name,
|
|
100
|
+
line_of_first_occurrence: line_of_first_occurrence
|
|
101
|
+
)
|
|
102
|
+
add_offense(offense_location, message: message)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def find_source_key(node)
|
|
106
|
+
source_block = node.each_ancestor(:block).find do |block_node|
|
|
107
|
+
SOURCE_BLOCK_NAMES.include?(block_node.method_name)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
return unless source_block
|
|
111
|
+
|
|
112
|
+
"#{source_block.method_name}#{source_block.send_node.first_argument&.source}"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def group_attributes(node)
|
|
116
|
+
node.arguments.map do |argument|
|
|
117
|
+
if argument.hash_type?
|
|
118
|
+
argument.pairs.map(&:source).sort.join(', ')
|
|
119
|
+
else
|
|
120
|
+
argument.respond_to?(:value) ? argument.value.to_s : argument.source
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -161,9 +161,9 @@ module RuboCop
|
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
def gem_options(node)
|
|
164
|
-
return [] unless node.
|
|
164
|
+
return [] unless node.last_argument&.type == :hash
|
|
165
165
|
|
|
166
|
-
node.
|
|
166
|
+
node.last_argument.keys.map(&:value)
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
end
|
|
@@ -19,7 +19,15 @@ module RuboCop
|
|
|
19
19
|
#
|
|
20
20
|
# gem 'rspec'
|
|
21
21
|
#
|
|
22
|
-
#
|
|
22
|
+
# @example TreatCommentsAsGroupSeparators: true (default)
|
|
23
|
+
# # good
|
|
24
|
+
# # For code quality
|
|
25
|
+
# gem 'rubocop'
|
|
26
|
+
# # For tests
|
|
27
|
+
# gem 'rspec'
|
|
28
|
+
#
|
|
29
|
+
# @example TreatCommentsAsGroupSeparators: false
|
|
30
|
+
# # bad
|
|
23
31
|
# # For code quality
|
|
24
32
|
# gem 'rubocop'
|
|
25
33
|
# # For tests
|