rubocop 1.3.0 → 1.5.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 +1 -1
- data/config/default.yml +75 -16
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cli.rb +5 -1
- data/lib/rubocop/cli/command/execute_runner.rb +26 -11
- data/lib/rubocop/cli/command/suggest_extensions.rb +67 -0
- data/lib/rubocop/config_loader.rb +12 -4
- data/lib/rubocop/config_loader_resolver.rb +5 -1
- data/lib/rubocop/config_obsoletion.rb +21 -3
- data/lib/rubocop/config_regeneration.rb +1 -1
- data/lib/rubocop/config_validator.rb +8 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +21 -6
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/generator.rb +2 -9
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +15 -3
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +80 -10
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +6 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +5 -5
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -1
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +4 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/missing_super.rb +7 -4
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +1 -1
- data/lib/rubocop/cop/lint/to_enum_arguments.rb +6 -15
- data/lib/rubocop/cop/lint/unexpected_block_arity.rb +85 -0
- data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +20 -6
- data/lib/rubocop/cop/metrics/abc_size.rb +25 -1
- data/lib/rubocop/cop/metrics/block_length.rb +13 -7
- data/lib/rubocop/cop/metrics/method_length.rb +7 -2
- data/lib/rubocop/cop/metrics/parameter_lists.rb +64 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +20 -10
- data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +146 -0
- data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +6 -1
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +4 -3
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +9 -1
- data/lib/rubocop/cop/mixin/ignored_methods.rb +36 -3
- data/lib/rubocop/cop/mixin/method_complexity.rb +6 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/visibility_help.rb +1 -3
- data/lib/rubocop/cop/style/and_or.rb +10 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +8 -3
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +8 -1
- data/lib/rubocop/cop/style/documentation.rb +12 -1
- data/lib/rubocop/cop/style/format_string.rb +8 -3
- data/lib/rubocop/cop/style/if_with_semicolon.rb +39 -4
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -2
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +3 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +14 -11
- data/lib/rubocop/cop/style/redundant_argument.rb +75 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +49 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +5 -3
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/scope.rb +1 -1
- data/lib/rubocop/core_ext/hash.rb +20 -0
- data/lib/rubocop/ext/regexp_node.rb +5 -10
- data/lib/rubocop/ext/regexp_parser.rb +2 -9
- data/lib/rubocop/formatter/disabled_config_formatter.rb +21 -6
- data/lib/rubocop/options.rb +5 -0
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/target_ruby.rb +12 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -10
- data/bin/console +0 -10
- data/bin/rubocop-profile +0 -32
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ce46e11fac05ae40731d9a49b0c4229aa719d395a3f946b294965c52513ad1b
|
4
|
+
data.tar.gz: 56c6f908f370d96d011287d67172e41c9a8a3a21748fb04d5235d0f957ffd64f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58d45c385e3fcccee94a8c258dd9536fb768c8ae069201411bb22f3c33dac0806b1d177f7f5562a27b71ae25ab3896917c06c29703c1f1c7d276506442069c6
|
7
|
+
data.tar.gz: ca55f537a662481c1337f6301d162074138c76a36c3332715aa2304ef2b67363df4b026ec1aa4dabe6e9c6b7833c0ed48edca99ea249a152a6a563a6242beeac
|
data/README.md
CHANGED
@@ -51,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
51
51
|
in your `Gemfile`:
|
52
52
|
|
53
53
|
```rb
|
54
|
-
gem 'rubocop', '~> 1.
|
54
|
+
gem 'rubocop', '~> 1.5', require: false
|
55
55
|
```
|
56
56
|
|
57
57
|
See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -139,6 +139,16 @@ AllCops:
|
|
139
139
|
# from the lock file.) If the Ruby version is still unresolved, RuboCop will
|
140
140
|
# use the oldest officially supported Ruby version (currently Ruby 2.4).
|
141
141
|
TargetRubyVersion: ~
|
142
|
+
# Determines if a notification for extension libraries should be shown when
|
143
|
+
# rubocop is run. Keys are the name of the extension, and values are an array
|
144
|
+
# of gems in the Gemfile that the extension is suggested for, if not already
|
145
|
+
# included.
|
146
|
+
SuggestExtensions:
|
147
|
+
rubocop-rails: [rails]
|
148
|
+
rubocop-rspec: [rspec, rspec-rails]
|
149
|
+
rubocop-minitest: [minitest]
|
150
|
+
rubocop-sequel: [sequel]
|
151
|
+
rubocop-rake: [rake]
|
142
152
|
|
143
153
|
#################### Bundler ###############################
|
144
154
|
|
@@ -459,10 +469,14 @@ Layout/EmptyLineAfterMultilineCondition:
|
|
459
469
|
- https://github.com/airbnb/ruby#multiline-if-newline
|
460
470
|
|
461
471
|
Layout/EmptyLineBetweenDefs:
|
462
|
-
Description: 'Use empty lines between defs.'
|
472
|
+
Description: 'Use empty lines between class/module/method defs.'
|
463
473
|
StyleGuide: '#empty-lines-between-methods'
|
464
474
|
Enabled: true
|
465
475
|
VersionAdded: '0.49'
|
476
|
+
VersionChanged: '1.4'
|
477
|
+
EmptyLineBetweenMethodDefs: true
|
478
|
+
EmptyLineBetweenClassDefs: true
|
479
|
+
EmptyLineBetweenModuleDefs: true
|
466
480
|
# If `true`, this parameter means that single line method definitions don't
|
467
481
|
# need an empty line between them.
|
468
482
|
AllowAdjacentOneLineDefs: false
|
@@ -891,8 +905,8 @@ Layout/LineLength:
|
|
891
905
|
StyleGuide: '#max-line-length'
|
892
906
|
Enabled: true
|
893
907
|
VersionAdded: '0.25'
|
894
|
-
VersionChanged: '1.
|
895
|
-
AutoCorrect:
|
908
|
+
VersionChanged: '1.4'
|
909
|
+
AutoCorrect: true
|
896
910
|
Max: 120
|
897
911
|
# To make it possible to copy or click on URIs in the code, we allow lines
|
898
912
|
# containing a URI to be longer than Max.
|
@@ -1176,7 +1190,7 @@ Layout/SpaceBeforeBlockBraces:
|
|
1176
1190
|
SupportedStylesForEmptyBraces:
|
1177
1191
|
- space
|
1178
1192
|
- no_space
|
1179
|
-
VersionChanged: '0.52
|
1193
|
+
VersionChanged: '0.52'
|
1180
1194
|
|
1181
1195
|
Layout/SpaceBeforeComma:
|
1182
1196
|
Description: 'No spaces before commas.'
|
@@ -1401,7 +1415,10 @@ Lint/ConstantDefinitionInBlock:
|
|
1401
1415
|
Enabled: true
|
1402
1416
|
VersionAdded: '0.91'
|
1403
1417
|
VersionChanged: '1.3'
|
1404
|
-
|
1418
|
+
# `enums` for Typed Enums via T::Enum in Sorbet.
|
1419
|
+
# https://sorbet.org/docs/tenum
|
1420
|
+
AllowedMethods:
|
1421
|
+
- enums
|
1405
1422
|
|
1406
1423
|
Lint/ConstantResolution:
|
1407
1424
|
Description: 'Check that constants are fully qualified with `::`.'
|
@@ -1681,6 +1698,7 @@ Lint/MissingSuper:
|
|
1681
1698
|
without calls to `super`'.
|
1682
1699
|
Enabled: true
|
1683
1700
|
VersionAdded: '0.89'
|
1701
|
+
VersionChanged: '1.4'
|
1684
1702
|
|
1685
1703
|
Lint/MixedRegexpCaptureTypes:
|
1686
1704
|
Description: 'Do not mix named captures and numbered captures in a Regexp literal.'
|
@@ -1862,7 +1880,7 @@ Lint/RescueException:
|
|
1862
1880
|
StyleGuide: '#no-blind-rescues'
|
1863
1881
|
Enabled: true
|
1864
1882
|
VersionAdded: '0.9'
|
1865
|
-
VersionChanged: '0.27
|
1883
|
+
VersionChanged: '0.27'
|
1866
1884
|
|
1867
1885
|
Lint/RescueType:
|
1868
1886
|
Description: 'Avoid rescuing from non constants that could result in a `TypeError`.'
|
@@ -1990,6 +2008,23 @@ Lint/UnderscorePrefixedVariableName:
|
|
1990
2008
|
VersionAdded: '0.21'
|
1991
2009
|
AllowKeywordBlockArguments: false
|
1992
2010
|
|
2011
|
+
Lint/UnexpectedBlockArity:
|
2012
|
+
Description: 'Looks for blocks that have fewer arguments that the calling method expects.'
|
2013
|
+
Enabled: pending
|
2014
|
+
Safe: false
|
2015
|
+
VersionAdded: '1.5'
|
2016
|
+
Methods:
|
2017
|
+
chunk_while: 2
|
2018
|
+
each_with_index: 2
|
2019
|
+
each_with_object: 2
|
2020
|
+
inject: 2
|
2021
|
+
max: 2
|
2022
|
+
min: 2
|
2023
|
+
minmax: 2
|
2024
|
+
reduce: 2
|
2025
|
+
slice_when: 2
|
2026
|
+
sort: 2
|
2027
|
+
|
1993
2028
|
Lint/UnifiedInteger:
|
1994
2029
|
Description: 'Use Integer instead of Fixnum or Bignum.'
|
1995
2030
|
Enabled: true
|
@@ -1999,6 +2034,7 @@ Lint/UnmodifiedReduceAccumulator:
|
|
1999
2034
|
Description: Checks for `reduce` or `inject` blocks that do not update the accumulator each iteration.
|
2000
2035
|
Enabled: pending
|
2001
2036
|
VersionAdded: '1.1'
|
2037
|
+
VersionChanged: '1.5'
|
2002
2038
|
|
2003
2039
|
Lint/UnreachableCode:
|
2004
2040
|
Description: 'Unreachable code.'
|
@@ -2102,21 +2138,23 @@ Metrics/AbcSize:
|
|
2102
2138
|
- https://en.wikipedia.org/wiki/ABC_Software_Metric
|
2103
2139
|
Enabled: true
|
2104
2140
|
VersionAdded: '0.27'
|
2105
|
-
VersionChanged: '
|
2141
|
+
VersionChanged: '1.5'
|
2106
2142
|
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
2107
2143
|
# a Float.
|
2108
2144
|
IgnoredMethods: []
|
2145
|
+
CountRepeatedAttributes: true
|
2109
2146
|
Max: 17
|
2110
2147
|
|
2111
2148
|
Metrics/BlockLength:
|
2112
2149
|
Description: 'Avoid long blocks with many lines.'
|
2113
2150
|
Enabled: true
|
2114
2151
|
VersionAdded: '0.44'
|
2115
|
-
VersionChanged: '
|
2152
|
+
VersionChanged: '1.5'
|
2116
2153
|
CountComments: false # count full line comments?
|
2117
2154
|
Max: 25
|
2118
2155
|
CountAsOne: []
|
2119
|
-
ExcludedMethods:
|
2156
|
+
ExcludedMethods: [] # deprecated, retained for backwards compatibility
|
2157
|
+
IgnoredMethods:
|
2120
2158
|
# By default, exclude the `#refine` method, as it tends to have larger
|
2121
2159
|
# associated blocks.
|
2122
2160
|
- refine
|
@@ -2157,11 +2195,12 @@ Metrics/MethodLength:
|
|
2157
2195
|
StyleGuide: '#short-methods'
|
2158
2196
|
Enabled: true
|
2159
2197
|
VersionAdded: '0.25'
|
2160
|
-
VersionChanged: '
|
2198
|
+
VersionChanged: '1.5'
|
2161
2199
|
CountComments: false # count full line comments?
|
2162
2200
|
Max: 10
|
2163
2201
|
CountAsOne: []
|
2164
|
-
ExcludedMethods: []
|
2202
|
+
ExcludedMethods: [] # deprecated, retained for backwards compatibility
|
2203
|
+
IgnoredMethods: []
|
2165
2204
|
|
2166
2205
|
Metrics/ModuleLength:
|
2167
2206
|
Description: 'Avoid modules longer than 100 lines of code.'
|
@@ -2177,8 +2216,10 @@ Metrics/ParameterLists:
|
|
2177
2216
|
StyleGuide: '#too-many-params'
|
2178
2217
|
Enabled: true
|
2179
2218
|
VersionAdded: '0.25'
|
2219
|
+
VersionChanged: '1.5'
|
2180
2220
|
Max: 5
|
2181
2221
|
CountKeywordArgs: true
|
2222
|
+
MaxOptionalParameters: 3
|
2182
2223
|
|
2183
2224
|
Metrics/PerceivedComplexity:
|
2184
2225
|
Description: >-
|
@@ -2448,7 +2489,7 @@ Naming/VariableNumber:
|
|
2448
2489
|
StyleGuide: '#snake-case-symbols-methods-vars-with-numbers'
|
2449
2490
|
Enabled: true
|
2450
2491
|
VersionAdded: '0.50'
|
2451
|
-
VersionChanged: '1.
|
2492
|
+
VersionChanged: '1.4'
|
2452
2493
|
EnforcedStyle: normalcase
|
2453
2494
|
SupportedStyles:
|
2454
2495
|
- snake_case
|
@@ -2456,7 +2497,13 @@ Naming/VariableNumber:
|
|
2456
2497
|
- non_integer
|
2457
2498
|
CheckMethodNames: true
|
2458
2499
|
CheckSymbols: true
|
2459
|
-
AllowedIdentifiers:
|
2500
|
+
AllowedIdentifiers:
|
2501
|
+
- capture3 # Open3.capture3
|
2502
|
+
- iso8601 # Time#iso8601
|
2503
|
+
- rfc1123_date # CGI.rfc1123_date
|
2504
|
+
- rfc822 # Time#rfc822
|
2505
|
+
- rfc2822 # Time#rfc2822
|
2506
|
+
- rfc3339 # DateTime.rfc3339
|
2460
2507
|
|
2461
2508
|
#################### Security ##############################
|
2462
2509
|
|
@@ -3917,7 +3964,7 @@ Style/PercentLiteralDelimiters:
|
|
3917
3964
|
'%r': '{}'
|
3918
3965
|
'%w': '[]'
|
3919
3966
|
'%W': '[]'
|
3920
|
-
VersionChanged: '0.48
|
3967
|
+
VersionChanged: '0.48'
|
3921
3968
|
|
3922
3969
|
Style/PercentQLiterals:
|
3923
3970
|
Description: 'Checks if uses of %Q/%q match the configured preference.'
|
@@ -3973,6 +4020,17 @@ Style/RandomWithOffset:
|
|
3973
4020
|
Enabled: true
|
3974
4021
|
VersionAdded: '0.52'
|
3975
4022
|
|
4023
|
+
Style/RedundantArgument:
|
4024
|
+
Description: 'Check for a redundant argument passed to certain methods.'
|
4025
|
+
Enabled: pending
|
4026
|
+
Safe: false
|
4027
|
+
VersionAdded: '1.4'
|
4028
|
+
Methods:
|
4029
|
+
# Array#join
|
4030
|
+
join: ''
|
4031
|
+
# String#split
|
4032
|
+
split: ' '
|
4033
|
+
|
3976
4034
|
Style/RedundantAssignment:
|
3977
4035
|
Description: 'Checks for redundant assignment before returning.'
|
3978
4036
|
Enabled: true
|
@@ -4243,6 +4301,7 @@ Style/SoleNestedConditional:
|
|
4243
4301
|
which can be merged into outer conditional node.
|
4244
4302
|
Enabled: true
|
4245
4303
|
VersionAdded: '0.89'
|
4304
|
+
VersionChanged: '1.5'
|
4246
4305
|
AllowModifier: false
|
4247
4306
|
|
4248
4307
|
Style/SpecialGlobalVars:
|
@@ -4324,7 +4383,7 @@ Style/StringMethods:
|
|
4324
4383
|
Description: 'Checks if configured preferred methods are used over non-preferred.'
|
4325
4384
|
Enabled: false
|
4326
4385
|
VersionAdded: '0.34'
|
4327
|
-
VersionChanged: '0.34
|
4386
|
+
VersionChanged: '0.34'
|
4328
4387
|
# Mapping from undesired method to desired_method
|
4329
4388
|
# e.g. to use `to_sym` over `intern`:
|
4330
4389
|
#
|
@@ -4375,7 +4434,7 @@ Style/SymbolProc:
|
|
4375
4434
|
Enabled: true
|
4376
4435
|
Safe: false
|
4377
4436
|
VersionAdded: '0.26'
|
4378
|
-
VersionChanged: '
|
4437
|
+
VersionChanged: '1.5'
|
4379
4438
|
# A list of method names to be ignored by the check.
|
4380
4439
|
# The names should be fairly unique, otherwise you'll end up ignoring lots of code.
|
4381
4440
|
IgnoredMethods:
|
data/lib/rubocop.rb
CHANGED
@@ -18,6 +18,7 @@ require_relative 'rubocop/ext/regexp_node'
|
|
18
18
|
require_relative 'rubocop/ext/regexp_parser'
|
19
19
|
|
20
20
|
require_relative 'rubocop/core_ext/string'
|
21
|
+
require_relative 'rubocop/core_ext/hash'
|
21
22
|
require_relative 'rubocop/ext/processed_source'
|
22
23
|
|
23
24
|
require_relative 'rubocop/path_util'
|
@@ -88,6 +89,7 @@ require_relative 'rubocop/cop/mixin/interpolation'
|
|
88
89
|
require_relative 'rubocop/cop/mixin/line_length_help'
|
89
90
|
require_relative 'rubocop/cop/mixin/match_range'
|
90
91
|
require_relative 'rubocop/cop/metrics/utils/repeated_csend_discount'
|
92
|
+
require_relative 'rubocop/cop/metrics/utils/repeated_attribute_discount'
|
91
93
|
require_relative 'rubocop/cop/mixin/method_complexity'
|
92
94
|
require_relative 'rubocop/cop/mixin/method_preference'
|
93
95
|
require_relative 'rubocop/cop/mixin/min_body_length'
|
@@ -341,6 +343,7 @@ require_relative 'rubocop/cop/lint/to_json'
|
|
341
343
|
require_relative 'rubocop/cop/lint/top_level_return_with_argument'
|
342
344
|
require_relative 'rubocop/cop/lint/trailing_comma_in_attribute_declaration'
|
343
345
|
require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
|
346
|
+
require_relative 'rubocop/cop/lint/unexpected_block_arity'
|
344
347
|
require_relative 'rubocop/cop/lint/unified_integer'
|
345
348
|
require_relative 'rubocop/cop/lint/unmodified_reduce_accumulator'
|
346
349
|
require_relative 'rubocop/cop/lint/unreachable_code'
|
@@ -529,6 +532,7 @@ require_relative 'rubocop/cop/style/preferred_hash_methods'
|
|
529
532
|
require_relative 'rubocop/cop/style/proc'
|
530
533
|
require_relative 'rubocop/cop/style/raise_args'
|
531
534
|
require_relative 'rubocop/cop/style/random_with_offset'
|
535
|
+
require_relative 'rubocop/cop/style/redundant_argument'
|
532
536
|
require_relative 'rubocop/cop/style/redundant_begin'
|
533
537
|
require_relative 'rubocop/cop/style/redundant_capital_w'
|
534
538
|
require_relative 'rubocop/cop/style/redundant_condition'
|
@@ -645,6 +649,7 @@ require_relative 'rubocop/cli/command/auto_genenerate_config'
|
|
645
649
|
require_relative 'rubocop/cli/command/execute_runner'
|
646
650
|
require_relative 'rubocop/cli/command/init_dotfile'
|
647
651
|
require_relative 'rubocop/cli/command/show_cops'
|
652
|
+
require_relative 'rubocop/cli/command/suggest_extensions'
|
648
653
|
require_relative 'rubocop/cli/command/version'
|
649
654
|
require_relative 'rubocop/config_regeneration'
|
650
655
|
require_relative 'rubocop/options'
|
data/lib/rubocop/cli.rb
CHANGED
@@ -69,10 +69,14 @@ module RuboCop
|
|
69
69
|
if @options[:auto_gen_config]
|
70
70
|
run_command(:auto_gen_config)
|
71
71
|
else
|
72
|
-
run_command(:execute_runner)
|
72
|
+
run_command(:execute_runner).tap { suggest_extensions }
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def suggest_extensions
|
77
|
+
run_command(:suggest_extensions)
|
78
|
+
end
|
79
|
+
|
76
80
|
def validate_options_vs_config
|
77
81
|
if @options[:parallel] &&
|
78
82
|
!@config_store.for_pwd.for_all_cops['UseCache']
|
@@ -22,12 +22,13 @@ module RuboCop
|
|
22
22
|
def execute_runner(paths)
|
23
23
|
runner = Runner.new(@options, @config_store)
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
all_pass_or_excluded = with_redirect do
|
26
|
+
all_passed = runner.run(paths)
|
27
|
+
display_summary(runner)
|
28
|
+
all_passed || @options[:auto_gen_config]
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
+
maybe_print_corrected_source
|
31
32
|
|
32
33
|
if runner.aborting?
|
33
34
|
STATUS_INTERRUPTED
|
@@ -38,6 +39,25 @@ module RuboCop
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
def with_redirect
|
43
|
+
if @options[:stderr]
|
44
|
+
orig_stdout = $stdout.dup
|
45
|
+
$stdout.reopen($stderr)
|
46
|
+
|
47
|
+
result = yield
|
48
|
+
|
49
|
+
$stdout.reopen(orig_stdout)
|
50
|
+
result
|
51
|
+
else
|
52
|
+
yield
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def display_summary(runner)
|
57
|
+
display_warning_summary(runner.warnings)
|
58
|
+
display_error_summary(runner.errors)
|
59
|
+
end
|
60
|
+
|
41
61
|
def display_warning_summary(warnings)
|
42
62
|
return if warnings.empty?
|
43
63
|
|
@@ -69,14 +89,9 @@ module RuboCop
|
|
69
89
|
# See: https://github.com/rubocop-hq/rubocop/issues/8673
|
70
90
|
return if INTEGRATION_FORMATTERS.include?(@options[:format])
|
71
91
|
|
72
|
-
# If we are asked to autocorrect source code read from stdin, the only
|
73
|
-
# reasonable place to write it is to stdout
|
74
|
-
# Unfortunately, we also write other information to stdout
|
75
|
-
# So a delimiter is needed for tools to easily identify where the
|
76
|
-
# autocorrected source begins
|
77
92
|
return unless @options[:stdin] && @options[:auto_correct]
|
78
93
|
|
79
|
-
puts '=' * 20
|
94
|
+
(@options[:stderr] ? $stderr : $stdout).puts '=' * 20
|
80
95
|
print @options[:stdin]
|
81
96
|
end
|
82
97
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
class CLI
|
5
|
+
module Command
|
6
|
+
# Run all the selected cops and report the result.
|
7
|
+
# @api private
|
8
|
+
class SuggestExtensions < Base
|
9
|
+
# Combination of short and long formatter names.
|
10
|
+
INCLUDED_FORMATTERS = %w[p progress fu fuubar pa pacman].freeze
|
11
|
+
|
12
|
+
self.command_name = :suggest_extensions
|
13
|
+
|
14
|
+
def run
|
15
|
+
return if skip? || extensions.none?
|
16
|
+
|
17
|
+
puts
|
18
|
+
puts 'Tip: Based on detected gems, the following '\
|
19
|
+
'RuboCop extension libraries might be helpful:'
|
20
|
+
|
21
|
+
extensions.each do |extension|
|
22
|
+
puts " * #{extension} (http://github.com/rubocop-hq/#{extension})"
|
23
|
+
end
|
24
|
+
|
25
|
+
puts
|
26
|
+
puts 'You can opt out of this message by adding the following to your config:'
|
27
|
+
puts ' AllCops:'
|
28
|
+
puts ' SuggestExtensions: false'
|
29
|
+
puts if @options[:display_time]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def skip?
|
35
|
+
# Disable outputting the notification:
|
36
|
+
# 1. On CI
|
37
|
+
# 2. When given RuboCop options that it doesn't make sense for
|
38
|
+
# 3. For all formatters except specified in `INCLUDED_FORMATTERS'`
|
39
|
+
ENV['CI'] ||
|
40
|
+
@options[:only] || @options[:debug] || @options[:list_target_files] || @options[:out] ||
|
41
|
+
!INCLUDED_FORMATTERS.include?(current_formatter)
|
42
|
+
end
|
43
|
+
|
44
|
+
def current_formatter
|
45
|
+
@options[:format] || @config_store.for_pwd.for_all_cops['DefaultFormatter'] || 'p'
|
46
|
+
end
|
47
|
+
|
48
|
+
def extensions
|
49
|
+
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
|
50
|
+
return [] unless extensions
|
51
|
+
|
52
|
+
extensions.select { |_, v| (v & dependent_gems).any? }.keys - dependent_gems
|
53
|
+
end
|
54
|
+
|
55
|
+
def dependent_gems
|
56
|
+
# This only includes gems in Gemfile, not in lockfile
|
57
|
+
Bundler.load.dependencies.map(&:name)
|
58
|
+
end
|
59
|
+
|
60
|
+
def puts(*args)
|
61
|
+
output = (@options[:stderr] ? $stderr : $stdout)
|
62
|
+
output.puts(*args)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
109
109
|
end
|
110
110
|
|
111
111
|
merge_with_default(config, config_file).tap do |merged_config|
|
112
|
-
warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(
|
112
|
+
warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(merged_config)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -255,10 +255,18 @@ module RuboCop
|
|
255
255
|
"Configuration file not found: #{absolute_path}"
|
256
256
|
end
|
257
257
|
|
258
|
-
|
258
|
+
def yaml_safe_load(yaml_code, filename)
|
259
|
+
yaml_safe_load!(yaml_code, filename)
|
260
|
+
rescue ::StandardError
|
261
|
+
if defined?(::SafeYAML)
|
262
|
+
raise 'SafeYAML is unmaintained, no longer needed and should be removed'
|
263
|
+
end
|
264
|
+
|
265
|
+
raise
|
266
|
+
end
|
259
267
|
|
260
268
|
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
|
261
|
-
def yaml_safe_load(yaml_code, filename)
|
269
|
+
def yaml_safe_load!(yaml_code, filename)
|
262
270
|
YAML.safe_load(yaml_code,
|
263
271
|
permitted_classes: [Regexp, Symbol],
|
264
272
|
permitted_symbols: [],
|
@@ -266,7 +274,7 @@ module RuboCop
|
|
266
274
|
filename: filename)
|
267
275
|
end
|
268
276
|
else # Ruby < 2.6
|
269
|
-
def yaml_safe_load(yaml_code, filename)
|
277
|
+
def yaml_safe_load!(yaml_code, filename)
|
270
278
|
YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
|
271
279
|
end
|
272
280
|
end
|