rubocop 1.36.0 → 1.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +78 -12
- data/exe/rubocop +1 -1
- data/lib/rubocop/arguments_env.rb +17 -0
- data/lib/rubocop/arguments_file.rb +17 -0
- data/lib/rubocop/cli/command/execute_runner.rb +7 -7
- data/lib/rubocop/cli/command/suggest_extensions.rb +8 -1
- data/lib/rubocop/comment_config.rb +41 -1
- data/lib/rubocop/config.rb +5 -4
- data/lib/rubocop/config_loader.rb +5 -5
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/cop/base.rb +2 -9
- data/lib/rubocop/cop/commissioner.rb +3 -1
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +22 -6
- data/lib/rubocop/cop/generator.rb +1 -2
- data/lib/rubocop/cop/internal_affairs/create_empty_file.rb +37 -0
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +111 -0
- data/lib/rubocop/cop/internal_affairs/lambda_or_proc.rb +46 -0
- data/lib/rubocop/cop/internal_affairs.rb +3 -0
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +29 -8
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +13 -9
- data/lib/rubocop/cop/layout/space_inside_array_percent_literal.rb +3 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +30 -3
- data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +34 -0
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +6 -2
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -2
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +11 -1
- data/lib/rubocop/cop/lint/deprecated_constants.rb +8 -1
- data/lib/rubocop/cop/lint/duplicate_magic_comment.rb +73 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +28 -9
- data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +25 -6
- data/lib/rubocop/cop/lint/empty_block.rb +1 -5
- data/lib/rubocop/cop/lint/empty_class.rb +3 -1
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +21 -9
- data/lib/rubocop/cop/lint/interpolation_check.rb +4 -3
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +18 -3
- data/lib/rubocop/cop/lint/nested_method_definition.rb +50 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
- data/lib/rubocop/cop/lint/ordered_magic_comments.rb +4 -5
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +5 -0
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +36 -4
- data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +7 -0
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +38 -10
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +18 -8
- data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +5 -4
- data/lib/rubocop/cop/lint/shadowed_exception.rb +0 -10
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +7 -3
- data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +4 -0
- data/lib/rubocop/cop/lint/void.rb +6 -6
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/block_length.rb +9 -4
- data/lib/rubocop/cop/metrics/class_length.rb +9 -4
- data/lib/rubocop/cop/metrics/method_length.rb +9 -4
- data/lib/rubocop/cop/metrics/module_length.rb +9 -4
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +5 -2
- data/lib/rubocop/cop/mixin/comments_help.rb +12 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -0
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +30 -8
- data/lib/rubocop/cop/mixin/range_help.rb +23 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +3 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +15 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +10 -8
- data/lib/rubocop/cop/mixin/visibility_help.rb +40 -5
- data/lib/rubocop/cop/naming/inclusive_language.rb +1 -1
- data/lib/rubocop/cop/registry.rb +32 -14
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +5 -7
- data/lib/rubocop/cop/style/accessor_grouping.rb +7 -3
- data/lib/rubocop/cop/style/array_intersect.rb +111 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -2
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/class_equality_comparison.rb +8 -6
- data/lib/rubocop/cop/style/collection_compact.rb +12 -3
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/endless_method.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +4 -0
- data/lib/rubocop/cop/style/format_string_token.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +90 -22
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +32 -10
- data/lib/rubocop/cop/style/hash_except.rb +4 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +25 -2
- data/lib/rubocop/cop/style/if_with_semicolon.rb +2 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +13 -2
- data/lib/rubocop/cop/style/module_function.rb +28 -6
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
- data/lib/rubocop/cop/style/object_then.rb +3 -0
- data/lib/rubocop/cop/style/operator_method_call.rb +53 -0
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +3 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +5 -2
- data/lib/rubocop/cop/style/redundant_constant_base.rb +72 -0
- data/lib/rubocop/cop/style/redundant_each.rb +116 -0
- data/lib/rubocop/cop/style/redundant_initialize.rb +3 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +8 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +12 -3
- data/lib/rubocop/cop/style/redundant_return.rb +7 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
- data/lib/rubocop/cop/style/redundant_string_escape.rb +181 -0
- data/lib/rubocop/cop/style/require_order.rb +88 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +35 -6
- data/lib/rubocop/cop/style/select_by_regexp.rb +8 -4
- data/lib/rubocop/cop/style/static_class.rb +32 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -5
- data/lib/rubocop/cop/style/symbol_array.rb +2 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +3 -5
- data/lib/rubocop/cop/style/word_array.rb +2 -0
- data/lib/rubocop/cop/team.rb +4 -5
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -1
- data/lib/rubocop/cop/variable_force.rb +20 -29
- data/lib/rubocop/cops_documentation_generator.rb +2 -1
- data/lib/rubocop/ext/processed_source.rb +2 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +25 -8
- data/lib/rubocop/formatter/html_formatter.rb +1 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +8 -5
- data/lib/rubocop/formatter/worst_offenders_formatter.rb +6 -3
- data/lib/rubocop/formatter.rb +3 -1
- data/lib/rubocop/optimized_patterns.rb +38 -0
- data/lib/rubocop/options.rb +28 -16
- data/lib/rubocop/path_util.rb +14 -2
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +24 -1
- data/lib/rubocop/rspec/shared_contexts.rb +14 -1
- data/lib/rubocop/rspec/support.rb +2 -2
- data/lib/rubocop/runner.rb +15 -11
- data/lib/rubocop/server/cache.rb +5 -1
- data/lib/rubocop/server/cli.rb +9 -2
- data/lib/rubocop/server/client_command/exec.rb +5 -0
- data/lib/rubocop/server/core.rb +19 -2
- data/lib/rubocop/server/socket_reader.rb +5 -1
- data/lib/rubocop/server.rb +1 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +8 -3
- data/lib/rubocop.rb +18 -6
- metadata +18 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb2b7b02733dca8e7577cd5ccd776044179cd762685152d9c7d5a739dd7cf9e1
|
4
|
+
data.tar.gz: 47b6ef2704e65f30af91def68b22331aca13d629d954cc860288738dccd4f14d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65cd2840052b36832dec3218f2994b0dbaae5e482328c767b0f82ac3d882ce1a29a02ddd53e960c199514ff241d17d0c5f33b139b50634fce4c7fa246018a1c
|
7
|
+
data.tar.gz: 51442c821afd72669bb0845386c1c05495618736b46978e1d2fae12f3f69f30ff914025209f6efc2c673692e585e4e2968fe76467f2433ba98f2209d435b46bd
|
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.40', 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
@@ -161,7 +161,9 @@ AllCops:
|
|
161
161
|
Bundler/DuplicatedGem:
|
162
162
|
Description: 'Checks for duplicate gem entries in Gemfile.'
|
163
163
|
Enabled: true
|
164
|
+
Severity: warning
|
164
165
|
VersionAdded: '0.46'
|
166
|
+
VersionChanged: '1.40'
|
165
167
|
Include:
|
166
168
|
- '**/*.gemfile'
|
167
169
|
- '**/Gemfile'
|
@@ -213,7 +215,9 @@ Bundler/InsecureProtocolSource:
|
|
213
215
|
because HTTP requests are insecure. Please change your source to
|
214
216
|
'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
|
215
217
|
Enabled: true
|
218
|
+
Severity: warning
|
216
219
|
VersionAdded: '0.50'
|
220
|
+
VersionChanged: '1.40'
|
217
221
|
AllowHttpProtocol: true
|
218
222
|
Include:
|
219
223
|
- '**/*.gemfile'
|
@@ -252,14 +256,18 @@ Gemspec/DependencyVersion:
|
|
252
256
|
Gemspec/DeprecatedAttributeAssignment:
|
253
257
|
Description: Checks that deprecated attribute assignments are not set in a gemspec file.
|
254
258
|
Enabled: pending
|
259
|
+
Severity: warning
|
255
260
|
VersionAdded: '1.30'
|
261
|
+
VersionChanged: '1.40'
|
256
262
|
Include:
|
257
263
|
- '**/*.gemspec'
|
258
264
|
|
259
265
|
Gemspec/DuplicatedAssignment:
|
260
266
|
Description: 'An attribute assignment method calls should be listed only once in a gemspec.'
|
261
267
|
Enabled: true
|
268
|
+
Severity: warning
|
262
269
|
VersionAdded: '0.52'
|
270
|
+
VersionChanged: '1.40'
|
263
271
|
Include:
|
264
272
|
- '**/*.gemspec'
|
265
273
|
|
@@ -278,7 +286,9 @@ Gemspec/OrderedDependencies:
|
|
278
286
|
Gemspec/RequireMFA:
|
279
287
|
Description: 'Checks that the gemspec has metadata to require Multi-Factor Authentication from RubyGems.'
|
280
288
|
Enabled: pending
|
289
|
+
Severity: warning
|
281
290
|
VersionAdded: '1.23'
|
291
|
+
VersionChanged: '1.40'
|
282
292
|
Reference:
|
283
293
|
- https://guides.rubygems.org/mfa-requirement-opt-in/
|
284
294
|
Include:
|
@@ -287,8 +297,9 @@ Gemspec/RequireMFA:
|
|
287
297
|
Gemspec/RequiredRubyVersion:
|
288
298
|
Description: 'Checks that `required_ruby_version` of gemspec is specified and equal to `TargetRubyVersion` of .rubocop.yml.'
|
289
299
|
Enabled: true
|
300
|
+
Severity: warning
|
290
301
|
VersionAdded: '0.52'
|
291
|
-
VersionChanged: '1.
|
302
|
+
VersionChanged: '1.40'
|
292
303
|
Include:
|
293
304
|
- '**/*.gemspec'
|
294
305
|
|
@@ -296,7 +307,9 @@ Gemspec/RubyVersionGlobalsUsage:
|
|
296
307
|
Description: Checks usage of RUBY_VERSION in gemspec.
|
297
308
|
StyleGuide: '#no-ruby-version-in-the-gemspec'
|
298
309
|
Enabled: true
|
310
|
+
Severity: warning
|
299
311
|
VersionAdded: '0.72'
|
312
|
+
VersionChanged: '1.40'
|
300
313
|
Include:
|
301
314
|
- '**/*.gemspec'
|
302
315
|
|
@@ -378,8 +391,9 @@ Layout/AssignmentIndentation:
|
|
378
391
|
Checks the indentation of the first line of the
|
379
392
|
right-hand-side of a multi-line assignment.
|
380
393
|
Enabled: true
|
394
|
+
SafeAutoCorrect: false
|
381
395
|
VersionAdded: '0.49'
|
382
|
-
VersionChanged: '
|
396
|
+
VersionChanged: '1.40'
|
383
397
|
# By default the indentation width from `Layout/IndentationWidth` is used,
|
384
398
|
# but it can be overridden by setting this parameter.
|
385
399
|
IndentationWidth: ~
|
@@ -1643,7 +1657,7 @@ Lint/DeprecatedConstants:
|
|
1643
1657
|
Description: 'Checks for deprecated constants.'
|
1644
1658
|
Enabled: pending
|
1645
1659
|
VersionAdded: '1.8'
|
1646
|
-
VersionChanged: '1.
|
1660
|
+
VersionChanged: '1.40'
|
1647
1661
|
# You can configure deprecated constants.
|
1648
1662
|
# If there is an alternative method, you can set alternative value as `Alternative`.
|
1649
1663
|
# And you can set the deprecated version as `DeprecatedVersion`.
|
@@ -1670,6 +1684,12 @@ Lint/DeprecatedConstants:
|
|
1670
1684
|
'Random::DEFAULT':
|
1671
1685
|
Alternative: 'Random.new'
|
1672
1686
|
DeprecatedVersion: '3.0'
|
1687
|
+
'Struct::Group':
|
1688
|
+
Alternative: 'Etc::Group'
|
1689
|
+
DeprecatedVersion: '3.0'
|
1690
|
+
'Struct::Passwd':
|
1691
|
+
Alternative: 'Etc::Passwd'
|
1692
|
+
DeprecatedVersion: '3.0'
|
1673
1693
|
|
1674
1694
|
Lint/DeprecatedOpenSSLConstant:
|
1675
1695
|
Description: "Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`."
|
@@ -1707,6 +1727,11 @@ Lint/DuplicateHashKey:
|
|
1707
1727
|
VersionAdded: '0.34'
|
1708
1728
|
VersionChanged: '0.77'
|
1709
1729
|
|
1730
|
+
Lint/DuplicateMagicComment:
|
1731
|
+
Description: 'Check for duplicated magic comments.'
|
1732
|
+
Enabled: pending
|
1733
|
+
VersionAdded: '1.37'
|
1734
|
+
|
1710
1735
|
Lint/DuplicateMethods:
|
1711
1736
|
Description: 'Check for duplicate method definitions.'
|
1712
1737
|
Enabled: true
|
@@ -1889,11 +1914,11 @@ Lint/InheritException:
|
|
1889
1914
|
- runtime_error
|
1890
1915
|
|
1891
1916
|
Lint/InterpolationCheck:
|
1892
|
-
Description: '
|
1917
|
+
Description: 'Checks for interpolation in a single quoted string.'
|
1893
1918
|
Enabled: true
|
1894
|
-
|
1919
|
+
SafeAutoCorrect: false
|
1895
1920
|
VersionAdded: '0.50'
|
1896
|
-
VersionChanged: '
|
1921
|
+
VersionChanged: '1.40'
|
1897
1922
|
|
1898
1923
|
Lint/LambdaWithoutLiteralBlock:
|
1899
1924
|
Description: 'Checks uses of lambda without a literal block.'
|
@@ -1957,6 +1982,8 @@ Lint/NestedMethodDefinition:
|
|
1957
1982
|
Description: 'Do not use nested method definitions.'
|
1958
1983
|
StyleGuide: '#no-nested-methods'
|
1959
1984
|
Enabled: true
|
1985
|
+
AllowedMethods: []
|
1986
|
+
AllowedPatterns: []
|
1960
1987
|
VersionAdded: '0.32'
|
1961
1988
|
|
1962
1989
|
Lint/NestedPercentLiteral:
|
@@ -2021,7 +2048,9 @@ Lint/OrAssignmentToConstant:
|
|
2021
2048
|
Lint/OrderedMagicComments:
|
2022
2049
|
Description: 'Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.'
|
2023
2050
|
Enabled: true
|
2051
|
+
SafeAutoCorrect: false
|
2024
2052
|
VersionAdded: '0.53'
|
2053
|
+
VersionChanged: '1.37'
|
2025
2054
|
|
2026
2055
|
Lint/OutOfRangeRegexpRef:
|
2027
2056
|
Description: 'Checks for out of range reference for Regexp because it always returns nil.'
|
@@ -2797,8 +2826,10 @@ Naming/MethodParameterName:
|
|
2797
2826
|
- as
|
2798
2827
|
- at
|
2799
2828
|
- by
|
2829
|
+
- cc
|
2800
2830
|
- db
|
2801
2831
|
- id
|
2832
|
+
- if
|
2802
2833
|
- in
|
2803
2834
|
- io
|
2804
2835
|
- ip
|
@@ -3003,6 +3034,11 @@ Style/ArrayCoercion:
|
|
3003
3034
|
Enabled: false
|
3004
3035
|
VersionAdded: '0.88'
|
3005
3036
|
|
3037
|
+
Style/ArrayIntersect:
|
3038
|
+
Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
|
3039
|
+
Enabled: 'pending'
|
3040
|
+
VersionAdded: '1.40'
|
3041
|
+
|
3006
3042
|
Style/ArrayJoin:
|
3007
3043
|
Description: 'Use Array#join instead of Array#*.'
|
3008
3044
|
StyleGuide: '#array-join'
|
@@ -3439,7 +3475,7 @@ Style/Copyright:
|
|
3439
3475
|
|
3440
3476
|
Style/DateTime:
|
3441
3477
|
Description: 'Use Time over DateTime.'
|
3442
|
-
StyleGuide: '#date
|
3478
|
+
StyleGuide: '#date-time'
|
3443
3479
|
Enabled: false
|
3444
3480
|
VersionAdded: '0.51'
|
3445
3481
|
VersionChanged: '0.92'
|
@@ -3810,8 +3846,9 @@ Style/HashExcept:
|
|
3810
3846
|
Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods
|
3811
3847
|
that can be replaced with `Hash#except` method.
|
3812
3848
|
Enabled: pending
|
3849
|
+
Safe: false
|
3813
3850
|
VersionAdded: '1.7'
|
3814
|
-
VersionChanged: '1.
|
3851
|
+
VersionChanged: '1.39'
|
3815
3852
|
|
3816
3853
|
Style/HashLikeCase:
|
3817
3854
|
Description: >-
|
@@ -3850,7 +3887,7 @@ Style/HashSyntax:
|
|
3850
3887
|
- never
|
3851
3888
|
# accepts both shorthand and explicit use of hash literal value.
|
3852
3889
|
- either
|
3853
|
-
# like "
|
3890
|
+
# like "either", but will avoid mixing styles in a single hash
|
3854
3891
|
- consistent
|
3855
3892
|
# Force hashes that have a symbol value to use hash rockets
|
3856
3893
|
UseHashRocketsWithSymbolValues: false
|
@@ -4498,6 +4535,12 @@ Style/OpenStructUse:
|
|
4498
4535
|
Enabled: pending
|
4499
4536
|
VersionAdded: '1.23'
|
4500
4537
|
|
4538
|
+
Style/OperatorMethodCall:
|
4539
|
+
Description: 'Checks for redundant dot before operator method call.'
|
4540
|
+
StyleGuide: '#operator-method-call'
|
4541
|
+
Enabled: pending
|
4542
|
+
VersionAdded: '1.37'
|
4543
|
+
|
4501
4544
|
Style/OptionHash:
|
4502
4545
|
Description: "Don't use option hashes when you can use keyword arguments."
|
4503
4546
|
Enabled: false
|
@@ -4643,10 +4686,12 @@ Style/RedundantArgument:
|
|
4643
4686
|
Enabled: pending
|
4644
4687
|
Safe: false
|
4645
4688
|
VersionAdded: '1.4'
|
4646
|
-
VersionChanged: '1.
|
4689
|
+
VersionChanged: '1.40'
|
4647
4690
|
Methods:
|
4648
4691
|
# Array#join
|
4649
4692
|
join: ''
|
4693
|
+
# Array#sum
|
4694
|
+
sum: 0
|
4650
4695
|
# String#split
|
4651
4696
|
split: ' '
|
4652
4697
|
# String#chomp
|
@@ -4681,6 +4726,17 @@ Style/RedundantConditional:
|
|
4681
4726
|
Enabled: true
|
4682
4727
|
VersionAdded: '0.50'
|
4683
4728
|
|
4729
|
+
Style/RedundantConstantBase:
|
4730
|
+
Description: Avoid redundant `::` prefix on constant.
|
4731
|
+
Enabled: pending
|
4732
|
+
VersionAdded: '1.40'
|
4733
|
+
|
4734
|
+
Style/RedundantEach:
|
4735
|
+
Description: 'Checks for redundant `each`.'
|
4736
|
+
Enabled: pending
|
4737
|
+
Safe: false
|
4738
|
+
VersionAdded: '1.38'
|
4739
|
+
|
4684
4740
|
Style/RedundantException:
|
4685
4741
|
Description: "Checks for an obsolete RuntimeException argument in raise/fail."
|
4686
4742
|
StyleGuide: '#no-explicit-runtimeerror'
|
@@ -4792,6 +4848,11 @@ Style/RedundantSortBy:
|
|
4792
4848
|
Enabled: true
|
4793
4849
|
VersionAdded: '0.36'
|
4794
4850
|
|
4851
|
+
Style/RedundantStringEscape:
|
4852
|
+
Description: 'Checks for redundant escapes in string literals.'
|
4853
|
+
Enabled: pending
|
4854
|
+
VersionAdded: '1.37'
|
4855
|
+
|
4795
4856
|
Style/RegexpLiteral:
|
4796
4857
|
Description: 'Use / or %r around regular expressions.'
|
4797
4858
|
StyleGuide: '#percent-r'
|
@@ -4810,6 +4871,12 @@ Style/RegexpLiteral:
|
|
4810
4871
|
# are found in the regexp string.
|
4811
4872
|
AllowInnerSlashes: false
|
4812
4873
|
|
4874
|
+
Style/RequireOrder:
|
4875
|
+
Description: Sort `require` and `require_relative` in alphabetical order.
|
4876
|
+
Enabled: false
|
4877
|
+
SafeAutoCorrect: false
|
4878
|
+
VersionAdded: '1.40'
|
4879
|
+
|
4813
4880
|
Style/RescueModifier:
|
4814
4881
|
Description: 'Avoid using rescue in its modifier form.'
|
4815
4882
|
StyleGuide: '#no-rescue-modifiers'
|
@@ -5094,12 +5161,11 @@ Style/SymbolProc:
|
|
5094
5161
|
Enabled: true
|
5095
5162
|
Safe: false
|
5096
5163
|
VersionAdded: '0.26'
|
5097
|
-
VersionChanged: '1.
|
5164
|
+
VersionChanged: '1.40'
|
5098
5165
|
AllowMethodsWithArguments: false
|
5099
5166
|
# A list of method names to be always allowed by the check.
|
5100
5167
|
# The names should be fairly unique, otherwise you'll end up ignoring lots of code.
|
5101
5168
|
AllowedMethods:
|
5102
|
-
- respond_to
|
5103
5169
|
- define_method
|
5104
5170
|
AllowedPatterns: []
|
5105
5171
|
IgnoredMethods: [] # deprecated
|
data/exe/rubocop
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This is a class that reads optional command line arguments to rubocop from environment variable.
|
5
|
+
# @api private
|
6
|
+
class ArgumentsEnv
|
7
|
+
def self.read_as_arguments
|
8
|
+
if (arguments = ENV.fetch('RUBOCOP_OPTS', '')).empty?
|
9
|
+
[]
|
10
|
+
else
|
11
|
+
require 'shellwords'
|
12
|
+
|
13
|
+
Shellwords.split(arguments)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This is a class that reads optional command line arguments to rubocop from .rubocop file.
|
5
|
+
# @api private
|
6
|
+
class ArgumentsFile
|
7
|
+
def self.read_as_arguments
|
8
|
+
if File.exist?('.rubocop') && !File.directory?('.rubocop')
|
9
|
+
require 'shellwords'
|
10
|
+
|
11
|
+
File.read('.rubocop').shellsplit
|
12
|
+
else
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -41,13 +41,13 @@ module RuboCop
|
|
41
41
|
|
42
42
|
def with_redirect
|
43
43
|
if @options[:stderr]
|
44
|
-
orig_stdout = $stdout
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
orig_stdout = $stdout
|
45
|
+
begin
|
46
|
+
$stdout = $stderr
|
47
|
+
yield
|
48
|
+
ensure
|
49
|
+
$stdout = orig_stdout
|
50
|
+
end
|
51
51
|
else
|
52
52
|
yield
|
53
53
|
end
|
@@ -73,7 +73,14 @@ module RuboCop
|
|
73
73
|
def all_extensions
|
74
74
|
return [] unless lockfile.dependencies.any?
|
75
75
|
|
76
|
-
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
|
76
|
+
extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions']
|
77
|
+
case extensions
|
78
|
+
when true
|
79
|
+
extensions = ConfigLoader.default_configuration.for_all_cops['SuggestExtensions']
|
80
|
+
when false, nil
|
81
|
+
extensions = {}
|
82
|
+
end
|
83
|
+
|
77
84
|
extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
|
78
85
|
end
|
79
86
|
|
@@ -4,12 +4,34 @@ module RuboCop
|
|
4
4
|
# This class parses the special `rubocop:disable` comments in a source
|
5
5
|
# and provides a way to check if each cop is enabled at arbitrary line.
|
6
6
|
class CommentConfig
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
CONFIG_DISABLED_LINE_RANGE_MIN = -Float::INFINITY
|
10
|
+
|
11
|
+
# This class provides an API compatible with RuboCop::DirectiveComment
|
12
|
+
# to be used for cops that are disabled in the config file
|
13
|
+
class ConfigDisabledCopDirectiveComment
|
14
|
+
attr_reader :text, :loc, :line_number
|
15
|
+
|
16
|
+
Loc = Struct.new(:expression)
|
17
|
+
Expression = Struct.new(:line)
|
18
|
+
|
19
|
+
def initialize(cop_name)
|
20
|
+
@text = "# rubocop:disable #{cop_name}"
|
21
|
+
@line_number = CONFIG_DISABLED_LINE_RANGE_MIN
|
22
|
+
@loc = Loc.new(Expression.new(CONFIG_DISABLED_LINE_RANGE_MIN))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
7
26
|
CopAnalysis = Struct.new(:line_ranges, :start_line_number)
|
8
27
|
|
9
28
|
attr_reader :processed_source
|
10
29
|
|
30
|
+
def_delegators :@processed_source, :config, :registry
|
31
|
+
|
11
32
|
def initialize(processed_source)
|
12
33
|
@processed_source = processed_source
|
34
|
+
@no_directives = !processed_source.raw_source.include?('rubocop')
|
13
35
|
end
|
14
36
|
|
15
37
|
def cop_enabled_at_line?(cop, line_number)
|
@@ -25,7 +47,11 @@ module RuboCop
|
|
25
47
|
end
|
26
48
|
|
27
49
|
def extra_enabled_comments
|
28
|
-
|
50
|
+
disable_count = Hash.new(0)
|
51
|
+
registry.disabled(config).each do |cop|
|
52
|
+
disable_count[cop.cop_name] += 1
|
53
|
+
end
|
54
|
+
extra_enabled_comments_with_names(extras: Hash.new { |h, k| h[k] = [] }, names: disable_count)
|
29
55
|
end
|
30
56
|
|
31
57
|
def comment_only_line?(line_number)
|
@@ -49,7 +75,10 @@ module RuboCop
|
|
49
75
|
end
|
50
76
|
|
51
77
|
def analyze # rubocop:todo Metrics/AbcSize
|
78
|
+
return {} if @no_directives
|
79
|
+
|
52
80
|
analyses = Hash.new { |hash, key| hash[key] = CopAnalysis.new([], nil) }
|
81
|
+
inject_disabled_cops_directives(analyses)
|
53
82
|
|
54
83
|
each_directive do |directive|
|
55
84
|
directive.cop_names.each do |cop_name|
|
@@ -64,6 +93,15 @@ module RuboCop
|
|
64
93
|
end
|
65
94
|
end
|
66
95
|
|
96
|
+
def inject_disabled_cops_directives(analyses)
|
97
|
+
registry.disabled(config).each do |cop|
|
98
|
+
analyses[cop.cop_name] = analyze_cop(
|
99
|
+
analyses[cop.cop_name],
|
100
|
+
DirectiveComment.new(ConfigDisabledCopDirectiveComment.new(cop.cop_name))
|
101
|
+
)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
67
105
|
def analyze_cop(analysis, directive)
|
68
106
|
# Disabling cops after comments like `#=SomeDslDirective` does not related to single line
|
69
107
|
if !comment_only_line?(directive.line_number) || directive.single_line?
|
@@ -111,6 +149,8 @@ module RuboCop
|
|
111
149
|
end
|
112
150
|
|
113
151
|
def each_directive
|
152
|
+
return if @no_directives
|
153
|
+
|
114
154
|
processed_source.comments.each do |comment|
|
115
155
|
directive = DirectiveComment.new(comment)
|
116
156
|
yield directive if directive.cop_names
|
data/lib/rubocop/config.rb
CHANGED
@@ -24,10 +24,11 @@ module RuboCop
|
|
24
24
|
def initialize(hash = {}, loaded_path = nil)
|
25
25
|
@loaded_path = loaded_path
|
26
26
|
@for_cop = Hash.new do |h, cop|
|
27
|
-
|
27
|
+
cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
|
28
|
+
qualified_cop_name = Cop::Registry.qualified_cop_name(cop_name, loaded_path)
|
28
29
|
cop_options = self[qualified_cop_name].dup || {}
|
29
30
|
cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
|
30
|
-
h[cop] = cop_options
|
31
|
+
h[cop] = h[cop_name] = cop_options
|
31
32
|
end
|
32
33
|
@hash = hash
|
33
34
|
@validator = ConfigValidator.new(self)
|
@@ -116,7 +117,7 @@ module RuboCop
|
|
116
117
|
# Note: the 'Enabled' attribute is calculated according to the department's
|
117
118
|
# and 'AllCops' configuration; other attributes are not inherited.
|
118
119
|
def for_cop(cop)
|
119
|
-
@for_cop[cop
|
120
|
+
@for_cop[cop]
|
120
121
|
end
|
121
122
|
|
122
123
|
# @return [Config] for the given cop merged with that of its department (if any)
|
@@ -215,7 +216,7 @@ module RuboCop
|
|
215
216
|
# directory since that wouldn't work.
|
216
217
|
def base_dir_for_path_parameters
|
217
218
|
@base_dir_for_path_parameters ||=
|
218
|
-
if File.basename(loaded_path).start_with?('.rubocop') &&
|
219
|
+
if loaded_path && File.basename(loaded_path).start_with?('.rubocop') &&
|
219
220
|
loaded_path != File.join(Dir.home, ConfigLoader::DOTFILE)
|
220
221
|
File.expand_path(File.dirname(loaded_path))
|
221
222
|
else
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'erb'
|
4
|
-
require 'yaml'
|
5
4
|
require 'pathname'
|
5
|
+
require 'yaml'
|
6
6
|
require_relative 'config_finder'
|
7
7
|
|
8
8
|
module RuboCop
|
@@ -42,18 +42,18 @@ module RuboCop
|
|
42
42
|
|
43
43
|
hash = load_yaml_configuration(path)
|
44
44
|
|
45
|
-
# Resolve requires first in case they define additional cops
|
46
45
|
loaded_features = resolver.resolve_requires(path, hash)
|
47
46
|
add_loaded_features(loaded_features)
|
48
47
|
|
49
|
-
add_missing_namespaces(path, hash)
|
50
|
-
|
51
48
|
resolver.override_department_setting_for_cops({}, hash)
|
52
49
|
resolver.resolve_inheritance_from_gems(hash)
|
53
50
|
resolver.resolve_inheritance(path, hash, file, debug?)
|
54
|
-
|
55
51
|
hash.delete('inherit_from')
|
56
52
|
|
53
|
+
# Adding missing namespaces only after resolving requires & inheritance,
|
54
|
+
# since both can introduce new cops that need to be considered here.
|
55
|
+
add_missing_namespaces(path, hash)
|
56
|
+
|
57
57
|
Config.create(hash, path, check: check)
|
58
58
|
end
|
59
59
|
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -412,15 +412,8 @@ module RuboCop
|
|
412
412
|
patterns = cop_config[parameter]
|
413
413
|
return default_result unless patterns
|
414
414
|
|
415
|
-
|
416
|
-
patterns.
|
417
|
-
# Try to match the absolute path, as Exclude properties are absolute.
|
418
|
-
next true if match_path?(pattern, file)
|
419
|
-
|
420
|
-
# Try with relative path.
|
421
|
-
path ||= config.path_relative_to_config(file)
|
422
|
-
match_path?(pattern, path)
|
423
|
-
end
|
415
|
+
patterns = OptimizedPatterns.from(patterns)
|
416
|
+
patterns.match?(config.path_relative_to_config(file)) || patterns.match?(file)
|
424
417
|
end
|
425
418
|
|
426
419
|
def enabled_line?(line_number)
|
@@ -159,9 +159,11 @@ module RuboCop
|
|
159
159
|
def with_cop_error_handling(cop, node = nil)
|
160
160
|
yield
|
161
161
|
rescue StandardError => e
|
162
|
-
raise e if @options[:raise_error]
|
162
|
+
raise e if @options[:raise_error] # For internal testing
|
163
163
|
|
164
164
|
err = ErrorWithAnalyzedFileLocation.new(cause: e, node: node, cop: cop)
|
165
|
+
raise err if @options[:raise_cop_error] # From user-input option
|
166
|
+
|
165
167
|
@errors << err
|
166
168
|
end
|
167
169
|
end
|
@@ -28,7 +28,10 @@ module RuboCop
|
|
28
28
|
# put the comment.
|
29
29
|
return if new_line_needed_before_closing_brace?(node)
|
30
30
|
|
31
|
-
|
31
|
+
end_range = last_element_range_with_trailing_comma(node).end
|
32
|
+
|
33
|
+
correct_next_line_brace(corrector, end_range)
|
34
|
+
correct_heredoc_argument_method_chain(corrector, end_range)
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -40,13 +43,19 @@ module RuboCop
|
|
40
43
|
corrector.insert_before(node.loc.end, "\n")
|
41
44
|
end
|
42
45
|
|
43
|
-
def correct_next_line_brace(corrector)
|
46
|
+
def correct_next_line_brace(corrector, end_range)
|
44
47
|
corrector.remove(range_with_surrounding_space(node.loc.end, side: :left))
|
48
|
+
corrector.insert_before(end_range, content_if_comment_present(corrector, node))
|
49
|
+
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def correct_heredoc_argument_method_chain(corrector, end_range)
|
52
|
+
return unless (parent = node.parent)
|
53
|
+
return unless use_heredoc_argument_method_chain?(parent)
|
54
|
+
|
55
|
+
chained_method = range_between(parent.loc.dot.begin_pos, parent.loc.expression.end_pos)
|
56
|
+
|
57
|
+
corrector.remove(chained_method)
|
58
|
+
corrector.insert_after(end_range, chained_method.source)
|
50
59
|
end
|
51
60
|
|
52
61
|
def content_if_comment_present(corrector, node)
|
@@ -61,6 +70,13 @@ module RuboCop
|
|
61
70
|
end
|
62
71
|
end
|
63
72
|
|
73
|
+
def use_heredoc_argument_method_chain?(parent)
|
74
|
+
return false unless node.respond_to?(:first_argument)
|
75
|
+
return false unless (first_argument = node.first_argument)
|
76
|
+
|
77
|
+
parent.call_type? && first_argument.str_type? && first_argument.heredoc?
|
78
|
+
end
|
79
|
+
|
64
80
|
def select_content_to_be_inserted_after_last_element(corrector, node)
|
65
81
|
range = range_between(
|
66
82
|
node.loc.end.begin_pos,
|
@@ -206,9 +206,8 @@ module RuboCop
|
|
206
206
|
end
|
207
207
|
|
208
208
|
def snake_case(camel_case_string)
|
209
|
-
return 'rspec' if camel_case_string == 'RSpec'
|
210
|
-
|
211
209
|
camel_case_string
|
210
|
+
.gsub('RSpec', 'Rspec')
|
212
211
|
.gsub(%r{([^A-Z/])([A-Z]+)}, '\1_\2')
|
213
212
|
.gsub(%r{([A-Z])([A-Z][^A-Z\d/]+)}, '\1_\2')
|
214
213
|
.downcase
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Checks for uses of `create_file` with empty string second argument.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# create_file(path, '')
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# create_empty_file(path)
|
15
|
+
#
|
16
|
+
class CreateEmptyFile < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Use `%<replacement>s`.'
|
20
|
+
RESTRICT_ON_SEND = %i[create_file].freeze
|
21
|
+
|
22
|
+
def on_send(node)
|
23
|
+
return if node.receiver
|
24
|
+
return unless (argument = node.arguments[1])
|
25
|
+
return unless argument.str_type? && argument.value.empty?
|
26
|
+
|
27
|
+
replacement = "create_empty_file(#{node.first_argument.source})"
|
28
|
+
message = format(MSG, replacement: replacement)
|
29
|
+
|
30
|
+
add_offense(node, message: message) do |corrector|
|
31
|
+
corrector.replace(node, replacement)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|