rubocop 1.45.1 → 1.48.1
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 +1 -1
- data/config/default.yml +28 -9
- data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
- data/lib/rubocop/comment_config.rb +19 -0
- data/lib/rubocop/config.rb +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/base.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/cop_description.rb +4 -4
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +39 -0
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
- data/lib/rubocop/cop/layout/class_structure.rb +5 -3
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +4 -0
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +8 -2
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +11 -7
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
- data/lib/rubocop/cop/lint/debugger.rb +3 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
- data/lib/rubocop/cop/lint/else_layout.rb +1 -1
- data/lib/rubocop/cop/lint/empty_block.rb +1 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
- data/lib/rubocop/cop/lint/missing_super.rb +31 -2
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -9
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +6 -10
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +10 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
- data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
- data/lib/rubocop/cop/lint/script_permission.rb +1 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +4 -0
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +6 -2
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +10 -10
- data/lib/rubocop/cop/lint/useless_rescue.rb +6 -2
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +2 -2
- data/lib/rubocop/cop/migration/department_name.rb +1 -1
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/comments_help.rb +2 -2
- data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +10 -5
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
- data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
- data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -6
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
- data/lib/rubocop/cop/naming/method_name.rb +3 -3
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
- data/lib/rubocop/cop/registry.rb +3 -1
- data/lib/rubocop/cop/style/accessor_grouping.rb +39 -17
- data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
- data/lib/rubocop/cop/style/array_intersect.rb +1 -1
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +11 -2
- data/lib/rubocop/cop/style/case_like_if.rb +20 -3
- data/lib/rubocop/cop/style/collection_compact.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +6 -6
- data/lib/rubocop/cop/style/dir_empty.rb +60 -0
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +10 -4
- data/lib/rubocop/cop/style/documentation_method.rb +4 -4
- data/lib/rubocop/cop/style/each_with_object.rb +1 -1
- data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/file_empty.rb +71 -0
- data/lib/rubocop/cop/style/file_read.rb +1 -1
- data/lib/rubocop/cop/style/file_write.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +1 -1
- data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +76 -9
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
- data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/min_max.rb +3 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +12 -7
- data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
- data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
- data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +5 -6
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +10 -3
- data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
- data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -2
- data/lib/rubocop/cop/style/require_order.rb +1 -3
- data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
- data/lib/rubocop/cop/style/unpack_first.rb +3 -3
- data/lib/rubocop/cop/style/word_array.rb +17 -5
- data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
- data/lib/rubocop/cop/team.rb +11 -8
- data/lib/rubocop/cop/util.rb +13 -4
- data/lib/rubocop/cop/variable_force/variable.rb +5 -3
- data/lib/rubocop/directive_comment.rb +3 -3
- data/lib/rubocop/ext/comment.rb +18 -0
- data/lib/rubocop/formatter/junit_formatter.rb +4 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/server/core.rb +1 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +5 -0
- metadata +17 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39e28428d694fdd8cf940d5e3494f62a0266b3ffd41e823cf50131d16b45cf2a
|
4
|
+
data.tar.gz: 75eadde7a899742fcb5f08c4b3cd845658dd64087dd80c0dad1bda5fef30804a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21bba5ce4024ff5c66695c56e4261fbefdedc8b293396b8d0687f836d4a56d0f53ae307435cb714a3e4b059def785a1d9862504910f94fe1815223b6036b727b
|
7
|
+
data.tar.gz: aec136f1e174b57ba2ae6307a3fdeda0257614bcaaf77a6d5c5eca9733cfd185970dd998ecc95a6691d9aa8310419cd69679ba9b021f5b8284b9d12ef675dcc0
|
data/README.md
CHANGED
@@ -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.48', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -153,6 +153,7 @@ AllCops:
|
|
153
153
|
rubocop-sequel: [sequel]
|
154
154
|
rubocop-rake: [rake]
|
155
155
|
rubocop-graphql: [graphql]
|
156
|
+
rubocop-capybara: [capybara]
|
156
157
|
# Enable/Disable checking the methods extended by Active Support.
|
157
158
|
ActiveSupportExtensionsEnabled: false
|
158
159
|
|
@@ -1630,13 +1631,12 @@ Lint/Debugger:
|
|
1630
1631
|
Description: 'Check for debugger calls.'
|
1631
1632
|
Enabled: true
|
1632
1633
|
VersionAdded: '0.14'
|
1633
|
-
VersionChanged: '1.
|
1634
|
+
VersionChanged: '1.46'
|
1634
1635
|
DebuggerMethods:
|
1635
1636
|
# Groups are available so that a specific group can be disabled in
|
1636
1637
|
# a user's configuration, but are otherwise not significant.
|
1637
1638
|
Kernel:
|
1638
1639
|
- binding.irb
|
1639
|
-
- p
|
1640
1640
|
- Kernel.binding.irb
|
1641
1641
|
Byebug:
|
1642
1642
|
- byebug
|
@@ -1646,9 +1646,6 @@ Lint/Debugger:
|
|
1646
1646
|
Capybara:
|
1647
1647
|
- save_and_open_page
|
1648
1648
|
- save_and_open_screenshot
|
1649
|
-
PP:
|
1650
|
-
- PP.pp
|
1651
|
-
- pp
|
1652
1649
|
debug.rb:
|
1653
1650
|
- binding.b
|
1654
1651
|
- binding.break
|
@@ -1662,6 +1659,7 @@ Lint/Debugger:
|
|
1662
1659
|
- Kernel.binding.remote_pry
|
1663
1660
|
- Kernel.binding.pry_remote
|
1664
1661
|
- Pry.rescue
|
1662
|
+
- pry
|
1665
1663
|
Rails:
|
1666
1664
|
- debugger
|
1667
1665
|
- Kernel.debugger
|
@@ -2547,6 +2545,12 @@ Metrics/ClassLength:
|
|
2547
2545
|
Max: 100
|
2548
2546
|
CountAsOne: []
|
2549
2547
|
|
2548
|
+
Metrics/CollectionLiteralLength:
|
2549
|
+
Description: 'Checks for `Array` or `Hash` literals with many entries.'
|
2550
|
+
Enabled: pending
|
2551
|
+
VersionAdded: '1.47'
|
2552
|
+
LengthThreshold: 250
|
2553
|
+
|
2550
2554
|
# Avoid complex methods.
|
2551
2555
|
Metrics/CyclomaticComplexity:
|
2552
2556
|
Description: >-
|
@@ -2927,6 +2931,7 @@ Naming/VariableNumber:
|
|
2927
2931
|
- rfc822 # Time#rfc822
|
2928
2932
|
- rfc2822 # Time#rfc2822
|
2929
2933
|
- rfc3339 # DateTime.rfc3339
|
2934
|
+
- x86_64 # Allowed by default as an underscore separated CPU architecture name
|
2930
2935
|
AllowedPatterns: []
|
2931
2936
|
|
2932
2937
|
#################### Security ##############################
|
@@ -3054,6 +3059,7 @@ Style/ArrayCoercion:
|
|
3054
3059
|
Style/ArrayIntersect:
|
3055
3060
|
Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
|
3056
3061
|
Enabled: 'pending'
|
3062
|
+
Safe: false
|
3057
3063
|
VersionAdded: '1.40'
|
3058
3064
|
|
3059
3065
|
Style/ArrayJoin:
|
@@ -3256,6 +3262,9 @@ Style/CaseLikeIf:
|
|
3256
3262
|
Enabled: true
|
3257
3263
|
Safe: false
|
3258
3264
|
VersionAdded: '0.88'
|
3265
|
+
VersionChanged: '1.48'
|
3266
|
+
# `MinBranchesCount` defines the number of branches `if` needs to have to trigger this cop.
|
3267
|
+
MinBranchesCount: 3
|
3259
3268
|
|
3260
3269
|
Style/CharacterLiteral:
|
3261
3270
|
Description: 'Checks for uses of character literals.'
|
@@ -3522,6 +3531,12 @@ Style/Dir:
|
|
3522
3531
|
Enabled: true
|
3523
3532
|
VersionAdded: '0.50'
|
3524
3533
|
|
3534
|
+
Style/DirEmpty:
|
3535
|
+
Description: >-
|
3536
|
+
Prefer to use `Dir.empty?('path/to/dir')` when checking if a directory is empty.
|
3537
|
+
Enabled: pending
|
3538
|
+
VersionAdded: '1.48'
|
3539
|
+
|
3525
3540
|
Style/DisableCopsWithinSourceCodeDirective:
|
3526
3541
|
Description: >-
|
3527
3542
|
Forbids disabling/enabling cops within source code.
|
@@ -3717,6 +3732,14 @@ Style/FetchEnvVar:
|
|
3717
3732
|
# Environment variables to be excluded from the inspection.
|
3718
3733
|
AllowedVars: []
|
3719
3734
|
|
3735
|
+
Style/FileEmpty:
|
3736
|
+
Description: >-
|
3737
|
+
Prefer to use `File.empty?('path/to/file')` when checking if a file is empty.
|
3738
|
+
Enabled: pending
|
3739
|
+
Safe: false
|
3740
|
+
SafeAutoCorrect: false
|
3741
|
+
VersionAdded: '1.48'
|
3742
|
+
|
3720
3743
|
Style/FileRead:
|
3721
3744
|
Description: 'Favor `File.(bin)read` convenience methods.'
|
3722
3745
|
StyleGuide: '#file-read'
|
@@ -4027,10 +4050,6 @@ Style/InverseMethods:
|
|
4027
4050
|
:=~: :!~
|
4028
4051
|
:<: :>=
|
4029
4052
|
:>: :<=
|
4030
|
-
# `ActiveSupport` defines some common inverse methods. They are listed below,
|
4031
|
-
# and not enabled by default.
|
4032
|
-
# :present?: :blank?,
|
4033
|
-
# :include?: :exclude?
|
4034
4053
|
# `InverseBlocks` are methods that are inverted by inverting the return
|
4035
4054
|
# of the block that is passed to the method
|
4036
4055
|
InverseBlocks:
|
@@ -16,6 +16,7 @@ module RuboCop
|
|
16
16
|
|
17
17
|
PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
|
18
18
|
PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
|
19
|
+
PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
|
19
20
|
|
20
21
|
def run
|
21
22
|
add_formatter
|
@@ -31,6 +32,8 @@ module RuboCop
|
|
31
32
|
skip_line_length_cop(PHASE_1_DISABLED)
|
32
33
|
elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
|
33
34
|
skip_line_length_cop(PHASE_1_OVERRIDDEN)
|
35
|
+
elsif options_has_only_flag?
|
36
|
+
skip_line_length_cop(PHASE_1_SKIPPED)
|
34
37
|
else
|
35
38
|
run_line_length_cop
|
36
39
|
end
|
@@ -57,6 +60,10 @@ module RuboCop
|
|
57
60
|
config.for_cop('Layout/LineLength')
|
58
61
|
end
|
59
62
|
|
63
|
+
def options_has_only_flag?
|
64
|
+
@options[:only]
|
65
|
+
end
|
66
|
+
|
60
67
|
# Do an initial run with only Layout/LineLength so that cops that
|
61
68
|
# depend on Layout/LineLength:Max get the correct value for that
|
62
69
|
# parameter.
|
@@ -11,6 +11,8 @@ module RuboCop
|
|
11
11
|
# This class provides an API compatible with RuboCop::DirectiveComment
|
12
12
|
# to be used for cops that are disabled in the config file
|
13
13
|
class ConfigDisabledCopDirectiveComment
|
14
|
+
include RuboCop::Ext::Comment
|
15
|
+
|
14
16
|
attr_reader :text, :loc, :line_number
|
15
17
|
|
16
18
|
Loc = Struct.new(:expression)
|
@@ -42,6 +44,10 @@ module RuboCop
|
|
42
44
|
disabled_line_ranges.none? { |range| range.include?(line_number) }
|
43
45
|
end
|
44
46
|
|
47
|
+
def cop_opted_in?(cop)
|
48
|
+
opt_in_cops.include?(cop.cop_name)
|
49
|
+
end
|
50
|
+
|
45
51
|
def cop_disabled_line_ranges
|
46
52
|
@cop_disabled_line_ranges ||= analyze
|
47
53
|
end
|
@@ -74,6 +80,19 @@ module RuboCop
|
|
74
80
|
extras
|
75
81
|
end
|
76
82
|
|
83
|
+
def opt_in_cops
|
84
|
+
@opt_in_cops ||= begin
|
85
|
+
cops = Set.new
|
86
|
+
each_directive do |directive|
|
87
|
+
next unless directive.enabled?
|
88
|
+
next if directive.all_cops?
|
89
|
+
|
90
|
+
cops.merge(directive.cop_names)
|
91
|
+
end
|
92
|
+
cops
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
77
96
|
def analyze # rubocop:todo Metrics/AbcSize
|
78
97
|
return {} if @no_directives
|
79
98
|
|
data/lib/rubocop/config.rb
CHANGED
@@ -304,8 +304,8 @@ module RuboCop
|
|
304
304
|
end
|
305
305
|
|
306
306
|
def enable_cop?(qualified_cop_name, cop_options)
|
307
|
-
# If the cop is explicitly enabled
|
308
|
-
return true if cop_options['Enabled'] == true
|
307
|
+
# If the cop is explicitly enabled or `Lint/Syntax`, the other checks can be skipped.
|
308
|
+
return true if cop_options['Enabled'] == true || qualified_cop_name == 'Lint/Syntax'
|
309
309
|
|
310
310
|
department = department_of(qualified_cop_name)
|
311
311
|
cop_enabled = cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }
|
@@ -65,7 +65,7 @@ module RuboCop
|
|
65
65
|
heredoc_nodes = processed_source.ast.each_descendant.select do |node|
|
66
66
|
node.respond_to?(:heredoc?) && node.heredoc?
|
67
67
|
end
|
68
|
-
heredoc_nodes.map { |node| node.
|
68
|
+
heredoc_nodes.map { |node| node.source_range.join(node.loc.heredoc_end) }
|
69
69
|
.find { |range| range.contains?(offense_range) }
|
70
70
|
end
|
71
71
|
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -124,7 +124,7 @@ module RuboCop
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def preceding_comment?(node1, node2)
|
127
|
-
node1 && node2 && precede?(node2, node1) && comment_line?(node2.
|
127
|
+
node1 && node2 && precede?(node2, node1) && comment_line?(node2.source)
|
128
128
|
end
|
129
129
|
|
130
130
|
def ignored_gem?(node)
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
def to_range(node_or_range)
|
105
105
|
range = case node_or_range
|
106
106
|
when ::RuboCop::AST::Node, ::Parser::Source::Comment
|
107
|
-
node_or_range.
|
107
|
+
node_or_range.source_range
|
108
108
|
when ::Parser::Source::Range
|
109
109
|
node_or_range
|
110
110
|
else
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
return unless node
|
17
17
|
|
18
18
|
@processed_source = processed_source
|
19
|
-
expr = node.respond_to?(:loc) ? node.
|
19
|
+
expr = node.respond_to?(:loc) ? node.source_range : node
|
20
20
|
return if block_comment_within?(expr)
|
21
21
|
|
22
22
|
taboo_ranges = inside_string_ranges(node)
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
|
81
81
|
def block_comment_within?(expr)
|
82
82
|
processed_source.comments.select(&:document?).any? do |c|
|
83
|
-
within?(c.
|
83
|
+
within?(c.source_range, expr)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -35,15 +35,15 @@ module RuboCop
|
|
35
35
|
|
36
36
|
def offending_range
|
37
37
|
if block_node.arguments?
|
38
|
-
replacement_range(argument_node.
|
38
|
+
replacement_range(argument_node.source_range.end_pos)
|
39
39
|
else
|
40
40
|
replacement_range(block_node.loc.begin.end_pos)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def replacement_range(end_pos)
|
45
|
-
Parser::Source::Range.new(block_node.
|
46
|
-
block_node.
|
45
|
+
Parser::Source::Range.new(block_node.source_range.source_buffer,
|
46
|
+
block_node.source_range.begin_pos,
|
47
47
|
end_pos)
|
48
48
|
end
|
49
49
|
end
|
@@ -56,7 +56,7 @@ module RuboCop
|
|
56
56
|
if collection_node.begin_type?
|
57
57
|
collection_node.loc.end
|
58
58
|
else
|
59
|
-
collection_node.
|
59
|
+
collection_node.source_range
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -65,8 +65,8 @@ module RuboCop
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def replacement_range(end_pos)
|
68
|
-
Parser::Source::Range.new(for_node.
|
69
|
-
for_node.
|
68
|
+
Parser::Source::Range.new(for_node.source_range.source_buffer,
|
69
|
+
for_node.source_range.begin_pos,
|
70
70
|
end_pos)
|
71
71
|
end
|
72
72
|
end
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
def move_comment(eol_comment:, node:, corrector:)
|
36
36
|
return unless eol_comment
|
37
37
|
|
38
|
-
text = eol_comment.
|
38
|
+
text = eol_comment.source
|
39
39
|
corrector.insert_before(node, "#{text}\n#{' ' * node.loc.keyword.column}")
|
40
40
|
corrector.remove(eol_comment)
|
41
41
|
end
|
@@ -52,7 +52,7 @@ module RuboCop
|
|
52
52
|
return unless (parent = node.parent)
|
53
53
|
return unless use_heredoc_argument_method_chain?(parent)
|
54
54
|
|
55
|
-
chained_method = range_between(parent.loc.dot.begin_pos, parent.
|
55
|
+
chained_method = range_between(parent.loc.dot.begin_pos, parent.source_range.end_pos)
|
56
56
|
|
57
57
|
corrector.remove(chained_method)
|
58
58
|
corrector.insert_after(end_range, chained_method.source)
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
def select_content_to_be_inserted_after_last_element(corrector, node)
|
81
81
|
range = range_between(
|
82
82
|
node.loc.end.begin_pos,
|
83
|
-
range_by_whole_lines(node.
|
83
|
+
range_by_whole_lines(node.source_range).end.end_pos
|
84
84
|
)
|
85
85
|
|
86
86
|
remove_trailing_content_of_comment(corrector, range)
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
def declaration_with_comment(node)
|
27
27
|
buffer = processed_source.buffer
|
28
28
|
begin_pos = range_by_whole_lines(get_source_range(node, comments_as_separators)).begin_pos
|
29
|
-
end_line = buffer.line_for_position(node.
|
29
|
+
end_line = buffer.line_for_position(node.source_range.end_pos)
|
30
30
|
end_pos = range_by_whole_lines(buffer.line_range(end_line),
|
31
31
|
include_final_newline: true).end_pos
|
32
32
|
|
@@ -59,9 +59,9 @@ module RuboCop
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def range(node, comment_line)
|
62
|
-
source_buffer = node.
|
62
|
+
source_buffer = node.source_range.source_buffer
|
63
63
|
|
64
|
-
begin_pos = node.
|
64
|
+
begin_pos = node.source_range.begin_pos
|
65
65
|
begin_pos += comment_index(node, comment_line)
|
66
66
|
end_pos = begin_pos + comment_body(comment_line).length
|
67
67
|
|
@@ -77,7 +77,7 @@ module RuboCop
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def first_comment_line(node)
|
80
|
-
node.
|
80
|
+
node.source.lines.find { |line| comment_line?(line) }
|
81
81
|
end
|
82
82
|
|
83
83
|
def comment_body(comment_line)
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
86
86
|
|
87
87
|
def comment_index(node, comment_line)
|
88
88
|
body = comment_body(comment_line)
|
89
|
-
node.
|
89
|
+
node.source.index(body)
|
90
90
|
end
|
91
91
|
|
92
92
|
def relevant_file?(file)
|
@@ -92,7 +92,7 @@ module RuboCop
|
|
92
92
|
# @return [Parser::Source::Range]
|
93
93
|
def heredoc_openning_delimiter_range_from(node)
|
94
94
|
match_data = node.source.match(Heredoc::OPENING_DELIMITER)
|
95
|
-
node.
|
95
|
+
node.source_range.begin.adjust(
|
96
96
|
begin_pos: match_data.begin(2),
|
97
97
|
end_pos: match_data.end(2)
|
98
98
|
)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Enforces the use of `node.source_range` instead of `node.location.expression`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# node.location.expression
|
12
|
+
# node.loc.expression
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# node.source_range
|
16
|
+
#
|
17
|
+
class LocationExpression < Base
|
18
|
+
extend AutoCorrector
|
19
|
+
|
20
|
+
MSG = 'Use `source_range` instead.'
|
21
|
+
RESTRICT_ON_SEND = %i[loc location].freeze
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
return unless (parent = node.parent)
|
25
|
+
return unless parent.send_type? && parent.method?(:expression)
|
26
|
+
return unless parent.receiver.receiver
|
27
|
+
|
28
|
+
offense = node.loc.selector.join(parent.source_range.end)
|
29
|
+
|
30
|
+
add_offense(offense) do |corrector|
|
31
|
+
corrector.replace(offense, 'source_range')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -99,7 +99,7 @@ module RuboCop
|
|
99
99
|
# If the pattern matcher uses arguments (`%1`, `%2`, etc.), include them in the directive
|
100
100
|
arguments = pattern_arguments(node.arguments[1].source)
|
101
101
|
|
102
|
-
range = range_with_surrounding_space(node.
|
102
|
+
range = range_with_surrounding_space(node.source_range, side: :left, newlines: false)
|
103
103
|
indentation = range.source.match(/^\s*/)[0]
|
104
104
|
directive = "#{indentation}# @!method #{actual_name}(#{arguments.join(', ')})\n"
|
105
105
|
directive = "\n#{directive}" if add_newline?(node)
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
|
31
31
|
message = format(MSG, type: node_type)
|
32
32
|
add_offense(node, message: message) do |corrector|
|
33
|
-
range = node.
|
33
|
+
range = node.source_range.with(begin_pos: receiver.source_range.end_pos + 1)
|
34
34
|
corrector.replace(range, "#{node_type}_type?")
|
35
35
|
end
|
36
36
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Enforces the use of `processed_source.file_path` instead of `processed_source.buffer.name`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# processed_source.buffer.name
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# processed_source.file_path
|
15
|
+
#
|
16
|
+
class ProcessedSourceBufferName < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Use `file_path` instead.'
|
20
|
+
|
21
|
+
RESTRICT_ON_SEND = %i[name].freeze
|
22
|
+
|
23
|
+
# @!method processed_source_buffer_name?(node)
|
24
|
+
def_node_matcher :processed_source_buffer_name?, <<~PATTERN
|
25
|
+
(send
|
26
|
+
(send
|
27
|
+
{(lvar :processed_source) (send nil? :processed_source)} :buffer) :name)
|
28
|
+
PATTERN
|
29
|
+
|
30
|
+
def on_send(node)
|
31
|
+
return unless processed_source_buffer_name?(node)
|
32
|
+
|
33
|
+
offense_range = node.children.first.loc.selector.begin.join(node.source_range.end)
|
34
|
+
|
35
|
+
add_offense(offense_range) do |corrector|
|
36
|
+
corrector.replace(offense_range, 'file_path')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for redundant `source_range`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# node.source_range.source
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# node.source
|
15
|
+
#
|
16
|
+
class RedundantSourceRange < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Remove the redundant `source_range`.'
|
20
|
+
RESTRICT_ON_SEND = %i[source].freeze
|
21
|
+
|
22
|
+
# @!method redundant_source_range(node)
|
23
|
+
def_node_matcher :redundant_source_range, <<~PATTERN
|
24
|
+
(send $(send _ :source_range) :source)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
return unless (source_range = redundant_source_range(node))
|
29
|
+
|
30
|
+
selector = source_range.loc.selector
|
31
|
+
|
32
|
+
add_offense(selector) do |corrector|
|
33
|
+
corrector.remove(source_range.loc.dot.join(selector))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -7,6 +7,7 @@ require_relative 'internal_affairs/example_description'
|
|
7
7
|
require_relative 'internal_affairs/example_heredoc_delimiter'
|
8
8
|
require_relative 'internal_affairs/inherit_deprecated_cop_class'
|
9
9
|
require_relative 'internal_affairs/lambda_or_proc'
|
10
|
+
require_relative 'internal_affairs/location_expression'
|
10
11
|
require_relative 'internal_affairs/location_line_equality_comparison'
|
11
12
|
require_relative 'internal_affairs/method_name_end_with'
|
12
13
|
require_relative 'internal_affairs/method_name_equal'
|
@@ -15,12 +16,14 @@ require_relative 'internal_affairs/node_matcher_directive'
|
|
15
16
|
require_relative 'internal_affairs/node_type_predicate'
|
16
17
|
require_relative 'internal_affairs/numblock_handler'
|
17
18
|
require_relative 'internal_affairs/offense_location_keyword'
|
19
|
+
require_relative 'internal_affairs/processed_source_buffer_name'
|
18
20
|
require_relative 'internal_affairs/redundant_context_config_parameter'
|
19
21
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
20
22
|
require_relative 'internal_affairs/redundant_let_rubocop_config_new'
|
21
23
|
require_relative 'internal_affairs/redundant_location_argument'
|
22
24
|
require_relative 'internal_affairs/redundant_message_argument'
|
23
25
|
require_relative 'internal_affairs/redundant_method_dispatch_node'
|
26
|
+
require_relative 'internal_affairs/redundant_source_range'
|
24
27
|
require_relative 'internal_affairs/single_line_comparison'
|
25
28
|
require_relative 'internal_affairs/style_detected_api_use'
|
26
29
|
require_relative 'internal_affairs/undefined_config'
|
@@ -36,17 +36,19 @@ module RuboCop
|
|
36
36
|
# If the end is on its own line, there is no offense
|
37
37
|
return if begins_its_line?(node.loc.end)
|
38
38
|
|
39
|
-
|
39
|
+
offense_range = offense_range(node)
|
40
|
+
return if offense_range.source.lstrip.start_with?(';')
|
41
|
+
|
42
|
+
register_offense(node, offense_range)
|
40
43
|
end
|
41
44
|
|
42
45
|
alias on_numblock on_block
|
43
46
|
|
44
47
|
private
|
45
48
|
|
46
|
-
def register_offense(node)
|
49
|
+
def register_offense(node, offense_range)
|
47
50
|
add_offense(node.loc.end, message: message(node)) do |corrector|
|
48
|
-
|
49
|
-
replacement = replacement(node)
|
51
|
+
replacement = "\n#{offense_range.source.lstrip}"
|
50
52
|
|
51
53
|
if (heredoc = last_heredoc_argument(node.body))
|
52
54
|
corrector.remove(offense_range)
|
@@ -72,23 +74,7 @@ module RuboCop
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def offense_range(node)
|
75
|
-
|
76
|
-
node.loc.expression.source_buffer,
|
77
|
-
node.children.compact.last.loc.expression.end_pos,
|
78
|
-
end_of_method_chain(node).loc.expression.end_pos
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
def replacement(node)
|
83
|
-
end_with_method_chain = node.loc.end.join(end_of_method_chain(node).loc.expression.end)
|
84
|
-
|
85
|
-
"\n#{end_with_method_chain.source.strip}"
|
86
|
-
end
|
87
|
-
|
88
|
-
def end_of_method_chain(node)
|
89
|
-
return node unless node.parent&.call_type?
|
90
|
-
|
91
|
-
end_of_method_chain(node.parent)
|
77
|
+
node.children.compact.last.source_range.end.join(node.loc.end)
|
92
78
|
end
|
93
79
|
end
|
94
80
|
end
|