rubocop 1.42.0 → 1.45.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +73 -31
  4. data/lib/rubocop/cli.rb +54 -8
  5. data/lib/rubocop/config_loader.rb +12 -15
  6. data/lib/rubocop/config_loader_resolver.rb +3 -4
  7. data/lib/rubocop/cop/base.rb +27 -9
  8. data/lib/rubocop/cop/commissioner.rb +8 -2
  9. data/lib/rubocop/cop/cop.rb +23 -3
  10. data/lib/rubocop/cop/corrector.rb +10 -2
  11. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -6
  12. data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
  13. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
  14. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  15. data/lib/rubocop/cop/layout/block_end_newline.rb +7 -1
  16. data/lib/rubocop/cop/layout/class_structure.rb +2 -16
  17. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
  18. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  19. data/lib/rubocop/cop/layout/heredoc_indentation.rb +6 -9
  20. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  21. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  22. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
  23. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
  24. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
  25. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
  26. data/lib/rubocop/cop/lint/debugger.rb +8 -27
  27. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
  28. data/lib/rubocop/cop/lint/else_layout.rb +2 -6
  29. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
  30. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
  31. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  32. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
  33. data/lib/rubocop/cop/lint/nested_method_definition.rb +8 -5
  34. data/lib/rubocop/cop/lint/redundant_require_statement.rb +11 -1
  35. data/lib/rubocop/cop/lint/useless_access_modifier.rb +7 -4
  36. data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -3
  37. data/lib/rubocop/cop/lint/useless_rescue.rb +85 -0
  38. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
  39. data/lib/rubocop/cop/lint/void.rb +19 -10
  40. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  41. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  42. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  43. data/lib/rubocop/cop/metrics/parameter_lists.rb +27 -0
  44. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -5
  45. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  46. data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
  47. data/lib/rubocop/cop/mixin/comments_help.rb +5 -3
  48. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +57 -23
  49. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
  50. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -0
  51. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  52. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  53. data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
  54. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  55. data/lib/rubocop/cop/registry.rb +12 -7
  56. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
  57. data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -0
  58. data/lib/rubocop/cop/style/block_delimiters.rb +8 -2
  59. data/lib/rubocop/cop/style/class_and_module_children.rb +3 -10
  60. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  61. data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
  62. data/lib/rubocop/cop/style/conditional_assignment.rb +0 -6
  63. data/lib/rubocop/cop/style/documentation.rb +1 -1
  64. data/lib/rubocop/cop/style/documentation_method.rb +6 -0
  65. data/lib/rubocop/cop/style/hash_each_methods.rb +13 -1
  66. data/lib/rubocop/cop/style/hash_syntax.rb +1 -0
  67. data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
  68. data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
  69. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +23 -14
  70. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
  71. data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
  72. data/lib/rubocop/cop/style/missing_else.rb +13 -1
  73. data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
  74. data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
  75. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
  76. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -5
  77. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
  78. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
  79. data/lib/rubocop/cop/style/operator_method_call.rb +16 -2
  80. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -1
  81. data/lib/rubocop/cop/style/redundant_condition.rb +16 -1
  82. data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
  83. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
  84. data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
  85. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +2 -1
  86. data/lib/rubocop/cop/style/require_order.rb +2 -9
  87. data/lib/rubocop/cop/style/self_assignment.rb +2 -2
  88. data/lib/rubocop/cop/style/semicolon.rb +24 -2
  89. data/lib/rubocop/cop/style/string_hash_keys.rb +4 -1
  90. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  91. data/lib/rubocop/cop/style/word_array.rb +1 -1
  92. data/lib/rubocop/cop/style/yoda_condition.rb +12 -5
  93. data/lib/rubocop/cop/style/yoda_expression.rb +18 -2
  94. data/lib/rubocop/cop/team.rb +19 -14
  95. data/lib/rubocop/cop/variable_force/scope.rb +3 -3
  96. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
  97. data/lib/rubocop/cop/variable_force.rb +1 -1
  98. data/lib/rubocop/formatter.rb +0 -1
  99. data/lib/rubocop/options.rb +22 -1
  100. data/lib/rubocop/path_util.rb +11 -6
  101. data/lib/rubocop/rspec/expect_offense.rb +6 -4
  102. data/lib/rubocop/runner.rb +40 -4
  103. data/lib/rubocop/server/cache.rb +10 -3
  104. data/lib/rubocop/server/cli.rb +37 -18
  105. data/lib/rubocop/server/client_command/exec.rb +1 -1
  106. data/lib/rubocop/server/client_command/start.rb +6 -1
  107. data/lib/rubocop/server/core.rb +23 -8
  108. data/lib/rubocop/version.rb +1 -1
  109. data/lib/rubocop.rb +5 -0
  110. metadata +12 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e37ffc01dbd2782dd811d4c35129f893502179457e76d8e3501d7c3683563cc2
4
- data.tar.gz: 9dba5be8e2168e986170e8366a62c73940262bfffec0a374c3a01b3f207ca291
3
+ metadata.gz: 648a8aa3156aebf0c078bc0b600f301d3aa0abaf92d6b3643c343718575f7302
4
+ data.tar.gz: 21b185886d70b70a163c6e7f3ea47e04ee0a0afcf11217e0d7bcb31e25440880
5
5
  SHA512:
6
- metadata.gz: 23769dc5239a734dc07a859a594e1cc0b732d05d24c61c1887525f9f69f748e0c23cbb84404e865e00a04bfb5c91e73d1e0bdb7908a72340ede4245fc38508c6
7
- data.tar.gz: f016891fb54e93a8f6c418d4aa97f7400a74c187c8cf5dbbe274020ea5bda900721f2a7fefbbb368472664cf21a4b586db4fb9373510c27da6428aa490d504e6
6
+ metadata.gz: ff5a5e947001ba9507f3e806896559baaf0e4bccc6b2cc56316dffc3ae334f62046040be389518139d2979c4d09900600f9b233bc1f4dbd2d1d37a2f8fe99037
7
+ data.tar.gz: 8f89f55198c9d206c5b8d0c32cbeb5033491046c0ea0f4311f6c1a23595bcce852ec732606ca1fd2bc499b31ecb2265dcf6d85edd352f6400d01bd9385993a44
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.42', require: false
56
+ gem 'rubocop', '~> 1.45', 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
@@ -262,6 +262,21 @@ Gemspec/DeprecatedAttributeAssignment:
262
262
  Include:
263
263
  - '**/*.gemspec'
264
264
 
265
+ Gemspec/DevelopmentDependencies:
266
+ Description: Checks that development dependencies are specified in Gemfile rather than gemspec.
267
+ Enabled: pending
268
+ VersionAdded: '1.44'
269
+ EnforcedStyle: Gemfile
270
+ SupportedStyles:
271
+ - Gemfile
272
+ - gems.rb
273
+ - gemspec
274
+ AllowedGems: []
275
+ Include:
276
+ - '**/*.gemspec'
277
+ - '**/Gemfile'
278
+ - '**/gems.rb'
279
+
265
280
  Gemspec/DuplicatedAssignment:
266
281
  Description: 'An attribute assignment method calls should be listed only once in a gemspec.'
267
282
  Enabled: true
@@ -391,9 +406,8 @@ Layout/AssignmentIndentation:
391
406
  Checks the indentation of the first line of the
392
407
  right-hand-side of a multi-line assignment.
393
408
  Enabled: true
394
- SafeAutoCorrect: false
395
409
  VersionAdded: '0.49'
396
- VersionChanged: '1.40'
410
+ VersionChanged: '1.45'
397
411
  # By default the indentation width from `Layout/IndentationWidth` is used,
398
412
  # but it can be overridden by setting this parameter.
399
413
  IndentationWidth: ~
@@ -964,7 +978,6 @@ Layout/IndentationWidth:
964
978
  # Number of spaces for each indentation level.
965
979
  Width: 2
966
980
  AllowedPatterns: []
967
- IgnoredPatterns: [] # deprecated
968
981
 
969
982
  Layout/InitialIndentation:
970
983
  Description: >-
@@ -992,10 +1005,8 @@ Layout/LineContinuationLeadingSpace:
992
1005
  Use trailing spaces instead of leading spaces in strings
993
1006
  broken over multiple lines (by a backslash).
994
1007
  Enabled: pending
995
- AutoCorrect: false
996
- SafeAutoCorrect: false
997
1008
  VersionAdded: '1.31'
998
- VersionChanged: '1.32'
1009
+ VersionChanged: '1.45'
999
1010
  EnforcedStyle: trailing
1000
1011
  SupportedStyles:
1001
1012
  - leading
@@ -1047,7 +1058,6 @@ Layout/LineLength:
1047
1058
  # elements. Strings will be converted to Regexp objects. A line that matches
1048
1059
  # any regular expression listed in this option will be ignored by LineLength.
1049
1060
  AllowedPatterns: []
1050
- IgnoredPatterns: [] # deprecated
1051
1061
 
1052
1062
  Layout/MultilineArrayBraceLayout:
1053
1063
  Description: >-
@@ -1526,7 +1536,6 @@ Lint/AmbiguousBlockAssociation:
1526
1536
  VersionChanged: '1.13'
1527
1537
  AllowedMethods: []
1528
1538
  AllowedPatterns: []
1529
- IgnoredMethods: [] # deprecated
1530
1539
 
1531
1540
  Lint/AmbiguousOperator:
1532
1541
  Description: >-
@@ -1563,7 +1572,9 @@ Lint/AssignmentInCondition:
1563
1572
  Description: "Don't use assignment in conditions."
1564
1573
  StyleGuide: '#safe-assignment-in-condition'
1565
1574
  Enabled: true
1575
+ SafeAutoCorrect: false
1566
1576
  VersionAdded: '0.9'
1577
+ VersionChanged: '1.45'
1567
1578
  AllowSafeAssignment: true
1568
1579
 
1569
1580
  Lint/BigDecimalNew:
@@ -1620,12 +1631,12 @@ Lint/Debugger:
1620
1631
  Enabled: true
1621
1632
  VersionAdded: '0.14'
1622
1633
  VersionChanged: '1.10'
1623
- DebuggerReceivers: [] # deprecated
1624
1634
  DebuggerMethods:
1625
1635
  # Groups are available so that a specific group can be disabled in
1626
1636
  # a user's configuration, but are otherwise not significant.
1627
1637
  Kernel:
1628
1638
  - binding.irb
1639
+ - p
1629
1640
  - Kernel.binding.irb
1630
1641
  Byebug:
1631
1642
  - byebug
@@ -1635,6 +1646,9 @@ Lint/Debugger:
1635
1646
  Capybara:
1636
1647
  - save_and_open_page
1637
1648
  - save_and_open_screenshot
1649
+ PP:
1650
+ - PP.pp
1651
+ - pp
1638
1652
  debug.rb:
1639
1653
  - binding.b
1640
1654
  - binding.break
@@ -2037,7 +2051,6 @@ Lint/NumberConversion:
2037
2051
  SafeAutoCorrect: false
2038
2052
  AllowedMethods: []
2039
2053
  AllowedPatterns: []
2040
- IgnoredMethods: [] # deprecated
2041
2054
  IgnoredClasses:
2042
2055
  - Time
2043
2056
  - DateTime
@@ -2388,7 +2401,6 @@ Lint/UnreachableLoop:
2388
2401
  # RSpec uses `times` in its message expectations
2389
2402
  # eg. `exactly(2).times`
2390
2403
  - !ruby/regexp /(exactly|at_least|at_most)\(\d+\)\.times/
2391
- IgnoredPatterns: [] # deprecated
2392
2404
 
2393
2405
  Lint/UnusedBlockArgument:
2394
2406
  Description: 'Checks for unused block arguments.'
@@ -2452,6 +2464,11 @@ Lint/UselessMethodDefinition:
2452
2464
  VersionChanged: '0.91'
2453
2465
  Safe: false
2454
2466
 
2467
+ Lint/UselessRescue:
2468
+ Description: 'Checks for useless `rescue`s.'
2469
+ Enabled: pending
2470
+ VersionAdded: '1.43'
2471
+
2455
2472
  Lint/UselessRuby2Keywords:
2456
2473
  Description: 'Finds unnecessary uses of `ruby2_keywords`.'
2457
2474
  Enabled: pending
@@ -2493,7 +2510,6 @@ Metrics/AbcSize:
2493
2510
  # a Float.
2494
2511
  AllowedMethods: []
2495
2512
  AllowedPatterns: []
2496
- IgnoredMethods: [] # deprecated
2497
2513
  CountRepeatedAttributes: true
2498
2514
  Max: 17
2499
2515
 
@@ -2505,13 +2521,11 @@ Metrics/BlockLength:
2505
2521
  CountComments: false # count full line comments?
2506
2522
  Max: 25
2507
2523
  CountAsOne: []
2508
- ExcludedMethods: [] # deprecated, retained for backwards compatibility
2509
2524
  AllowedMethods:
2510
2525
  # By default, exclude the `#refine` method, as it tends to have larger
2511
2526
  # associated blocks.
2512
2527
  - refine
2513
2528
  AllowedPatterns: []
2514
- IgnoredMethods: [] # deprecated
2515
2529
  Exclude:
2516
2530
  - '**/*.gemspec'
2517
2531
 
@@ -2543,7 +2557,6 @@ Metrics/CyclomaticComplexity:
2543
2557
  VersionChanged: '0.81'
2544
2558
  AllowedMethods: []
2545
2559
  AllowedPatterns: []
2546
- IgnoredMethods: [] # deprecated
2547
2560
  Max: 7
2548
2561
 
2549
2562
  Metrics/MethodLength:
@@ -2555,10 +2568,8 @@ Metrics/MethodLength:
2555
2568
  CountComments: false # count full line comments?
2556
2569
  Max: 10
2557
2570
  CountAsOne: []
2558
- ExcludedMethods: [] # deprecated, retained for backwards compatibility
2559
2571
  AllowedMethods: []
2560
2572
  AllowedPatterns: []
2561
- IgnoredMethods: [] # deprecated
2562
2573
 
2563
2574
  Metrics/ModuleLength:
2564
2575
  Description: 'Avoid modules longer than 100 lines of code.'
@@ -2588,7 +2599,6 @@ Metrics/PerceivedComplexity:
2588
2599
  VersionChanged: '0.81'
2589
2600
  AllowedMethods: []
2590
2601
  AllowedPatterns: []
2591
- IgnoredMethods: [] # deprecated
2592
2602
  Max: 8
2593
2603
 
2594
2604
  ################## Migration #############################
@@ -2759,7 +2769,7 @@ Naming/HeredocDelimiterNaming:
2759
2769
  Enabled: true
2760
2770
  VersionAdded: '0.50'
2761
2771
  ForbiddenDelimiters:
2762
- - !ruby/regexp '/(^|\s)(EO[A-Z]{1}|END)(\s|$)/'
2772
+ - !ruby/regexp '/(^|\s)(EO[A-Z]{1}|END)(\s|$)/i'
2763
2773
 
2764
2774
  Naming/InclusiveLanguage:
2765
2775
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
@@ -2817,7 +2827,6 @@ Naming/MethodName:
2817
2827
  # - '\A\s*onSelectionCleared\s*'
2818
2828
  #
2819
2829
  AllowedPatterns: []
2820
- IgnoredPatterns: [] # deprecated
2821
2830
 
2822
2831
  Naming/MethodParameterName:
2823
2832
  Description: >-
@@ -3187,7 +3196,6 @@ Style/BlockDelimiters:
3187
3196
  - proc
3188
3197
  - it
3189
3198
  AllowedPatterns: []
3190
- IgnoredMethods: [] # deprecated
3191
3199
  # The AllowBracesOnProceduralOneLiners option is ignored unless the
3192
3200
  # EnforcedStyle is set to `semantic`. If so:
3193
3201
  #
@@ -3211,7 +3219,7 @@ Style/BlockDelimiters:
3211
3219
  # collection.each do |element| puts element end
3212
3220
  AllowBracesOnProceduralOneLiners: false
3213
3221
  # The BracesRequiredMethods overrides all other configurations except
3214
- # IgnoredMethods. It can be used to enforce that all blocks for specific
3222
+ # AllowedMethods. It can be used to enforce that all blocks for specific
3215
3223
  # methods use braces. For example, you can use this to enforce Sorbet
3216
3224
  # signatures use braces even when the rest of your codebase enforces
3217
3225
  # the `line_count_based` style.
@@ -3305,7 +3313,6 @@ Style/ClassEqualityComparison:
3305
3313
  - equal?
3306
3314
  - eql?
3307
3315
  AllowedPatterns: []
3308
- IgnoredMethods: [] # deprecated
3309
3316
 
3310
3317
  Style/ClassMethods:
3311
3318
  Description: 'Use self when defining module/class methods.'
@@ -3426,6 +3433,11 @@ Style/CommentedKeyword:
3426
3433
  VersionAdded: '0.51'
3427
3434
  VersionChanged: '1.19'
3428
3435
 
3436
+ Style/ComparableClamp:
3437
+ Description: 'Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum.'
3438
+ Enabled: pending
3439
+ VersionAdded: '1.44'
3440
+
3429
3441
  Style/ConcatArrayLiterals:
3430
3442
  Description: 'Enforces the use of `Array#push(item)` instead of `Array#concat([item])` to avoid redundant array literals.'
3431
3443
  Enabled: pending
@@ -3775,7 +3787,6 @@ Style/FormatStringToken:
3775
3787
  VersionChanged: '1.0'
3776
3788
  AllowedMethods: []
3777
3789
  AllowedPatterns: []
3778
- IgnoredMethods: [] # deprecated
3779
3790
 
3780
3791
  Style/FrozenStringLiteralComment:
3781
3792
  Description: >-
@@ -3853,7 +3864,8 @@ Style/HashEachMethods:
3853
3864
  Safe: false
3854
3865
  VersionAdded: '0.80'
3855
3866
  VersionChanged: '1.16'
3856
- AllowedReceivers: []
3867
+ AllowedReceivers:
3868
+ - Thread.current
3857
3869
 
3858
3870
  Style/HashExcept:
3859
3871
  Description: >-
@@ -4025,6 +4037,35 @@ Style/InverseMethods:
4025
4037
  :select: :reject
4026
4038
  :select!: :reject!
4027
4039
 
4040
+ Style/InvertibleUnlessCondition:
4041
+ Description: 'Favor `if` with inverted condition over `unless`.'
4042
+ Enabled: false
4043
+ VersionAdded: '1.44'
4044
+ # `InverseMethods` are methods that can be inverted in a `unless` condition.
4045
+ # The relationship of inverse methods needs to be defined in both directions.
4046
+ # Keys and values both need to be defined as symbols.
4047
+ InverseMethods:
4048
+ :!=: :==
4049
+ :>: :<=
4050
+ :<=: :>
4051
+ :<: :>=
4052
+ :>=: :<
4053
+ :!~: :=~
4054
+ :zero?: :nonzero?
4055
+ :nonzero?: :zero?
4056
+ :any?: :none?
4057
+ :none?: :any?
4058
+ :even?: :odd?
4059
+ :odd?: :even?
4060
+ # `ActiveSupport` defines some common inverse methods. They are listed below,
4061
+ # and not enabled by default.
4062
+ # :present?: :blank?
4063
+ # :blank?: :present?
4064
+ # :include?: :exclude?
4065
+ # :exclude?: :include?
4066
+ # :one?: :many?
4067
+ # :many?: :one?
4068
+
4028
4069
  Style/IpAddresses:
4029
4070
  Description: "Don't include literal IP addresses in code."
4030
4071
  Enabled: false
@@ -4124,9 +4165,7 @@ Style/MethodCallWithArgsParentheses:
4124
4165
  VersionChanged: '1.7'
4125
4166
  IgnoreMacros: true
4126
4167
  AllowedMethods: []
4127
- IgnoredMethods: [] # deprecated
4128
4168
  AllowedPatterns: []
4129
- IgnoredPatterns: [] # deprecated
4130
4169
  IncludedMacros: []
4131
4170
  AllowParenthesesInMultilineCall: false
4132
4171
  AllowParenthesesInChaining: false
@@ -4143,7 +4182,6 @@ Style/MethodCallWithoutArgsParentheses:
4143
4182
  Enabled: true
4144
4183
  AllowedMethods: []
4145
4184
  AllowedPatterns: []
4146
- IgnoredMethods: [] # deprecated
4147
4185
  VersionAdded: '0.47'
4148
4186
  VersionChanged: '0.55'
4149
4187
 
@@ -4522,7 +4560,6 @@ Style/NumericPredicate:
4522
4560
  - comparison
4523
4561
  AllowedMethods: []
4524
4562
  AllowedPatterns: []
4525
- IgnoredMethods: [] # deprecated
4526
4563
  # Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
4527
4564
  # false positives.
4528
4565
  Exclude:
@@ -4802,6 +4839,11 @@ Style/RedundantFreeze:
4802
4839
  VersionAdded: '0.34'
4803
4840
  VersionChanged: '0.66'
4804
4841
 
4842
+ Style/RedundantHeredocDelimiterQuotes:
4843
+ Description: 'Checks for redundant heredoc delimiter quotes.'
4844
+ Enabled: pending
4845
+ VersionAdded: '1.45'
4846
+
4805
4847
  Style/RedundantInitialize:
4806
4848
  Description: 'Checks for redundant `initialize` methods.'
4807
4849
  Enabled: pending
@@ -5199,7 +5241,6 @@ Style/SymbolProc:
5199
5241
  AllowedMethods:
5200
5242
  - define_method
5201
5243
  AllowedPatterns: []
5202
- IgnoredMethods: [] # deprecated
5203
5244
  AllowComments: false
5204
5245
 
5205
5246
  Style/TernaryParentheses:
@@ -5440,9 +5481,10 @@ Style/YodaCondition:
5440
5481
 
5441
5482
  Style/YodaExpression:
5442
5483
  Description: 'Forbid the use of yoda expressions.'
5443
- Enabled: pending
5484
+ Enabled: false
5444
5485
  Safe: false
5445
5486
  VersionAdded: '1.42'
5487
+ VersionChanged: '1.43'
5446
5488
  SupportedOperators:
5447
5489
  - '*'
5448
5490
  - '+'
data/lib/rubocop/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+
3
5
  module RuboCop
4
6
  # The CLI is a class responsible of handling all the command line interface
5
7
  # logic.
@@ -38,14 +40,16 @@ module RuboCop
38
40
  @options, paths = Options.new.parse(args)
39
41
  @env = Environment.new(@options, @config_store, paths)
40
42
 
41
- if @options[:init]
42
- run_command(:init)
43
- else
44
- act_on_options
45
- validate_options_vs_config
46
- parallel_by_default!
47
- apply_default_formatter
48
- execute_runners
43
+ profile_if_needed do
44
+ if @options[:init]
45
+ run_command(:init)
46
+ else
47
+ act_on_options
48
+ validate_options_vs_config
49
+ parallel_by_default!
50
+ apply_default_formatter
51
+ execute_runners
52
+ end
49
53
  end
50
54
  rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
51
55
  warn e.message
@@ -68,6 +72,48 @@ module RuboCop
68
72
 
69
73
  private
70
74
 
75
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
76
+ def profile_if_needed
77
+ return yield unless @options[:profile]
78
+
79
+ return STATUS_ERROR unless require_gem('stackprof')
80
+
81
+ with_memory = @options[:memory]
82
+ if with_memory
83
+ return STATUS_ERROR unless require_gem('memory_profiler')
84
+
85
+ MemoryProfiler.start
86
+ end
87
+
88
+ tmp_dir = File.join(ConfigFinder.project_root, 'tmp')
89
+ FileUtils.mkdir_p(tmp_dir)
90
+ status = nil
91
+
92
+ StackProf.run(out: File.join(tmp_dir, 'rubocop-stackprof.dump')) do
93
+ status = yield
94
+ end
95
+ puts 'Profile report generated'
96
+
97
+ if with_memory
98
+ puts 'Building memory report...'
99
+ report = MemoryProfiler.stop
100
+ report.pretty_print(
101
+ to_file: File.join(tmp_dir, 'rubocop-memory_profiler.txt'),
102
+ scale_bytes: true
103
+ )
104
+ end
105
+ status
106
+ end
107
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
108
+
109
+ def require_gem(name)
110
+ require name
111
+ true
112
+ rescue LoadError
113
+ warn("You don't have #{name} installed. Add it to your Gemfile and run `bundle install`")
114
+ false
115
+ end
116
+
71
117
  def run_command(name)
72
118
  @env.run(name)
73
119
  end
@@ -111,10 +111,17 @@ module RuboCop
111
111
  end
112
112
 
113
113
  merge_with_default(config, config_file).tap do |merged_config|
114
- warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(merged_config)
114
+ unless possible_new_cops?(merged_config)
115
+ pending_cops = pending_cops_only_qualified(merged_config.pending_cops)
116
+ warn_on_pending_cops(pending_cops) unless pending_cops.empty?
117
+ end
115
118
  end
116
119
  end
117
120
 
121
+ def pending_cops_only_qualified(pending_cops)
122
+ pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
123
+ end
124
+
118
125
  def possible_new_cops?(config)
119
126
  disable_pending_cops || enable_pending_cops ||
120
127
  config.disabled_new_cops? || config.enabled_new_cops?
@@ -167,8 +174,6 @@ module RuboCop
167
174
  BANNER
168
175
 
169
176
  def warn_on_pending_cops(pending_cops)
170
- return if pending_cops.empty?
171
-
172
177
  warn Rainbow(PENDING_BANNER).yellow
173
178
 
174
179
  pending_cops.each { |cop| warn_pending_cop cop }
@@ -241,18 +246,10 @@ module RuboCop
241
246
  raise
242
247
  end
243
248
 
244
- if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
245
- def yaml_safe_load!(yaml_code, filename)
246
- YAML.safe_load(yaml_code,
247
- permitted_classes: [Regexp, Symbol],
248
- permitted_symbols: [],
249
- aliases: true,
250
- filename: filename)
251
- end
252
- else # Ruby < 2.6
253
- def yaml_safe_load!(yaml_code, filename)
254
- YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
255
- end
249
+ def yaml_safe_load!(yaml_code, filename)
250
+ YAML.safe_load(
251
+ yaml_code, permitted_classes: [Regexp, Symbol], aliases: true, filename: filename
252
+ )
256
253
  end
257
254
  end
258
255
 
@@ -33,7 +33,7 @@ module RuboCop
33
33
  inherit_mode: determine_inherit_mode(hash, k))
34
34
  end
35
35
  hash[k] = v
36
- fix_include_paths(base_config.loaded_path, hash, path, k, v) if v.key?('Include')
36
+ fix_include_paths(base_config.loaded_path, hash, k, v) if v.key?('Include')
37
37
  end
38
38
  end
39
39
  end
@@ -42,13 +42,12 @@ module RuboCop
42
42
  # base configuration are relative to the directory where the base configuration file is. For the
43
43
  # derived configuration, we need to make those paths relative to where the derived configuration
44
44
  # file is.
45
- def fix_include_paths(base_config_path, hash, path, key, value)
45
+ def fix_include_paths(base_config_path, hash, key, value)
46
46
  return unless File.basename(base_config_path).start_with?('.rubocop')
47
47
 
48
48
  base_dir = File.dirname(base_config_path)
49
- derived_dir = File.dirname(path)
50
49
  hash[key]['Include'] = value['Include'].map do |include_path|
51
- PathUtil.relative_path(File.join(base_dir, include_path), derived_dir)
50
+ PathUtil.relative_path(File.join(base_dir, include_path), Dir.pwd)
52
51
  end
53
52
  end
54
53
 
@@ -180,6 +180,10 @@ module RuboCop
180
180
 
181
181
  status, corrector = enabled_line?(range.line) ? correct(range, &block) : :disabled
182
182
 
183
+ # Since this range may be generated from Ruby code embedded in some
184
+ # template file, we convert it to location info in the original file.
185
+ range = range_for_original(range)
186
+
183
187
  current_offenses << Offense.new(severity, range, message, name, status, corrector)
184
188
  end
185
189
 
@@ -286,6 +290,21 @@ module RuboCop
286
290
  end
287
291
  # rubocop:enable Layout/ClassStructure
288
292
 
293
+ # Called before any investigation
294
+ # @api private
295
+ def begin_investigation(processed_source, offset: 0, original: processed_source)
296
+ @current_offenses = nil
297
+ @current_offense_locations = nil
298
+ @currently_disabled_lines = nil
299
+ @processed_source = processed_source
300
+ @current_corrector = nil
301
+
302
+ # We need to keep track of the original source and offset,
303
+ # because `processed_source` here may be an embedded code in it.
304
+ @current_offset = offset
305
+ @current_original = original
306
+ end
307
+
289
308
  private
290
309
 
291
310
  ### Reserved for Cop::Cop
@@ -320,15 +339,6 @@ module RuboCop
320
339
  @restrict_on_send ||= self::RESTRICT_ON_SEND.to_a.freeze
321
340
  end
322
341
 
323
- # Called before any investigation
324
- def begin_investigation(processed_source)
325
- @current_offenses = nil
326
- @current_offense_locations = nil
327
- @currently_disabled_lines = nil
328
- @processed_source = processed_source
329
- @current_corrector = nil
330
- end
331
-
332
342
  EMPTY_OFFENSES = [].freeze
333
343
  private_constant :EMPTY_OFFENSES
334
344
  # Called to complete an investigation
@@ -459,6 +469,14 @@ module RuboCop
459
469
  warn(Rainbow(message).red)
460
470
  end
461
471
  end
472
+
473
+ def range_for_original(range)
474
+ ::Parser::Source::Range.new(
475
+ @current_original.buffer,
476
+ range.begin_pos + @current_offset,
477
+ range.end_pos + @current_offset
478
+ )
479
+ end
462
480
  end
463
481
  end
464
482
  end
@@ -76,10 +76,10 @@ module RuboCop
76
76
  end
77
77
 
78
78
  # @return [InvestigationReport]
79
- def investigate(processed_source)
79
+ def investigate(processed_source, offset: 0, original: processed_source)
80
80
  reset
81
81
 
82
- @cops.each { |cop| cop.send :begin_investigation, processed_source }
82
+ begin_investigation(processed_source, offset: offset, original: original)
83
83
  if processed_source.valid_syntax?
84
84
  invoke(:on_new_investigation, @cops)
85
85
  invoke_with_argument(:investigate, @forces, processed_source)
@@ -95,6 +95,12 @@ module RuboCop
95
95
 
96
96
  private
97
97
 
98
+ def begin_investigation(processed_source, offset:, original:)
99
+ @cops.each do |cop|
100
+ cop.begin_investigation(processed_source, offset: offset, original: original)
101
+ end
102
+ end
103
+
98
104
  def trigger_responding_cops(callback, node)
99
105
  @callbacks[callback]&.each do |cop|
100
106
  with_cop_error_handling(cop, node) do
@@ -53,6 +53,11 @@ module RuboCop
53
53
  def add_offense(node_or_range, location: :expression, message: nil, severity: nil, &block)
54
54
  @v0_argument = node_or_range
55
55
  range = find_location(node_or_range, location)
56
+
57
+ # Since this range may be generated from Ruby code embedded in some
58
+ # template file, we convert it to location info in the original file.
59
+ range = range_for_original(range)
60
+
56
61
  if block.nil? && !support_autocorrect?
57
62
  super(range, message: message, severity: severity)
58
63
  else
@@ -93,14 +98,21 @@ module RuboCop
93
98
  super
94
99
  end
95
100
 
96
- private
97
-
98
- def begin_investigation(processed_source)
101
+ # Called before any investigation
102
+ # @api private
103
+ def begin_investigation(processed_source, offset: 0, original: processed_source)
99
104
  super
100
105
  @offenses = current_offenses
101
106
  @last_corrector = @current_corrector
107
+
108
+ # We need to keep track of the original source and offset,
109
+ # because `processed_source` here may be an embedded code in it.
110
+ @current_offset = offset
111
+ @current_original = original
102
112
  end
103
113
 
114
+ private
115
+
104
116
  # Override Base
105
117
  def callback_argument(_range)
106
118
  @v0_argument
@@ -141,6 +153,14 @@ module RuboCop
141
153
  rescue ::Parser::ClobberingError
142
154
  # ignore Clobbering errors
143
155
  end
156
+
157
+ def range_for_original(range)
158
+ ::Parser::Source::Range.new(
159
+ @current_original.buffer,
160
+ range.begin_pos + @current_offset,
161
+ range.end_pos + @current_offset
162
+ )
163
+ end
144
164
  end
145
165
  end
146
166
  end
@@ -86,8 +86,16 @@ module RuboCop
86
86
  range1 = to_range(node_or_range1)
87
87
  range2 = to_range(node_or_range2)
88
88
 
89
- replace(range1, range2.source)
90
- replace(range2, range1.source)
89
+ if range1.end_pos == range2.begin_pos
90
+ insert_before(range1, range2.source)
91
+ remove(range2)
92
+ elsif range2.end_pos == range1.begin_pos
93
+ insert_before(range2, range1.source)
94
+ remove(range1)
95
+ else
96
+ replace(range1, range2.source)
97
+ replace(range2, range1.source)
98
+ end
91
99
  end
92
100
 
93
101
  private
@@ -18,7 +18,7 @@ module RuboCop
18
18
  current_range = declaration_with_comment(node)
19
19
  previous_range = declaration_with_comment(previous_declaration)
20
20
 
21
- ->(corrector) { swap_range(corrector, current_range, previous_range) }
21
+ ->(corrector) { corrector.swap(current_range, previous_range) }
22
22
  end
23
23
 
24
24
  private
@@ -32,11 +32,6 @@ module RuboCop
32
32
 
33
33
  range_between(begin_pos, end_pos)
34
34
  end
35
-
36
- def swap_range(corrector, range1, range2)
37
- corrector.insert_before(range2, range1.source)
38
- corrector.remove(range1)
39
- end
40
35
  end
41
36
  end
42
37
  end