rubocop 1.41.1 → 1.45.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -2
  4. data/config/default.yml +97 -31
  5. data/lib/rubocop/cli.rb +55 -9
  6. data/lib/rubocop/config.rb +7 -7
  7. data/lib/rubocop/config_loader.rb +12 -15
  8. data/lib/rubocop/config_loader_resolver.rb +8 -5
  9. data/lib/rubocop/cop/base.rb +89 -70
  10. data/lib/rubocop/cop/commissioner.rb +8 -2
  11. data/lib/rubocop/cop/cop.rb +51 -31
  12. data/lib/rubocop/cop/corrector.rb +30 -10
  13. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -6
  14. data/lib/rubocop/cop/gemspec/dependency_version.rb +16 -18
  15. data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
  16. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
  17. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  18. data/lib/rubocop/cop/layout/block_end_newline.rb +7 -1
  19. data/lib/rubocop/cop/layout/class_structure.rb +31 -23
  20. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
  21. data/lib/rubocop/cop/layout/comment_indentation.rb +3 -1
  22. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  23. data/lib/rubocop/cop/layout/heredoc_indentation.rb +6 -9
  24. data/lib/rubocop/cop/layout/indentation_style.rb +4 -1
  25. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +6 -6
  26. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  27. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  28. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  29. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
  30. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
  31. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
  32. data/lib/rubocop/cop/layout/trailing_whitespace.rb +5 -2
  33. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
  34. data/lib/rubocop/cop/lint/debugger.rb +8 -27
  35. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
  36. data/lib/rubocop/cop/lint/else_layout.rb +2 -6
  37. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
  38. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
  39. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  40. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
  41. data/lib/rubocop/cop/lint/nested_method_definition.rb +8 -5
  42. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +19 -0
  43. data/lib/rubocop/cop/lint/redundant_require_statement.rb +11 -1
  44. data/lib/rubocop/cop/lint/regexp_as_condition.rb +6 -0
  45. data/lib/rubocop/cop/lint/require_parentheses.rb +3 -1
  46. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -1
  47. data/lib/rubocop/cop/lint/useless_access_modifier.rb +7 -4
  48. data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -3
  49. data/lib/rubocop/cop/lint/useless_rescue.rb +85 -0
  50. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +14 -4
  51. data/lib/rubocop/cop/lint/void.rb +19 -10
  52. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  53. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  54. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  55. data/lib/rubocop/cop/metrics/parameter_lists.rb +27 -0
  56. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  57. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +3 -6
  58. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  59. data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
  60. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
  61. data/lib/rubocop/cop/mixin/comments_help.rb +5 -3
  62. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +57 -23
  63. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
  64. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
  65. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -0
  66. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  67. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  68. data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
  69. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  70. data/lib/rubocop/cop/registry.rb +34 -29
  71. data/lib/rubocop/cop/security/compound_hash.rb +2 -1
  72. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
  73. data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -0
  74. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  75. data/lib/rubocop/cop/style/block_delimiters.rb +8 -2
  76. data/lib/rubocop/cop/style/class_and_module_children.rb +3 -10
  77. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  78. data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
  79. data/lib/rubocop/cop/style/concat_array_literals.rb +22 -2
  80. data/lib/rubocop/cop/style/conditional_assignment.rb +0 -6
  81. data/lib/rubocop/cop/style/documentation.rb +1 -1
  82. data/lib/rubocop/cop/style/documentation_method.rb +6 -0
  83. data/lib/rubocop/cop/style/guard_clause.rb +11 -7
  84. data/lib/rubocop/cop/style/hash_each_methods.rb +13 -1
  85. data/lib/rubocop/cop/style/hash_syntax.rb +11 -7
  86. data/lib/rubocop/cop/style/identical_conditional_branches.rb +15 -0
  87. data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
  88. data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
  89. data/lib/rubocop/cop/style/map_to_set.rb +61 -0
  90. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +23 -14
  91. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
  92. data/lib/rubocop/cop/style/method_def_parentheses.rb +11 -4
  93. data/lib/rubocop/cop/style/min_max_comparison.rb +83 -0
  94. data/lib/rubocop/cop/style/missing_else.rb +13 -1
  95. data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
  96. data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
  97. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
  98. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -5
  99. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
  100. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
  101. data/lib/rubocop/cop/style/operator_method_call.rb +16 -2
  102. data/lib/rubocop/cop/style/parallel_assignment.rb +3 -1
  103. data/lib/rubocop/cop/style/redundant_condition.rb +16 -1
  104. data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
  105. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
  106. data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
  107. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +2 -1
  108. data/lib/rubocop/cop/style/redundant_string_escape.rb +4 -2
  109. data/lib/rubocop/cop/style/require_order.rb +6 -11
  110. data/lib/rubocop/cop/style/select_by_regexp.rb +6 -2
  111. data/lib/rubocop/cop/style/self_assignment.rb +2 -2
  112. data/lib/rubocop/cop/style/semicolon.rb +24 -2
  113. data/lib/rubocop/cop/style/signal_exception.rb +8 -6
  114. data/lib/rubocop/cop/style/string_hash_keys.rb +4 -1
  115. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  116. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -4
  117. data/lib/rubocop/cop/style/word_array.rb +42 -1
  118. data/lib/rubocop/cop/style/yoda_condition.rb +12 -5
  119. data/lib/rubocop/cop/style/yoda_expression.rb +90 -0
  120. data/lib/rubocop/cop/style/zero_length_predicate.rb +31 -14
  121. data/lib/rubocop/cop/team.rb +48 -43
  122. data/lib/rubocop/cop/variable_force/scope.rb +3 -3
  123. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
  124. data/lib/rubocop/cop/variable_force.rb +1 -4
  125. data/lib/rubocop/formatter.rb +0 -1
  126. data/lib/rubocop/options.rb +22 -1
  127. data/lib/rubocop/path_util.rb +17 -7
  128. data/lib/rubocop/result_cache.rb +1 -1
  129. data/lib/rubocop/rspec/expect_offense.rb +6 -4
  130. data/lib/rubocop/runner.rb +50 -7
  131. data/lib/rubocop/server/cache.rb +10 -3
  132. data/lib/rubocop/server/cli.rb +37 -18
  133. data/lib/rubocop/server/client_command/exec.rb +1 -1
  134. data/lib/rubocop/server/client_command/start.rb +6 -1
  135. data/lib/rubocop/server/core.rb +23 -8
  136. data/lib/rubocop/target_ruby.rb +0 -1
  137. data/lib/rubocop/version.rb +1 -1
  138. data/lib/rubocop.rb +8 -0
  139. metadata +21 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56e97cb2571864e1514ba2e8837cabf2135356847edac7dacc239f77a30b6463
4
- data.tar.gz: 94a8c7c1c876e0491ceb26e18cfa633d5204ba9f2a7a86c177c803ecbbbbbd30
3
+ metadata.gz: 648a8aa3156aebf0c078bc0b600f301d3aa0abaf92d6b3643c343718575f7302
4
+ data.tar.gz: 21b185886d70b70a163c6e7f3ea47e04ee0a0afcf11217e0d7bcb31e25440880
5
5
  SHA512:
6
- metadata.gz: 782246da9932f0785322b49085efc7db06fb0a4043d1ca684957c8cf34e70dbc395fc0e09e654be3336f6060f48171ac79bcc81bc44b5b31f58b9e433ab02876
7
- data.tar.gz: '093fe7537462df3ed1114995a785ea5390428c3e2a1aab982c8a70b19e50bb073c6ee051a4f2b168755b532cb276dc16e6d1965ec4590efbbb916c4932de8bda'
6
+ metadata.gz: ff5a5e947001ba9507f3e806896559baaf0e4bccc6b2cc56316dffc3ae334f62046040be389518139d2979c4d09900600f9b233bc1f4dbd2d1d37a2f8fe99037
7
+ data.tar.gz: 8f89f55198c9d206c5b8d0c32cbeb5033491046c0ea0f4311f6c1a23595bcce852ec732606ca1fd2bc499b31ecb2265dcf6d85edd352f6400d01bd9385993a44
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-22 Bozhidar Batsov
1
+ Copyright (c) 2012-23 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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.41', 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.
@@ -246,5 +246,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
246
246
 
247
247
  ## Copyright
248
248
 
249
- Copyright (c) 2012-2022 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
249
+ Copyright (c) 2012-2023 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
250
250
  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: >-
@@ -3901,7 +3913,7 @@ Style/HashSyntax:
3901
3913
  - never
3902
3914
  # accepts both shorthand and explicit use of hash literal value.
3903
3915
  - either
3904
- # like "either", but will avoid mixing styles in a single hash
3916
+ # forces use of the 3.1 syntax only if all values can be omitted in the hash.
3905
3917
  - consistent
3906
3918
  # Force hashes that have a symbol value to use hash rockets
3907
3919
  UseHashRocketsWithSymbolValues: false
@@ -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
@@ -4110,6 +4151,12 @@ Style/MapToHash:
4110
4151
  VersionAdded: '1.24'
4111
4152
  Safe: false
4112
4153
 
4154
+ Style/MapToSet:
4155
+ Description: 'Prefer `to_set` with a block over `map.to_set`.'
4156
+ Enabled: pending
4157
+ Safe: false
4158
+ VersionAdded: '1.42'
4159
+
4113
4160
  Style/MethodCallWithArgsParentheses:
4114
4161
  Description: 'Use parentheses for method calls with arguments.'
4115
4162
  StyleGuide: '#method-invocation-parens'
@@ -4118,9 +4165,7 @@ Style/MethodCallWithArgsParentheses:
4118
4165
  VersionChanged: '1.7'
4119
4166
  IgnoreMacros: true
4120
4167
  AllowedMethods: []
4121
- IgnoredMethods: [] # deprecated
4122
4168
  AllowedPatterns: []
4123
- IgnoredPatterns: [] # deprecated
4124
4169
  IncludedMacros: []
4125
4170
  AllowParenthesesInMultilineCall: false
4126
4171
  AllowParenthesesInChaining: false
@@ -4137,7 +4182,6 @@ Style/MethodCallWithoutArgsParentheses:
4137
4182
  Enabled: true
4138
4183
  AllowedMethods: []
4139
4184
  AllowedPatterns: []
4140
- IgnoredMethods: [] # deprecated
4141
4185
  VersionAdded: '0.47'
4142
4186
  VersionChanged: '0.55'
4143
4187
 
@@ -4168,6 +4212,12 @@ Style/MinMax:
4168
4212
  Enabled: true
4169
4213
  VersionAdded: '0.50'
4170
4214
 
4215
+ Style/MinMaxComparison:
4216
+ Description: 'Enforces the use of `max` or `min` instead of comparison for greater or less.'
4217
+ Enabled: pending
4218
+ Safe: false
4219
+ VersionAdded: '1.42'
4220
+
4171
4221
  Style/MissingElse:
4172
4222
  Description: >-
4173
4223
  Require if/case expressions to have an else branches.
@@ -4510,7 +4560,6 @@ Style/NumericPredicate:
4510
4560
  - comparison
4511
4561
  AllowedMethods: []
4512
4562
  AllowedPatterns: []
4513
- IgnoredMethods: [] # deprecated
4514
4563
  # Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
4515
4564
  # false positives.
4516
4565
  Exclude:
@@ -4790,6 +4839,11 @@ Style/RedundantFreeze:
4790
4839
  VersionAdded: '0.34'
4791
4840
  VersionChanged: '0.66'
4792
4841
 
4842
+ Style/RedundantHeredocDelimiterQuotes:
4843
+ Description: 'Checks for redundant heredoc delimiter quotes.'
4844
+ Enabled: pending
4845
+ VersionAdded: '1.45'
4846
+
4793
4847
  Style/RedundantInitialize:
4794
4848
  Description: 'Checks for redundant `initialize` methods.'
4795
4849
  Enabled: pending
@@ -5187,7 +5241,6 @@ Style/SymbolProc:
5187
5241
  AllowedMethods:
5188
5242
  - define_method
5189
5243
  AllowedPatterns: []
5190
- IgnoredMethods: [] # deprecated
5191
5244
  AllowComments: false
5192
5245
 
5193
5246
  Style/TernaryParentheses:
@@ -5426,6 +5479,19 @@ Style/YodaCondition:
5426
5479
  VersionAdded: '0.49'
5427
5480
  VersionChanged: '0.75'
5428
5481
 
5482
+ Style/YodaExpression:
5483
+ Description: 'Forbid the use of yoda expressions.'
5484
+ Enabled: false
5485
+ Safe: false
5486
+ VersionAdded: '1.42'
5487
+ VersionChanged: '1.43'
5488
+ SupportedOperators:
5489
+ - '*'
5490
+ - '+'
5491
+ - '&'
5492
+ - '|'
5493
+ - '^'
5494
+
5429
5495
  Style/ZeroLengthPredicate:
5430
5496
  Description: 'Use #empty? when testing for objects of length 0.'
5431
5497
  Enabled: true
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.
@@ -7,7 +9,7 @@ module RuboCop
7
9
  STATUS_SUCCESS = 0
8
10
  STATUS_OFFENSES = 1
9
11
  STATUS_ERROR = 2
10
- STATUS_INTERRUPTED = 128 + Signal.list['INT']
12
+ STATUS_INTERRUPTED = Signal.list['INT'] + 128
11
13
  DEFAULT_PARALLEL_OPTIONS = %i[
12
14
  color debug display_style_guide display_time display_only_fail_level_offenses
13
15
  display_only_failed except extra_details fail_level fix_layout format
@@ -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
@@ -21,6 +21,13 @@ module RuboCop
21
21
  DEFAULT_RAILS_VERSION = 5.0
22
22
  attr_reader :loaded_path
23
23
 
24
+ def self.create(hash, path, check: true)
25
+ config = new(hash, path)
26
+ config.check if check
27
+
28
+ config
29
+ end
30
+
24
31
  # rubocop:disable Metrics/AbcSize
25
32
  def initialize(hash = {}, loaded_path = nil)
26
33
  @loaded_path = loaded_path
@@ -39,13 +46,6 @@ module RuboCop
39
46
  end
40
47
  # rubocop:enable Metrics/AbcSize
41
48
 
42
- def self.create(hash, path, check: true)
43
- config = new(hash, path)
44
- config.check if check
45
-
46
- config
47
- end
48
-
49
49
  def loaded_features
50
50
  @loaded_features ||= ConfigLoader.loaded_features
51
51
  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
 
@@ -206,7 +205,11 @@ module RuboCop
206
205
  end
207
206
 
208
207
  def base_configs(path, inherit_from, file)
209
- configs = Array(inherit_from).compact.map do |f|
208
+ inherit_froms = Array(inherit_from).compact.flat_map do |f|
209
+ PathUtil.glob?(f) ? Dir.glob(f) : f
210
+ end
211
+
212
+ configs = inherit_froms.map do |f|
210
213
  ConfigLoader.load_file(inherited_file(path, f, file))
211
214
  end
212
215