rubocop 1.67.0 → 1.69.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 +81 -6
- data/lib/rubocop/cached_data.rb +12 -4
- data/lib/rubocop/cli/command/execute_runner.rb +1 -1
- data/lib/rubocop/cli/command/version.rb +2 -2
- data/lib/rubocop/cop/autocorrect_logic.rb +22 -2
- data/lib/rubocop/cop/base.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_filename.rb +0 -1
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +0 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -12
- data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +10 -0
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -2
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +0 -2
- data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +2 -4
- data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/operator_keyword.rb +46 -0
- data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +0 -2
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/begin_end_alignment.rb +0 -1
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -3
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +3 -4
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +3 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +7 -7
- data/lib/rubocop/cop/layout/leading_comment_space.rb +44 -1
- data/lib/rubocop/cop/layout/line_length.rb +118 -4
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -3
- data/lib/rubocop/cop/layout/parameter_alignment.rb +3 -4
- data/lib/rubocop/cop/layout/redundant_line_break.rb +3 -35
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -2
- data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +16 -17
- data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -5
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +6 -0
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +0 -1
- data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +11 -12
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -0
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
- data/lib/rubocop/cop/lint/duplicate_branch.rb +39 -4
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/empty_file.rb +0 -2
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/float_comparison.rb +14 -6
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -3
- data/lib/rubocop/cop/lint/hash_new_with_keyword_arguments_as_default.rb +55 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +9 -0
- data/lib/rubocop/cop/lint/it_without_arguments_in_block.rb +3 -0
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/mixed_case_range.rb +2 -5
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +2 -2
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +8 -1
- data/lib/rubocop/cop/lint/number_conversion.rb +0 -1
- data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -2
- data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +106 -0
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -2
- data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +12 -7
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +8 -7
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +0 -1
- data/lib/rubocop/cop/lint/rescue_type.rb +3 -7
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +9 -0
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +5 -1
- data/lib/rubocop/cop/lint/self_assignment.rb +8 -10
- data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
- data/lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb +88 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +18 -2
- data/lib/rubocop/cop/lint/useless_defined.rb +55 -0
- data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +14 -25
- data/lib/rubocop/cop/lint/void.rb +3 -2
- data/lib/rubocop/cop/metrics/class_length.rb +7 -7
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +4 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -2
- data/lib/rubocop/cop/mixin/check_assignment.rb +4 -12
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -0
- data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +49 -0
- data/lib/rubocop/cop/mixin/dig_help.rb +27 -0
- data/lib/rubocop/cop/mixin/endless_method_rewriter.rb +24 -0
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +3 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +5 -9
- data/lib/rubocop/cop/mixin/range_help.rb +0 -1
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +17 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
- data/lib/rubocop/cop/naming/constant_name.rb +6 -7
- data/lib/rubocop/cop/naming/file_name.rb +0 -2
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +11 -12
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +3 -11
- data/lib/rubocop/cop/naming/variable_name.rb +3 -4
- data/lib/rubocop/cop/naming/variable_number.rb +2 -3
- data/lib/rubocop/cop/offense.rb +2 -3
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +53 -24
- data/lib/rubocop/cop/style/ambiguous_endless_method_definition.rb +79 -0
- data/lib/rubocop/cop/style/array_intersect.rb +5 -4
- data/lib/rubocop/cop/style/bitwise_predicate.rb +100 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +18 -3
- data/lib/rubocop/cop/style/case_like_if.rb +8 -11
- data/lib/rubocop/cop/style/combinable_defined.rb +115 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +11 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +19 -21
- data/lib/rubocop/cop/style/constant_visibility.rb +3 -12
- data/lib/rubocop/cop/style/dig_chain.rb +90 -0
- data/lib/rubocop/cop/style/endless_method.rb +1 -14
- data/lib/rubocop/cop/style/file_null.rb +73 -0
- data/lib/rubocop/cop/style/file_touch.rb +75 -0
- data/lib/rubocop/cop/style/for.rb +0 -1
- data/lib/rubocop/cop/style/global_vars.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +15 -2
- data/lib/rubocop/cop/style/hash_conversion.rb +1 -2
- data/lib/rubocop/cop/style/if_inside_else.rb +0 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -2
- data/lib/rubocop/cop/style/if_with_semicolon.rb +14 -5
- data/lib/rubocop/cop/style/inverse_methods.rb +0 -1
- data/lib/rubocop/cop/style/keyword_arguments_merging.rb +67 -0
- data/lib/rubocop/cop/style/lambda_call.rb +0 -1
- data/lib/rubocop/cop/style/map_into_array.rb +6 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +7 -11
- data/lib/rubocop/cop/style/missing_respond_to_missing.rb +33 -3
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
- data/lib/rubocop/cop/style/multiple_comparison.rb +28 -39
- data/lib/rubocop/cop/style/mutable_constant.rb +4 -5
- data/lib/rubocop/cop/style/negated_if_else_condition.rb +6 -4
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +5 -4
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/one_line_conditional.rb +25 -4
- data/lib/rubocop/cop/style/operator_method_call.rb +5 -6
- data/lib/rubocop/cop/style/or_assignment.rb +3 -6
- data/lib/rubocop/cop/style/parallel_assignment.rb +8 -13
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +36 -21
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +21 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +9 -11
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +1 -0
- data/lib/rubocop/cop/style/redundant_return.rb +2 -2
- data/lib/rubocop/cop/style/redundant_self.rb +7 -14
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +7 -5
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +4 -4
- data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
- data/lib/rubocop/cop/style/rescue_modifier.rb +2 -3
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -1
- data/lib/rubocop/cop/style/safe_navigation_chain_length.rb +52 -0
- data/lib/rubocop/cop/style/select_by_regexp.rb +1 -1
- data/lib/rubocop/cop/style/self_assignment.rb +11 -17
- data/lib/rubocop/cop/style/signal_exception.rb +2 -3
- data/lib/rubocop/cop/style/single_argument_dig.rb +9 -5
- data/lib/rubocop/cop/style/single_line_do_end_block.rb +13 -3
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -3
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_concatenation.rb +0 -1
- data/lib/rubocop/cop/style/swap_values.rb +4 -15
- data/lib/rubocop/cop/style/ternary_parentheses.rb +25 -4
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +4 -4
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -2
- data/lib/rubocop/cop/variable_force/assignment.rb +18 -3
- data/lib/rubocop/cop/variable_force/branch.rb +1 -1
- data/lib/rubocop/cop/variable_force/variable.rb +5 -1
- data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
- data/lib/rubocop/cop/variable_force.rb +4 -10
- data/lib/rubocop/cops_documentation_generator.rb +20 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/runner.rb +16 -8
- data/lib/rubocop/target_ruby.rb +1 -1
- data/lib/rubocop/version.rb +27 -8
- data/lib/rubocop.rb +16 -0
- metadata +28 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97d8db05a66f5153d186df8720a9ea65237569f976c572053b4830925df4a825
|
4
|
+
data.tar.gz: a2864b5abc210251dc57f5ff1180043fd99069a3151cec6ab43824f9d4a40758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab8930edd85daa8e4eddbbedd1e6baa129875798644bcbb3b5e8d8359278d5f58fdc4f372d671654b21d7088606bab5202ef4c5fe34e38ad09e6590f5825339
|
7
|
+
data.tar.gz: 336decf7113d831b30a5ca8c8c71d324827853fb8f7102c646a1420957f8d3022f56d2f02c9e21791b280a9659138d0fe041202fff66cb33de9ea3d08548a876
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
|
|
52
52
|
in your `Gemfile`:
|
53
53
|
|
54
54
|
```rb
|
55
|
-
gem 'rubocop', '~> 1.
|
55
|
+
gem 'rubocop', '~> 1.69', require: false
|
56
56
|
```
|
57
57
|
|
58
58
|
See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
|
data/config/default.yml
CHANGED
@@ -1038,6 +1038,7 @@ Layout/LeadingCommentSpace:
|
|
1038
1038
|
AllowDoxygenCommentStyle: false
|
1039
1039
|
AllowGemfileRubyComment: false
|
1040
1040
|
AllowRBSInlineAnnotation: false
|
1041
|
+
AllowSteepAnnotation: false
|
1041
1042
|
|
1042
1043
|
Layout/LeadingEmptyLines:
|
1043
1044
|
Description: Check for unnecessary blank lines at the beginning of a file.
|
@@ -1085,11 +1086,11 @@ Layout/LineLength:
|
|
1085
1086
|
StyleGuide: '#max-line-length'
|
1086
1087
|
Enabled: true
|
1087
1088
|
VersionAdded: '0.25'
|
1088
|
-
VersionChanged: '1.
|
1089
|
+
VersionChanged: '1.69'
|
1089
1090
|
Max: 120
|
1091
|
+
AllowHeredoc: true
|
1090
1092
|
# To make it possible to copy or click on URIs in the code, we allow lines
|
1091
1093
|
# containing a URI to be longer than Max.
|
1092
|
-
AllowHeredoc: true
|
1093
1094
|
AllowURI: true
|
1094
1095
|
URISchemes:
|
1095
1096
|
- http
|
@@ -1101,6 +1102,8 @@ Layout/LineLength:
|
|
1101
1102
|
# elements. Strings will be converted to Regexp objects. A line that matches
|
1102
1103
|
# any regular expression listed in this option will be ignored by LineLength.
|
1103
1104
|
AllowedPatterns: []
|
1105
|
+
# If SplitStrings is true, long strings will be split using continuations
|
1106
|
+
SplitStrings: false
|
1104
1107
|
|
1105
1108
|
Layout/MultilineArrayBraceLayout:
|
1106
1109
|
Description: >-
|
@@ -1498,7 +1501,6 @@ Layout/SpaceInsideHashLiteralBraces:
|
|
1498
1501
|
- space
|
1499
1502
|
- no_space
|
1500
1503
|
|
1501
|
-
|
1502
1504
|
Layout/SpaceInsideParens:
|
1503
1505
|
Description: 'No spaces after ( or before ).'
|
1504
1506
|
StyleGuide: '#spaces-braces'
|
@@ -1633,7 +1635,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
|
|
1633
1635
|
Enabled: true
|
1634
1636
|
Safe: false
|
1635
1637
|
VersionAdded: '0.89'
|
1636
|
-
VersionChanged: '1.
|
1638
|
+
VersionChanged: '1.69'
|
1637
1639
|
|
1638
1640
|
Lint/BooleanSymbol:
|
1639
1641
|
Description: 'Check for `:true` and `:false` symbols.'
|
@@ -1785,6 +1787,7 @@ Lint/DuplicateBranch:
|
|
1785
1787
|
VersionChanged: '1.7'
|
1786
1788
|
IgnoreLiteralBranches: false
|
1787
1789
|
IgnoreConstantBranches: false
|
1790
|
+
IgnoreDuplicateElseBranch: false
|
1788
1791
|
|
1789
1792
|
Lint/DuplicateCaseCondition:
|
1790
1793
|
Description: 'Do not repeat values in case conditionals.'
|
@@ -1954,6 +1957,11 @@ Lint/HashCompareByIdentity:
|
|
1954
1957
|
Safe: false
|
1955
1958
|
VersionAdded: '0.93'
|
1956
1959
|
|
1960
|
+
Lint/HashNewWithKeywordArgumentsAsDefault:
|
1961
|
+
Description: 'Checks for the deprecated use of keyword arguments for hash default in `Hash.new`.'
|
1962
|
+
Enabled: pending
|
1963
|
+
VersionAdded: '1.69'
|
1964
|
+
|
1957
1965
|
Lint/HeredocMethodCallPosition:
|
1958
1966
|
Description: >-
|
1959
1967
|
Checks for the ordering of a method call where
|
@@ -2144,6 +2152,11 @@ Lint/NumberedParameterAssignment:
|
|
2144
2152
|
Enabled: pending
|
2145
2153
|
VersionAdded: '1.9'
|
2146
2154
|
|
2155
|
+
Lint/NumericOperationWithConstantResult:
|
2156
|
+
Description: 'Checks for numeric operations with constant results.'
|
2157
|
+
Enabled: pending
|
2158
|
+
VersionAdded: '1.69'
|
2159
|
+
|
2147
2160
|
Lint/OrAssignmentToConstant:
|
2148
2161
|
Description: 'Checks unintended or-assignment to constant.'
|
2149
2162
|
Enabled: pending
|
@@ -2375,7 +2388,6 @@ Lint/ShadowedArgument:
|
|
2375
2388
|
VersionAdded: '0.52'
|
2376
2389
|
IgnoreImplicitReferences: false
|
2377
2390
|
|
2378
|
-
|
2379
2391
|
Lint/ShadowedException:
|
2380
2392
|
Description: >-
|
2381
2393
|
Avoid rescuing a higher level exception
|
@@ -2455,6 +2467,11 @@ Lint/UnderscorePrefixedVariableName:
|
|
2455
2467
|
VersionAdded: '0.21'
|
2456
2468
|
AllowKeywordBlockArguments: false
|
2457
2469
|
|
2470
|
+
Lint/UnescapedBracketInRegexp:
|
2471
|
+
Description: 'Checks for unescaped literal `]` in Regexp.'
|
2472
|
+
Enabled: pending
|
2473
|
+
VersionAdded: '1.68'
|
2474
|
+
|
2458
2475
|
Lint/UnexpectedBlockArity:
|
2459
2476
|
Description: 'Looks for blocks that have fewer arguments that the calling method expects.'
|
2460
2477
|
Enabled: pending
|
@@ -2514,10 +2531,12 @@ Lint/UnusedMethodArgument:
|
|
2514
2531
|
Enabled: true
|
2515
2532
|
AutoCorrect: contextual
|
2516
2533
|
VersionAdded: '0.21'
|
2517
|
-
VersionChanged: '1.
|
2534
|
+
VersionChanged: '1.69'
|
2518
2535
|
AllowUnusedKeywordArguments: false
|
2519
2536
|
IgnoreEmptyMethods: true
|
2520
2537
|
IgnoreNotImplementedMethods: true
|
2538
|
+
NotImplementedExceptions:
|
2539
|
+
- NotImplementedError
|
2521
2540
|
|
2522
2541
|
Lint/UriEscapeUnescape:
|
2523
2542
|
Description: >-
|
@@ -2552,6 +2571,11 @@ Lint/UselessAssignment:
|
|
2552
2571
|
VersionAdded: '0.11'
|
2553
2572
|
VersionChanged: '1.66'
|
2554
2573
|
|
2574
|
+
Lint/UselessDefined:
|
2575
|
+
Description: 'Checks for calls to `defined?` with strings and symbols. The result of such a call will always be truthy.'
|
2576
|
+
Enabled: pending
|
2577
|
+
VersionAdded: '1.69'
|
2578
|
+
|
2555
2579
|
Lint/UselessElseWithoutRescue:
|
2556
2580
|
Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
|
2557
2581
|
Enabled: true
|
@@ -3143,6 +3167,12 @@ Style/Alias:
|
|
3143
3167
|
- prefer_alias
|
3144
3168
|
- prefer_alias_method
|
3145
3169
|
|
3170
|
+
Style/AmbiguousEndlessMethodDefinition:
|
3171
|
+
Description: 'Checks for endless methods inside operators of lower precedence.'
|
3172
|
+
StyleGuide: '#ambiguous-endless-method-defintions'
|
3173
|
+
Enabled: pending
|
3174
|
+
VersionAdded: '1.68'
|
3175
|
+
|
3146
3176
|
Style/AndOr:
|
3147
3177
|
Description: 'Use &&/|| instead of and/or.'
|
3148
3178
|
StyleGuide: '#no-and-or-or'
|
@@ -3250,6 +3280,13 @@ Style/BisectedAttrAccessor:
|
|
3250
3280
|
Enabled: true
|
3251
3281
|
VersionAdded: '0.87'
|
3252
3282
|
|
3283
|
+
Style/BitwisePredicate:
|
3284
|
+
Description: 'Prefer bitwise predicate methods over direct comparison operations.'
|
3285
|
+
StyleGuide: '#bitwise-predicate-methods'
|
3286
|
+
Enabled: pending
|
3287
|
+
Safe: false
|
3288
|
+
VersionAdded: '1.68'
|
3289
|
+
|
3253
3290
|
Style/BlockComments:
|
3254
3291
|
Description: 'Do not use block comments.'
|
3255
3292
|
StyleGuide: '#no-block-comments'
|
@@ -3533,6 +3570,11 @@ Style/ColonMethodDefinition:
|
|
3533
3570
|
Enabled: true
|
3534
3571
|
VersionAdded: '0.52'
|
3535
3572
|
|
3573
|
+
Style/CombinableDefined:
|
3574
|
+
Description: 'Checks successive `defined?` calls that can be combined into a single call.'
|
3575
|
+
Enabled: pending
|
3576
|
+
VersionAdded: '1.68'
|
3577
|
+
|
3536
3578
|
Style/CombinableLoops:
|
3537
3579
|
Description: >-
|
3538
3580
|
Checks for places where multiple consecutive loops over the same data
|
@@ -3673,6 +3715,12 @@ Style/DefWithParentheses:
|
|
3673
3715
|
VersionAdded: '0.9'
|
3674
3716
|
VersionChanged: '0.12'
|
3675
3717
|
|
3718
|
+
Style/DigChain:
|
3719
|
+
Description: 'Use `dig` with multiple parameters instead of chaining multiple calls.'
|
3720
|
+
Enabled: pending
|
3721
|
+
Safe: false
|
3722
|
+
VersionAdded: '1.69'
|
3723
|
+
|
3676
3724
|
Style/Dir:
|
3677
3725
|
Description: >-
|
3678
3726
|
Use the `__dir__` method to retrieve the canonicalized
|
@@ -3899,12 +3947,24 @@ Style/FileEmpty:
|
|
3899
3947
|
Safe: false
|
3900
3948
|
VersionAdded: '1.48'
|
3901
3949
|
|
3950
|
+
Style/FileNull:
|
3951
|
+
Description: 'Use `File::NULL` instead of hardcoding "dev/null".'
|
3952
|
+
Enabled: pending
|
3953
|
+
SafeAutoCorrect: false
|
3954
|
+
VersionAdded: '1.69'
|
3955
|
+
|
3902
3956
|
Style/FileRead:
|
3903
3957
|
Description: 'Favor `File.(bin)read` convenience methods.'
|
3904
3958
|
StyleGuide: '#file-read'
|
3905
3959
|
Enabled: pending
|
3906
3960
|
VersionAdded: '1.24'
|
3907
3961
|
|
3962
|
+
Style/FileTouch:
|
3963
|
+
Description: 'Favor `FileUtils.touch` for touching files.'
|
3964
|
+
Enabled: pending
|
3965
|
+
VersionAdded: '1.69'
|
3966
|
+
SafeAutoCorrect: false
|
3967
|
+
|
3908
3968
|
Style/FileWrite:
|
3909
3969
|
Description: 'Favor `File.(bin)write` convenience methods.'
|
3910
3970
|
StyleGuide: '#file-write'
|
@@ -4256,6 +4316,14 @@ Style/IpAddresses:
|
|
4256
4316
|
- '**/gems.rb'
|
4257
4317
|
- '**/*.gemspec'
|
4258
4318
|
|
4319
|
+
Style/KeywordArgumentsMerging:
|
4320
|
+
Description: >-
|
4321
|
+
When passing an existing hash as keyword arguments, provide additional arguments
|
4322
|
+
directly rather than using `merge`.
|
4323
|
+
StyleGuide: '#merging-keyword-arguments'
|
4324
|
+
Enabled: pending
|
4325
|
+
VersionAdded: '1.68'
|
4326
|
+
|
4259
4327
|
Style/KeywordParametersOrder:
|
4260
4328
|
Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
|
4261
4329
|
StyleGuide: '#keyword-parameters-order'
|
@@ -5241,6 +5309,13 @@ Style/SafeNavigation:
|
|
5241
5309
|
# Maximum length of method chains for register an offense.
|
5242
5310
|
MaxChainLength: 2
|
5243
5311
|
|
5312
|
+
Style/SafeNavigationChainLength:
|
5313
|
+
Description: 'Enforces safe navigation chains length to not exceed the configured maximum.'
|
5314
|
+
StyleGuide: '#safe-navigation'
|
5315
|
+
Enabled: pending
|
5316
|
+
VersionAdded: '1.68'
|
5317
|
+
Max: 2
|
5318
|
+
|
5244
5319
|
Style/Sample:
|
5245
5320
|
Description: >-
|
5246
5321
|
Use `sample` instead of `shuffle.first`,
|
data/lib/rubocop/cached_data.rb
CHANGED
@@ -45,15 +45,13 @@ module RuboCop
|
|
45
45
|
|
46
46
|
# Restore an offense object loaded from a JSON file.
|
47
47
|
def deserialize_offenses(offenses)
|
48
|
-
source_buffer = Parser::Source::Buffer.new(@filename)
|
49
|
-
source_buffer.source = File.read(@filename, encoding: Encoding::UTF_8)
|
50
48
|
offenses.map! do |o|
|
51
|
-
location = location_from_source_buffer(o
|
49
|
+
location = location_from_source_buffer(o)
|
52
50
|
Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym)
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
def location_from_source_buffer(offense
|
54
|
+
def location_from_source_buffer(offense)
|
57
55
|
begin_pos = offense['location']['begin_pos']
|
58
56
|
end_pos = offense['location']['end_pos']
|
59
57
|
if begin_pos.zero? && end_pos.zero?
|
@@ -62,5 +60,15 @@ module RuboCop
|
|
62
60
|
Parser::Source::Range.new(source_buffer, begin_pos, end_pos)
|
63
61
|
end
|
64
62
|
end
|
63
|
+
|
64
|
+
# Delay creation until needed. Some type of offenses will have no buffer associated with them
|
65
|
+
# and be global only. For these, trying to create the buffer will likely fail, for example
|
66
|
+
# because of unknown encoding comments.
|
67
|
+
def source_buffer
|
68
|
+
@source_buffer ||= begin
|
69
|
+
source = File.read(@filename, encoding: Encoding::UTF_8)
|
70
|
+
Parser::Source::Buffer.new(@filename, source: source)
|
71
|
+
end
|
72
|
+
end
|
65
73
|
end
|
66
74
|
end
|
@@ -9,8 +9,8 @@ module RuboCop
|
|
9
9
|
self.command_name = :version
|
10
10
|
|
11
11
|
def run
|
12
|
-
puts RuboCop::Version
|
13
|
-
puts RuboCop::Version.
|
12
|
+
puts RuboCop::Version::STRING if @options[:version]
|
13
|
+
puts RuboCop::Version.verbose(env: env) if @options[:verbose_version]
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -49,7 +49,9 @@ module RuboCop
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def disable_offense(offense_range)
|
52
|
-
range = surrounding_heredoc(offense_range) ||
|
52
|
+
range = surrounding_heredoc(offense_range) ||
|
53
|
+
surrounding_percent_array(offense_range) ||
|
54
|
+
string_continuation(offense_range)
|
53
55
|
|
54
56
|
if range
|
55
57
|
disable_offense_before_and_after(range_by_lines(range))
|
@@ -88,10 +90,28 @@ module RuboCop
|
|
88
90
|
end
|
89
91
|
|
90
92
|
percent_array.map(&:source_range).find do |range|
|
91
|
-
offense_range
|
93
|
+
range_overlaps_offense?(offense_range, range)
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
97
|
+
def string_continuation(offense_range)
|
98
|
+
return nil if offense_range.empty?
|
99
|
+
|
100
|
+
string_continuation_nodes = processed_source.ast.each_descendant.filter_map do |node|
|
101
|
+
range_by_lines(node.source_range) if string_continuation?(node)
|
102
|
+
end
|
103
|
+
|
104
|
+
string_continuation_nodes.find { |range| range_overlaps_offense?(offense_range, range) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def range_overlaps_offense?(offense_range, range)
|
108
|
+
offense_range.begin_pos > range.begin_pos && range.overlaps?(offense_range)
|
109
|
+
end
|
110
|
+
|
111
|
+
def string_continuation?(node)
|
112
|
+
(node.str_type? || node.dstr_type? || node.xstr_type?) && node.source.match?(/\\\s*$/)
|
113
|
+
end
|
114
|
+
|
95
115
|
def range_of_first_line(range)
|
96
116
|
begin_of_first_line = range.begin_pos - range.column
|
97
117
|
end_of_first_line = begin_of_first_line + range.source_line.length
|
data/lib/rubocop/cop/base.rb
CHANGED
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
[]
|
61
61
|
end
|
62
62
|
|
63
|
-
# Returns
|
63
|
+
# Returns a url to view this cops documentation online.
|
64
64
|
# Requires 'DocumentationBaseURL' to be set for your department.
|
65
65
|
# Will follow the convention of RuboCops own documentation structure,
|
66
66
|
# overwrite this method to accommodate your custom layout.
|
@@ -27,7 +27,6 @@ module RuboCop
|
|
27
27
|
# Project contains gems.rb and gems.locked files
|
28
28
|
class GemFilename < Base
|
29
29
|
include ConfigurableEnforcedStyle
|
30
|
-
include RangeHelp
|
31
30
|
|
32
31
|
MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required ' \
|
33
32
|
'(file path: %<file_path>s).'
|
@@ -47,7 +47,7 @@ module RuboCop
|
|
47
47
|
if column_delta.positive? && range.resize(1).source != "\n"
|
48
48
|
corrector.insert_before(range, ' ' * column_delta)
|
49
49
|
elsif /\A[ \t]+\z/.match?(range.source)
|
50
|
-
remove(range
|
50
|
+
corrector.remove(range)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -96,17 +96,6 @@ module RuboCop
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def remove(range, corrector)
|
100
|
-
original_stderr = $stderr
|
101
|
-
$stderr = StringIO.new # Avoid error messages on console
|
102
|
-
corrector.remove(range)
|
103
|
-
rescue RuntimeError
|
104
|
-
range = range_between(range.begin_pos + 1, range.end_pos + 1)
|
105
|
-
retry if /^ +$/.match?(range.source)
|
106
|
-
ensure
|
107
|
-
$stderr = original_stderr
|
108
|
-
end
|
109
|
-
|
110
99
|
def each_line(expr)
|
111
100
|
line_begin_pos = expr.begin_pos
|
112
101
|
expr.source.each_line do |line|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
def requires_parentheses?
|
40
40
|
return true if collection_node.send_type? && collection_node.operator_method?
|
41
41
|
|
42
|
-
collection_node.range_type? || collection_node.
|
42
|
+
collection_node.range_type? || collection_node.operator_keyword?
|
43
43
|
end
|
44
44
|
|
45
45
|
def end_range
|
@@ -94,6 +94,16 @@ module RuboCop
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def substitute_escaped_delimiters(content, delimiters)
|
97
|
+
if delimiters.first != delimiters.last
|
98
|
+
# With different delimiters (eg. `[]`, `()`), if there are the same
|
99
|
+
# number of each, escaping is not necessary
|
100
|
+
delimiter_counts = delimiters.each_with_object({}) do |delimiter, counts|
|
101
|
+
counts[delimiter] = content.count(delimiter)
|
102
|
+
end
|
103
|
+
|
104
|
+
return content if delimiter_counts[delimiters.first] == delimiter_counts[delimiters.last]
|
105
|
+
end
|
106
|
+
|
97
107
|
delimiters.each { |delim| content.gsub!(delim, "\\#{delim}") }
|
98
108
|
end
|
99
109
|
|
@@ -53,8 +53,6 @@ module RuboCop
|
|
53
53
|
# spec.required_ruby_version = '~> 2.5'
|
54
54
|
# end
|
55
55
|
class RequiredRubyVersion < Base
|
56
|
-
include RangeHelp
|
57
|
-
|
58
56
|
RESTRICT_ON_SEND = %i[required_ruby_version=].freeze
|
59
57
|
NOT_EQUAL_MSG = '`required_ruby_version` and `TargetRubyVersion` ' \
|
60
58
|
'(%<target_ruby_version>s, which may be specified in ' \
|
@@ -36,10 +36,8 @@ module RuboCop
|
|
36
36
|
def on_send(node)
|
37
37
|
return unless location_line_equality_comparison?(node)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
lhs_receiver = extract_receiver(lhs)
|
42
|
-
rhs_receiver = extract_receiver(rhs)
|
39
|
+
lhs_receiver = extract_receiver(node.receiver)
|
40
|
+
rhs_receiver = extract_receiver(node.first_argument)
|
43
41
|
preferred = "same_line?(#{lhs_receiver}, #{rhs_receiver})"
|
44
42
|
|
45
43
|
add_offense(node, message: format(MSG, preferred: preferred)) do |corrector|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module InternalAffairs
|
6
|
-
# Checks for missing `numblock handlers. The blocks with numbered
|
6
|
+
# Checks for missing `numblock` handlers. The blocks with numbered
|
7
7
|
# arguments introduced in Ruby 2.7 are parsed with a node type of
|
8
8
|
# `numblock` instead of block. Cops that define `block` handlers
|
9
9
|
# need to define `numblock` handlers or disable this cope for them.
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InternalAffairs
|
6
|
+
# Enforces the use of `node.operator_keyword?` instead of `node.and_type? || node.or_type?`.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# node.and_type? || node.or_type?
|
11
|
+
# node.or_type? || node.and_type?
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
# node.operator_keyword?
|
15
|
+
#
|
16
|
+
class OperatorKeyword < Base
|
17
|
+
extend AutoCorrector
|
18
|
+
|
19
|
+
MSG = 'Use `%<prefer>s`.'
|
20
|
+
|
21
|
+
# @!method and_or_type(node)
|
22
|
+
def_node_matcher :and_or_type, <<~PATTERN
|
23
|
+
{
|
24
|
+
(or $(send _node :and_type?) $(send _node :or_type?))
|
25
|
+
(or $(send _node :or_type?) $(send _node :and_type?))
|
26
|
+
(or
|
27
|
+
(or _ $(send _node :and_type?)) $(send _node :or_type?))
|
28
|
+
(or
|
29
|
+
(or _ $(send _node :or_type?)) $(send _node :and_type?))
|
30
|
+
}
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_or(node)
|
34
|
+
return unless (lhs, rhs = and_or_type(node))
|
35
|
+
|
36
|
+
offense = lhs.receiver.source_range.join(rhs.source_range.end)
|
37
|
+
prefer = "#{lhs.receiver.source}.operator_keyword?"
|
38
|
+
|
39
|
+
add_offense(offense, message: format(MSG, prefer: prefer)) do |corrector|
|
40
|
+
corrector.replace(offense, prefer)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -17,6 +17,7 @@ require_relative 'internal_affairs/node_matcher_directive'
|
|
17
17
|
require_relative 'internal_affairs/node_type_predicate'
|
18
18
|
require_relative 'internal_affairs/numblock_handler'
|
19
19
|
require_relative 'internal_affairs/offense_location_keyword'
|
20
|
+
require_relative 'internal_affairs/operator_keyword'
|
20
21
|
require_relative 'internal_affairs/processed_source_buffer_name'
|
21
22
|
require_relative 'internal_affairs/redundant_context_config_parameter'
|
22
23
|
require_relative 'internal_affairs/redundant_described_class_as_subject'
|
@@ -3,8 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
#
|
7
|
-
# definition are aligned.
|
6
|
+
# Check that the arguments on a multi-line method definition are aligned.
|
8
7
|
#
|
9
8
|
# @example EnforcedStyle: with_first_argument (default)
|
10
9
|
# # good
|
@@ -127,7 +127,6 @@ module RuboCop
|
|
127
127
|
start_loc,
|
128
128
|
end_loc,
|
129
129
|
do_source_line_column)
|
130
|
-
|
131
130
|
error_source_line_column = if style == :start_of_block
|
132
131
|
do_source_line_column
|
133
132
|
else
|
@@ -189,7 +188,7 @@ module RuboCop
|
|
189
188
|
# In offense message, we want to show the assignment LHS rather than
|
190
189
|
# the entire assignment.
|
191
190
|
def find_lhs_node(node)
|
192
|
-
node
|
191
|
+
node = node.lhs while node.op_asgn_type? || node.masgn_type?
|
193
192
|
node
|
194
193
|
end
|
195
194
|
|
@@ -200,7 +200,7 @@ module RuboCop
|
|
200
200
|
parent = node.parent
|
201
201
|
return false unless parent
|
202
202
|
|
203
|
-
parent.begin_type? &&
|
203
|
+
parent.begin_type? && same_line?(node, node.right_sibling)
|
204
204
|
end
|
205
205
|
|
206
206
|
# SimpleCov excludes code from the coverage report by wrapping it in `# :nocov:`:
|
@@ -84,9 +84,8 @@ module RuboCop
|
|
84
84
|
|
85
85
|
alias on_numblock on_block
|
86
86
|
|
87
|
-
def on_send(node)
|
88
|
-
return unless node.bare_access_modifier? &&
|
89
|
-
!(node.parent&.block_type? || node.parent&.numblock_type?)
|
87
|
+
def on_send(node)
|
88
|
+
return unless node.bare_access_modifier? && !node.block_literal?
|
90
89
|
return if expected_empty_lines?(node)
|
91
90
|
|
92
91
|
message = message(node)
|
@@ -72,8 +72,7 @@ module RuboCop
|
|
72
72
|
alias on_numblock on_def
|
73
73
|
|
74
74
|
def on_kwbegin(node)
|
75
|
-
|
76
|
-
check_body(body, node.loc.line)
|
75
|
+
check_body(node.children.first, node.loc.line)
|
77
76
|
end
|
78
77
|
|
79
78
|
private
|
@@ -128,10 +127,10 @@ module RuboCop
|
|
128
127
|
end
|
129
128
|
|
130
129
|
def keyword_locations_in_ensure(node)
|
131
|
-
|
130
|
+
rescue_body_without_ensure = node.children.first
|
132
131
|
[
|
133
132
|
node.loc.keyword,
|
134
|
-
*keyword_locations(
|
133
|
+
*keyword_locations(rescue_body_without_ensure)
|
135
134
|
]
|
136
135
|
end
|
137
136
|
end
|