rubocop 1.31.2 → 1.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/config/default.yml +74 -16
- data/config/obsoletion.yml +23 -1
- data/lib/rubocop/cache_config.rb +29 -0
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +2 -2
- data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +53 -15
- data/lib/rubocop/cli.rb +1 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_finder.rb +68 -0
- data/lib/rubocop/config_loader.rb +12 -40
- data/lib/rubocop/config_loader_resolver.rb +1 -5
- data/lib/rubocop/config_obsoletion/changed_parameter.rb +5 -0
- data/lib/rubocop/config_obsoletion/parameter_rule.rb +4 -0
- data/lib/rubocop/config_obsoletion.rb +7 -2
- data/lib/rubocop/cop/cop.rb +1 -1
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +28 -0
- data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +61 -0
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +7 -1
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/block_end_newline.rb +33 -5
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +57 -13
- data/lib/rubocop/cop/layout/line_length.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -1
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +45 -0
- data/lib/rubocop/cop/legacy/corrections_proxy.rb +1 -1
- data/lib/rubocop/cop/legacy/corrector.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +26 -6
- data/lib/rubocop/cop/lint/debugger.rb +26 -16
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +10 -4
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +65 -1
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +55 -24
- data/lib/rubocop/cop/lint/number_conversion.rb +28 -6
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +7 -0
- data/lib/rubocop/cop/lint/require_range_parentheses.rb +57 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +35 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +15 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +9 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
- data/lib/rubocop/cop/metrics/block_length.rb +6 -6
- data/lib/rubocop/cop/metrics/method_length.rb +8 -7
- data/lib/rubocop/cop/mixin/allowed_methods.rb +15 -1
- data/lib/rubocop/cop/mixin/allowed_pattern.rb +9 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +4 -0
- data/lib/rubocop/cop/mixin/comments_help.rb +5 -1
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +4 -9
- data/lib/rubocop/cop/mixin/percent_array.rb +60 -1
- data/lib/rubocop/cop/mixin/range_help.rb +2 -2
- data/lib/rubocop/cop/naming/predicate_name.rb +30 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +26 -7
- data/lib/rubocop/cop/style/class_and_module_children.rb +4 -4
- data/lib/rubocop/cop/style/class_equality_comparison.rb +50 -3
- data/lib/rubocop/cop/style/double_negation.rb +2 -0
- data/lib/rubocop/cop/style/empty_else.rb +37 -0
- data/lib/rubocop/cop/style/empty_heredoc.rb +73 -0
- data/lib/rubocop/cop/style/fetch_env_var.rb +10 -177
- data/lib/rubocop/cop/style/format_string_token.rb +25 -6
- data/lib/rubocop/cop/style/hash_except.rb +0 -4
- data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +5 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -7
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +19 -2
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +9 -0
- data/lib/rubocop/cop/style/numeric_literals.rb +16 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +43 -9
- data/lib/rubocop/cop/style/redundant_condition.rb +19 -4
- data/lib/rubocop/cop/style/redundant_parentheses.rb +15 -22
- data/lib/rubocop/cop/style/redundant_sort.rb +21 -6
- data/lib/rubocop/cop/style/semicolon.rb +27 -3
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +14 -3
- data/lib/rubocop/cop/style/symbol_array.rb +2 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +40 -7
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -13
- data/lib/rubocop/cop/style/top_level_method_definition.rb +2 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -0
- data/lib/rubocop/cop/style/word_array.rb +2 -3
- data/lib/rubocop/ext/range.rb +15 -0
- data/lib/rubocop/feature_loader.rb +88 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/markdown_formatter.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/options.rb +3 -6
- data/lib/rubocop/result_cache.rb +22 -20
- data/lib/rubocop/rspec/shared_contexts.rb +14 -14
- data/lib/rubocop/rspec/support.rb +14 -0
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/server/cache.rb +33 -1
- data/lib/rubocop/server/cli.rb +19 -2
- data/lib/rubocop/server/client_command/base.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +5 -1
- metadata +16 -9
- data/lib/rubocop/cop/mixin/ignored_methods.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1c7a1f010764e941e11b523804a06d0fa77002769d763a4b1de81b459808c98
|
4
|
+
data.tar.gz: 28014c651859698a9a8fbdc122ba93159095f8a3182ac8bed497fbd9c2362c8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf155f34f4e1a5520a03668455234518417a154029bafa1f8ee43713fd83f3d1745267abff56fcb487ad8254653cf55bb3d902f93eef8cac5f31fc01430d2f9
|
7
|
+
data.tar.gz: 0f5349bb191f7a321136cfe349497b2e3edb847849039cc4d6a9b520332388cf2538e62ec65ab70fc8572dac8d354d276b8a77674562e7ddd54cefaa44a317d4
|
data/README.md
CHANGED
@@ -46,14 +46,14 @@ If you'd rather install RuboCop using `bundler`, add a line for it in your `Gemf
|
|
46
46
|
gem 'rubocop', require: false
|
47
47
|
```
|
48
48
|
|
49
|
-
RuboCop is stable between
|
49
|
+
RuboCop is stable between minor versions, both in terms of API and cop configuration.
|
50
50
|
We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop
|
51
51
|
releases. All big changes are reserved for major releases.
|
52
52
|
To prevent an unwanted RuboCop update you might want to use a conservative version lock
|
53
53
|
in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 1.
|
56
|
+
gem 'rubocop', '~> 1.34', 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
@@ -977,6 +977,11 @@ Layout/LineContinuationLeadingSpace:
|
|
977
977
|
AutoCorrect: false
|
978
978
|
SafeAutoCorrect: false
|
979
979
|
VersionAdded: '1.31'
|
980
|
+
VersionChanged: '1.32'
|
981
|
+
EnforcedStyle: trailing
|
982
|
+
SupportedStyles:
|
983
|
+
- leading
|
984
|
+
- trailing
|
980
985
|
|
981
986
|
Layout/LineContinuationSpacing:
|
982
987
|
Description: 'Checks the spacing in front of backslash in line continuations.'
|
@@ -1153,6 +1158,13 @@ Layout/MultilineMethodDefinitionBraceLayout:
|
|
1153
1158
|
- new_line
|
1154
1159
|
- same_line
|
1155
1160
|
|
1161
|
+
Layout/MultilineMethodParameterLineBreaks:
|
1162
|
+
Description: >-
|
1163
|
+
Checks that each parameter in a multi-line method definition
|
1164
|
+
starts on a separate line.
|
1165
|
+
Enabled: false
|
1166
|
+
VersionAdded: '1.32'
|
1167
|
+
|
1156
1168
|
Layout/MultilineOperationIndentation:
|
1157
1169
|
Description: >-
|
1158
1170
|
Checks indentation of binary operations that span more than
|
@@ -1490,7 +1502,9 @@ Lint/AmbiguousBlockAssociation:
|
|
1490
1502
|
Enabled: true
|
1491
1503
|
VersionAdded: '0.48'
|
1492
1504
|
VersionChanged: '1.13'
|
1493
|
-
|
1505
|
+
AllowedMethods: []
|
1506
|
+
AllowedPatterns: []
|
1507
|
+
IgnoredMethods: [] # deprecated
|
1494
1508
|
|
1495
1509
|
Lint/AmbiguousOperator:
|
1496
1510
|
Description: >-
|
@@ -1590,6 +1604,7 @@ Lint/Debugger:
|
|
1590
1604
|
# a user's configuration, but are otherwise not significant.
|
1591
1605
|
Kernel:
|
1592
1606
|
- binding.irb
|
1607
|
+
- Kernel.binding.irb
|
1593
1608
|
Byebug:
|
1594
1609
|
- byebug
|
1595
1610
|
- remote_byebug
|
@@ -1607,6 +1622,9 @@ Lint/Debugger:
|
|
1607
1622
|
- binding.pry
|
1608
1623
|
- binding.remote_pry
|
1609
1624
|
- binding.pry_remote
|
1625
|
+
- Kernel.binding.pry
|
1626
|
+
- Kernel.binding.remote_pry
|
1627
|
+
- Kernel.binding.pry_remote
|
1610
1628
|
- Pry.rescue
|
1611
1629
|
Rails:
|
1612
1630
|
- debugger
|
@@ -1739,8 +1757,10 @@ Lint/EmptyClass:
|
|
1739
1757
|
Lint/EmptyConditionalBody:
|
1740
1758
|
Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
|
1741
1759
|
Enabled: true
|
1760
|
+
SafeAutoCorrect: false
|
1742
1761
|
AllowComments: true
|
1743
1762
|
VersionAdded: '0.89'
|
1763
|
+
VersionChanged: '1.34'
|
1744
1764
|
|
1745
1765
|
Lint/EmptyEnsure:
|
1746
1766
|
Description: 'Checks for empty ensure block.'
|
@@ -1958,6 +1978,7 @@ Lint/NoReturnInBeginEndBlocks:
|
|
1958
1978
|
|
1959
1979
|
Lint/NonAtomicFileOperation:
|
1960
1980
|
Description: Checks for non-atomic file operations.
|
1981
|
+
StyleGuide: '#atomic-file-operations'
|
1961
1982
|
Enabled: pending
|
1962
1983
|
VersionAdded: '1.31'
|
1963
1984
|
SafeAutoCorrect: false
|
@@ -1979,7 +2000,9 @@ Lint/NumberConversion:
|
|
1979
2000
|
VersionAdded: '0.53'
|
1980
2001
|
VersionChanged: '1.1'
|
1981
2002
|
SafeAutoCorrect: false
|
1982
|
-
|
2003
|
+
AllowedMethods: []
|
2004
|
+
AllowedPatterns: []
|
2005
|
+
IgnoredMethods: [] # deprecated
|
1983
2006
|
IgnoredClasses:
|
1984
2007
|
- Time
|
1985
2008
|
- DateTime
|
@@ -2128,6 +2151,11 @@ Lint/RequireParentheses:
|
|
2128
2151
|
Enabled: true
|
2129
2152
|
VersionAdded: '0.18'
|
2130
2153
|
|
2154
|
+
Lint/RequireRangeParentheses:
|
2155
|
+
Description: 'Checks that a range literal is enclosed in parentheses when the end of the range is at a line break.'
|
2156
|
+
Enabled: pending
|
2157
|
+
VersionAdded: '1.32'
|
2158
|
+
|
2131
2159
|
Lint/RequireRelativeSelfPath:
|
2132
2160
|
Description: 'Checks for uses a file requiring itself with `require_relative`.'
|
2133
2161
|
Enabled: pending
|
@@ -2426,7 +2454,9 @@ Metrics/AbcSize:
|
|
2426
2454
|
VersionChanged: '1.5'
|
2427
2455
|
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
2428
2456
|
# a Float.
|
2429
|
-
|
2457
|
+
AllowedMethods: []
|
2458
|
+
AllowedPatterns: []
|
2459
|
+
IgnoredMethods: [] # deprecated
|
2430
2460
|
CountRepeatedAttributes: true
|
2431
2461
|
Max: 17
|
2432
2462
|
|
@@ -2439,10 +2469,12 @@ Metrics/BlockLength:
|
|
2439
2469
|
Max: 25
|
2440
2470
|
CountAsOne: []
|
2441
2471
|
ExcludedMethods: [] # deprecated, retained for backwards compatibility
|
2442
|
-
|
2472
|
+
AllowedMethods:
|
2443
2473
|
# By default, exclude the `#refine` method, as it tends to have larger
|
2444
2474
|
# associated blocks.
|
2445
2475
|
- refine
|
2476
|
+
AllowedPatterns: []
|
2477
|
+
IgnoredMethods: [] # deprecated
|
2446
2478
|
Exclude:
|
2447
2479
|
- '**/*.gemspec'
|
2448
2480
|
|
@@ -2472,7 +2504,9 @@ Metrics/CyclomaticComplexity:
|
|
2472
2504
|
Enabled: true
|
2473
2505
|
VersionAdded: '0.25'
|
2474
2506
|
VersionChanged: '0.81'
|
2475
|
-
|
2507
|
+
AllowedMethods: []
|
2508
|
+
AllowedPatterns: []
|
2509
|
+
IgnoredMethods: [] # deprecated
|
2476
2510
|
Max: 7
|
2477
2511
|
|
2478
2512
|
Metrics/MethodLength:
|
@@ -2485,7 +2519,9 @@ Metrics/MethodLength:
|
|
2485
2519
|
Max: 10
|
2486
2520
|
CountAsOne: []
|
2487
2521
|
ExcludedMethods: [] # deprecated, retained for backwards compatibility
|
2488
|
-
|
2522
|
+
AllowedMethods: []
|
2523
|
+
AllowedPatterns: []
|
2524
|
+
IgnoredMethods: [] # deprecated
|
2489
2525
|
|
2490
2526
|
Metrics/ModuleLength:
|
2491
2527
|
Description: 'Avoid modules longer than 100 lines of code.'
|
@@ -2513,7 +2549,9 @@ Metrics/PerceivedComplexity:
|
|
2513
2549
|
Enabled: true
|
2514
2550
|
VersionAdded: '0.25'
|
2515
2551
|
VersionChanged: '0.81'
|
2516
|
-
|
2552
|
+
AllowedMethods: []
|
2553
|
+
AllowedPatterns: []
|
2554
|
+
IgnoredMethods: [] # deprecated
|
2517
2555
|
Max: 8
|
2518
2556
|
|
2519
2557
|
################## Migration #############################
|
@@ -3044,7 +3082,7 @@ Style/BlockDelimiters:
|
|
3044
3082
|
# This looks at the usage of a block's method to determine its type (e.g. is
|
3045
3083
|
# the result of a `map` assigned to a variable or passed to another
|
3046
3084
|
# method) but exceptions are permitted in the `ProceduralMethods`,
|
3047
|
-
# `FunctionalMethods` and `
|
3085
|
+
# `FunctionalMethods` and `AllowedMethods` sections below.
|
3048
3086
|
- semantic
|
3049
3087
|
# The `braces_for_chaining` style enforces braces around single line blocks
|
3050
3088
|
# and do..end around multi-line blocks, except for multi-line blocks whose
|
@@ -3085,7 +3123,7 @@ Style/BlockDelimiters:
|
|
3085
3123
|
- let!
|
3086
3124
|
- subject
|
3087
3125
|
- watch
|
3088
|
-
|
3126
|
+
AllowedMethods:
|
3089
3127
|
# Methods that can be either procedural or functional and cannot be
|
3090
3128
|
# categorised from their usage alone, e.g.
|
3091
3129
|
#
|
@@ -3102,6 +3140,8 @@ Style/BlockDelimiters:
|
|
3102
3140
|
- lambda
|
3103
3141
|
- proc
|
3104
3142
|
- it
|
3143
|
+
AllowedPatterns: []
|
3144
|
+
IgnoredMethods: [] # deprecated
|
3105
3145
|
# The AllowBracesOnProceduralOneLiners option is ignored unless the
|
3106
3146
|
# EnforcedStyle is set to `semantic`. If so:
|
3107
3147
|
#
|
@@ -3205,10 +3245,12 @@ Style/ClassEqualityComparison:
|
|
3205
3245
|
StyleGuide: '#instance-of-vs-class-comparison'
|
3206
3246
|
Enabled: true
|
3207
3247
|
VersionAdded: '0.93'
|
3208
|
-
|
3248
|
+
AllowedMethods:
|
3209
3249
|
- ==
|
3210
3250
|
- equal?
|
3211
3251
|
- eql?
|
3252
|
+
AllowedPatterns: []
|
3253
|
+
IgnoredMethods: [] # deprecated
|
3212
3254
|
|
3213
3255
|
Style/ClassMethods:
|
3214
3256
|
Description: 'Use self when defining module/class methods.'
|
@@ -3495,6 +3537,12 @@ Style/EmptyElse:
|
|
3495
3537
|
- empty
|
3496
3538
|
- nil
|
3497
3539
|
- both
|
3540
|
+
AllowComments: false
|
3541
|
+
|
3542
|
+
Style/EmptyHeredoc:
|
3543
|
+
Description: 'Checks for using empty heredoc to reduce redundancy.'
|
3544
|
+
Enabled: pending
|
3545
|
+
VersionAdded: '1.32'
|
3498
3546
|
|
3499
3547
|
Style/EmptyLambdaParameter:
|
3500
3548
|
Description: 'Omit parens for empty lambda parameters.'
|
@@ -3664,7 +3712,9 @@ Style/FormatStringToken:
|
|
3664
3712
|
MaxUnannotatedPlaceholdersAllowed: 1
|
3665
3713
|
VersionAdded: '0.49'
|
3666
3714
|
VersionChanged: '1.0'
|
3667
|
-
|
3715
|
+
AllowedMethods: []
|
3716
|
+
AllowedPatterns: []
|
3717
|
+
IgnoredMethods: [] # deprecated
|
3668
3718
|
|
3669
3719
|
Style/FrozenStringLiteralComment:
|
3670
3720
|
Description: >-
|
@@ -3983,7 +4033,8 @@ Style/MethodCallWithArgsParentheses:
|
|
3983
4033
|
VersionAdded: '0.47'
|
3984
4034
|
VersionChanged: '1.7'
|
3985
4035
|
IgnoreMacros: true
|
3986
|
-
|
4036
|
+
AllowedMethods: []
|
4037
|
+
IgnoredMethods: [] # deprecated
|
3987
4038
|
AllowedPatterns: []
|
3988
4039
|
IgnoredPatterns: [] # deprecated
|
3989
4040
|
IncludedMacros: []
|
@@ -4000,7 +4051,9 @@ Style/MethodCallWithoutArgsParentheses:
|
|
4000
4051
|
Description: 'Do not use parentheses for method calls with no arguments.'
|
4001
4052
|
StyleGuide: '#method-invocation-parens'
|
4002
4053
|
Enabled: true
|
4003
|
-
|
4054
|
+
AllowedMethods: []
|
4055
|
+
AllowedPatterns: []
|
4056
|
+
IgnoredMethods: [] # deprecated
|
4004
4057
|
VersionAdded: '0.47'
|
4005
4058
|
VersionChanged: '0.55'
|
4006
4059
|
|
@@ -4352,6 +4405,7 @@ Style/NumericLiterals:
|
|
4352
4405
|
Strict: false
|
4353
4406
|
# You can specify allowed numbers. (e.g. port number 3000, 8080, and etc)
|
4354
4407
|
AllowedNumbers: []
|
4408
|
+
AllowedPatterns: []
|
4355
4409
|
|
4356
4410
|
Style/NumericPredicate:
|
4357
4411
|
Description: >-
|
@@ -4370,7 +4424,9 @@ Style/NumericPredicate:
|
|
4370
4424
|
SupportedStyles:
|
4371
4425
|
- predicate
|
4372
4426
|
- comparison
|
4373
|
-
|
4427
|
+
AllowedMethods: []
|
4428
|
+
AllowedPatterns: []
|
4429
|
+
IgnoredMethods: [] # deprecated
|
4374
4430
|
# Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
|
4375
4431
|
# false positives.
|
4376
4432
|
Exclude:
|
@@ -5007,11 +5063,13 @@ Style/SymbolProc:
|
|
5007
5063
|
VersionAdded: '0.26'
|
5008
5064
|
VersionChanged: '1.28'
|
5009
5065
|
AllowMethodsWithArguments: false
|
5010
|
-
# A list of method names to be
|
5066
|
+
# A list of method names to be always allowed by the check.
|
5011
5067
|
# The names should be fairly unique, otherwise you'll end up ignoring lots of code.
|
5012
|
-
|
5068
|
+
AllowedMethods:
|
5013
5069
|
- respond_to
|
5014
5070
|
- define_method
|
5071
|
+
AllowedPatterns: []
|
5072
|
+
IgnoredMethods: [] # deprecated
|
5015
5073
|
AllowComments: false
|
5016
5074
|
|
5017
5075
|
Style/TernaryParentheses:
|
data/config/obsoletion.yml
CHANGED
@@ -187,7 +187,9 @@ changed_parameters:
|
|
187
187
|
- Metrics/BlockLength
|
188
188
|
- Metrics/MethodLength
|
189
189
|
parameters: ExcludedMethods
|
190
|
-
|
190
|
+
alternatives:
|
191
|
+
- AllowedMethods
|
192
|
+
- AllowedPatterns
|
191
193
|
severity: warning
|
192
194
|
- cops: Lint/Debugger
|
193
195
|
parameters: DebuggerReceivers
|
@@ -202,6 +204,26 @@ changed_parameters:
|
|
202
204
|
parameters: IgnoredPatterns
|
203
205
|
alternative: AllowedPatterns
|
204
206
|
severity: warning
|
207
|
+
- cops:
|
208
|
+
- Lint/AmbiguousBlockAssociation
|
209
|
+
- Lint/NumberConversion
|
210
|
+
- Metrics/AbcSize
|
211
|
+
- Metrics/BlockLength
|
212
|
+
- Metrics/CyclomaticComplexity
|
213
|
+
- Metrics/MethodLength
|
214
|
+
- Metrics/PerceivedComplexity
|
215
|
+
- Style/BlockDelimiters
|
216
|
+
- Style/ClassEqualityComparison
|
217
|
+
- Style/FormatStringToken
|
218
|
+
- Style/MethodCallWithArgsParentheses
|
219
|
+
- Style/MethodCallWithoutArgsParentheses
|
220
|
+
- Style/NumericPredicate
|
221
|
+
- Style/SymbolLiteral
|
222
|
+
parameters: IgnoredMethods
|
223
|
+
alternatives:
|
224
|
+
- AllowedMethods
|
225
|
+
- AllowedPatterns
|
226
|
+
severity: warning
|
205
227
|
|
206
228
|
# Enforced styles that have been removed or replaced
|
207
229
|
changed_enforced_styles:
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This class represents the cache config of the caching RuboCop runs.
|
5
|
+
# @api private
|
6
|
+
class CacheConfig
|
7
|
+
def self.root_dir
|
8
|
+
root = ENV.fetch('RUBOCOP_CACHE_ROOT', nil)
|
9
|
+
root ||= yield
|
10
|
+
root ||= if ENV.key?('XDG_CACHE_HOME')
|
11
|
+
# Include user ID in the path to make sure the user has write
|
12
|
+
# access.
|
13
|
+
File.join(ENV.fetch('XDG_CACHE_HOME'), Process.uid.to_s)
|
14
|
+
else
|
15
|
+
# On FreeBSD, the /home path is a symbolic link to /usr/home
|
16
|
+
# and the $HOME environment variable returns the /home path.
|
17
|
+
#
|
18
|
+
# As $HOME is a built-in environment variable, FreeBSD users
|
19
|
+
# always get a warning message.
|
20
|
+
#
|
21
|
+
# To avoid raising warn log messages on FreeBSD, we retrieve
|
22
|
+
# the real path of the home folder.
|
23
|
+
File.join(File.realpath(Dir.home), '.cache')
|
24
|
+
end
|
25
|
+
|
26
|
+
File.join(root, 'rubocop_cache')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
def add_inheritance_from_auto_generated_file(config_file)
|
99
99
|
file_string = " #{relative_path_to_todo_from_options_config}"
|
100
100
|
|
101
|
-
config_file ||=
|
101
|
+
config_file ||= ConfigFinder::DOTFILE
|
102
102
|
|
103
103
|
if File.exist?(config_file)
|
104
104
|
files = Array(ConfigLoader.load_yaml_configuration(config_file)['inherit_from'])
|
@@ -113,7 +113,7 @@ module RuboCop
|
|
113
113
|
write_config_file(config_file, file_string, rubocop_yml_contents)
|
114
114
|
|
115
115
|
puts "Added inheritance from `#{relative_path_to_todo_from_options_config}` " \
|
116
|
-
"in `#{
|
116
|
+
"in `#{ConfigFinder::DOTFILE}`."
|
117
117
|
end
|
118
118
|
|
119
119
|
def existing_configuration(config_file)
|
@@ -17,20 +17,10 @@ module RuboCop
|
|
17
17
|
def run
|
18
18
|
return if skip? || extensions.none?
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
'RuboCop extension libraries might be helpful:'
|
23
|
-
|
24
|
-
extensions.sort.each do |extension|
|
25
|
-
puts " * #{extension} (https://rubygems.org/gems/#{extension})"
|
26
|
-
end
|
20
|
+
print_install_suggestions if not_installed_extensions.any?
|
21
|
+
print_load_suggestions if installed_and_not_loaded_extensions.any?
|
27
22
|
|
28
|
-
|
29
|
-
puts 'You can opt out of this message by adding the following to your config ' \
|
30
|
-
'(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \
|
31
|
-
'for more options):'
|
32
|
-
puts ' AllCops:'
|
33
|
-
puts ' SuggestExtensions: false'
|
23
|
+
print_opt_out_instruction
|
34
24
|
|
35
25
|
puts if @options[:display_time]
|
36
26
|
end
|
@@ -48,15 +38,63 @@ module RuboCop
|
|
48
38
|
!INCLUDED_FORMATTERS.include?(current_formatter)
|
49
39
|
end
|
50
40
|
|
41
|
+
def print_install_suggestions
|
42
|
+
puts
|
43
|
+
puts 'Tip: Based on detected gems, the following ' \
|
44
|
+
'RuboCop extension libraries might be helpful:'
|
45
|
+
|
46
|
+
not_installed_extensions.sort.each do |extension|
|
47
|
+
puts " * #{extension} (https://rubygems.org/gems/#{extension})"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_load_suggestions
|
52
|
+
puts
|
53
|
+
puts 'The following RuboCop extension libraries are installed but not loaded in config:'
|
54
|
+
|
55
|
+
installed_and_not_loaded_extensions.sort.each do |extension|
|
56
|
+
puts " * #{extension}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def print_opt_out_instruction
|
61
|
+
puts
|
62
|
+
puts 'You can opt out of this message by adding the following to your config ' \
|
63
|
+
'(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \
|
64
|
+
'for more options):'
|
65
|
+
puts ' AllCops:'
|
66
|
+
puts ' SuggestExtensions: false'
|
67
|
+
end
|
68
|
+
|
51
69
|
def current_formatter
|
52
70
|
@options[:format] || @config_store.for_pwd.for_all_cops['DefaultFormatter'] || 'p'
|
53
71
|
end
|
54
72
|
|
55
|
-
def
|
73
|
+
def all_extensions
|
56
74
|
return [] unless lockfile.dependencies.any?
|
57
75
|
|
58
76
|
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions'] || {}
|
59
|
-
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
|
77
|
+
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
|
78
|
+
end
|
79
|
+
|
80
|
+
def extensions
|
81
|
+
not_installed_extensions + installed_and_not_loaded_extensions
|
82
|
+
end
|
83
|
+
|
84
|
+
def installed_extensions
|
85
|
+
all_extensions & installed_gems
|
86
|
+
end
|
87
|
+
|
88
|
+
def not_installed_extensions
|
89
|
+
all_extensions - installed_gems
|
90
|
+
end
|
91
|
+
|
92
|
+
def loaded_extensions
|
93
|
+
@config_store.for_pwd.loaded_features.to_a
|
94
|
+
end
|
95
|
+
|
96
|
+
def installed_and_not_loaded_extensions
|
97
|
+
installed_extensions - loaded_extensions
|
60
98
|
end
|
61
99
|
|
62
100
|
def lockfile
|
data/lib/rubocop/cli.rb
CHANGED
@@ -12,6 +12,7 @@ module RuboCop
|
|
12
12
|
color debug display_style_guide display_time display_only_fail_level_offenses
|
13
13
|
display_only_failed except extra_details fail_level fix_layout format
|
14
14
|
ignore_disable_comments lint only only_guide_cops require safe
|
15
|
+
autocorrect safe_autocorrect autocorrect_all
|
15
16
|
].freeze
|
16
17
|
|
17
18
|
class Finished < StandardError; end
|
data/lib/rubocop/config.rb
CHANGED
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
@loaded_path = loaded_path
|
26
26
|
@for_cop = Hash.new do |h, cop|
|
27
27
|
qualified_cop_name = Cop::Registry.qualified_cop_name(cop, loaded_path)
|
28
|
-
cop_options = self[qualified_cop_name] || {}
|
28
|
+
cop_options = self[qualified_cop_name].dup || {}
|
29
29
|
cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
|
30
30
|
h[cop] = cop_options
|
31
31
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'file_finder'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
# This class has methods related to finding configuration path.
|
7
|
+
# @api private
|
8
|
+
class ConfigFinder
|
9
|
+
DOTFILE = '.rubocop.yml'
|
10
|
+
XDG_CONFIG = 'config.yml'
|
11
|
+
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
12
|
+
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
|
13
|
+
|
14
|
+
class << self
|
15
|
+
include FileFinder
|
16
|
+
|
17
|
+
attr_writer :project_root
|
18
|
+
|
19
|
+
def find_config_path(target_dir)
|
20
|
+
find_project_dotfile(target_dir) || find_user_dotfile || find_user_xdg_config ||
|
21
|
+
DEFAULT_FILE
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the path RuboCop inferred as the root of the project. No file
|
25
|
+
# searches will go past this directory.
|
26
|
+
def project_root
|
27
|
+
@project_root ||= find_project_root
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def find_project_root
|
33
|
+
pwd = Dir.pwd
|
34
|
+
gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd)
|
35
|
+
return unless gems_file
|
36
|
+
|
37
|
+
File.dirname(gems_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_project_dotfile(target_dir)
|
41
|
+
find_file_upwards(DOTFILE, target_dir, project_root)
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_user_dotfile
|
45
|
+
return unless ENV.key?('HOME')
|
46
|
+
|
47
|
+
file = File.join(Dir.home, DOTFILE)
|
48
|
+
|
49
|
+
return file if File.exist?(file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_user_xdg_config
|
53
|
+
xdg_config_home = expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
54
|
+
xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG)
|
55
|
+
|
56
|
+
return xdg_config if File.exist?(xdg_config)
|
57
|
+
end
|
58
|
+
|
59
|
+
def expand_path(path)
|
60
|
+
File.expand_path(path)
|
61
|
+
rescue ArgumentError
|
62
|
+
# Could happen because HOME or ID could not be determined. Fall back on
|
63
|
+
# using the path literally in that case.
|
64
|
+
path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'erb'
|
4
4
|
require 'yaml'
|
5
5
|
require 'pathname'
|
6
|
+
require_relative 'config_finder'
|
6
7
|
|
7
8
|
module RuboCop
|
8
9
|
# Raised when a RuboCop configuration file is not found.
|
@@ -15,8 +16,7 @@ module RuboCop
|
|
15
16
|
# during a run of the rubocop program, if files in several
|
16
17
|
# directories are inspected.
|
17
18
|
class ConfigLoader
|
18
|
-
DOTFILE =
|
19
|
-
XDG_CONFIG = 'config.yml'
|
19
|
+
DOTFILE = ConfigFinder::DOTFILE
|
20
20
|
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
21
21
|
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
|
22
22
|
|
@@ -25,7 +25,7 @@ module RuboCop
|
|
25
25
|
|
26
26
|
attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
|
27
27
|
:ignore_unrecognized_cops
|
28
|
-
attr_writer :default_configuration
|
28
|
+
attr_writer :default_configuration
|
29
29
|
attr_reader :loaded_features
|
30
30
|
|
31
31
|
alias debug? debug
|
@@ -95,8 +95,7 @@ module RuboCop
|
|
95
95
|
# user's home directory is checked. If there's no .rubocop.yml
|
96
96
|
# there either, the path to the default file is returned.
|
97
97
|
def configuration_file_for(target_dir)
|
98
|
-
|
99
|
-
find_user_xdg_config || DEFAULT_FILE
|
98
|
+
ConfigFinder.find_config_path(target_dir)
|
100
99
|
end
|
101
100
|
|
102
101
|
def configuration_from_file(config_file, check: true)
|
@@ -122,7 +121,7 @@ module RuboCop
|
|
122
121
|
end
|
123
122
|
|
124
123
|
def add_excludes_from_files(config, config_file)
|
125
|
-
exclusion_file = find_last_file_upwards(DOTFILE, config_file, project_root)
|
124
|
+
exclusion_file = find_last_file_upwards(DOTFILE, config_file, ConfigFinder.project_root)
|
126
125
|
|
127
126
|
return unless exclusion_file
|
128
127
|
return if PathUtil.relative_path(exclusion_file) == PathUtil.relative_path(config_file)
|
@@ -140,8 +139,14 @@ module RuboCop
|
|
140
139
|
|
141
140
|
# Returns the path RuboCop inferred as the root of the project. No file
|
142
141
|
# searches will go past this directory.
|
142
|
+
# @deprecated Use `RuboCop::ConfigFinder.project_root` instead.
|
143
143
|
def project_root
|
144
|
-
|
144
|
+
warn Rainbow(<<~WARNING).yellow
|
145
|
+
`RuboCop::ConfigLoader.project_root` is deprecated and will be removed in RuboCop 2.0. \
|
146
|
+
Use `RuboCop::ConfigFinder.project_root` instead.
|
147
|
+
WARNING
|
148
|
+
|
149
|
+
ConfigFinder.project_root
|
145
150
|
end
|
146
151
|
|
147
152
|
PENDING_BANNER = <<~BANNER
|
@@ -187,39 +192,6 @@ module RuboCop
|
|
187
192
|
File.absolute_path(file.is_a?(RemoteConfig) ? file.file : file)
|
188
193
|
end
|
189
194
|
|
190
|
-
def find_project_dotfile(target_dir)
|
191
|
-
find_file_upwards(DOTFILE, target_dir, project_root)
|
192
|
-
end
|
193
|
-
|
194
|
-
def find_project_root
|
195
|
-
pwd = Dir.pwd
|
196
|
-
gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd)
|
197
|
-
return unless gems_file
|
198
|
-
|
199
|
-
File.dirname(gems_file)
|
200
|
-
end
|
201
|
-
|
202
|
-
def find_user_dotfile
|
203
|
-
return unless ENV.key?('HOME')
|
204
|
-
|
205
|
-
file = File.join(Dir.home, DOTFILE)
|
206
|
-
return file if File.exist?(file)
|
207
|
-
end
|
208
|
-
|
209
|
-
def find_user_xdg_config
|
210
|
-
xdg_config_home = expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
|
211
|
-
xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG)
|
212
|
-
return xdg_config if File.exist?(xdg_config)
|
213
|
-
end
|
214
|
-
|
215
|
-
def expand_path(path)
|
216
|
-
File.expand_path(path)
|
217
|
-
rescue ArgumentError
|
218
|
-
# Could happen because HOME or ID could not be determined. Fall back on
|
219
|
-
# using the path literally in that case.
|
220
|
-
path
|
221
|
-
end
|
222
|
-
|
223
195
|
def resolver
|
224
196
|
@resolver ||= ConfigLoaderResolver.new
|
225
197
|
end
|
@@ -11,11 +11,7 @@ module RuboCop
|
|
11
11
|
config_dir = File.dirname(path)
|
12
12
|
hash.delete('require').tap do |loaded_features|
|
13
13
|
Array(loaded_features).each do |feature|
|
14
|
-
|
15
|
-
require(File.join(config_dir, feature))
|
16
|
-
else
|
17
|
-
require(feature)
|
18
|
-
end
|
14
|
+
FeatureLoader.load(config_directory_path: config_dir, feature: feature)
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|