rubocop 1.48.1 → 1.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/config/default.yml +59 -12
  4. data/lib/rubocop/cli/command/execute_runner.rb +7 -2
  5. data/lib/rubocop/cli.rb +6 -6
  6. data/lib/rubocop/config.rb +5 -1
  7. data/lib/rubocop/config_loader.rb +8 -8
  8. data/lib/rubocop/config_obsoletion.rb +2 -2
  9. data/lib/rubocop/cop/autocorrect_logic.rb +28 -12
  10. data/lib/rubocop/cop/base.rb +5 -1
  11. data/lib/rubocop/cop/cop.rb +2 -2
  12. data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -1
  13. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  14. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  15. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
  16. data/lib/rubocop/cop/gemspec/development_dependencies.rb +1 -1
  17. data/lib/rubocop/cop/internal_affairs/cop_description.rb +33 -9
  18. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +2 -2
  19. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
  20. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +2 -2
  21. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +29 -2
  22. data/lib/rubocop/cop/layout/class_structure.rb +1 -0
  23. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +0 -1
  24. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  25. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  26. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
  27. data/lib/rubocop/cop/layout/end_alignment.rb +5 -1
  28. data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
  29. data/lib/rubocop/cop/layout/first_argument_indentation.rb +6 -1
  30. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
  31. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
  32. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
  33. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
  34. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +4 -4
  35. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  36. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
  37. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
  38. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
  39. data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
  40. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
  41. data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
  42. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -0
  43. data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
  44. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +13 -1
  45. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +3 -3
  46. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
  47. data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
  48. data/lib/rubocop/cop/lint/erb_new_arguments.rb +3 -4
  49. data/lib/rubocop/cop/lint/identity_comparison.rb +0 -1
  50. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +5 -3
  51. data/lib/rubocop/cop/lint/inherit_exception.rb +9 -0
  52. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +1 -1
  53. data/lib/rubocop/cop/lint/missing_super.rb +3 -0
  54. data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
  55. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +2 -2
  56. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +0 -1
  57. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +2 -2
  58. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +1 -1
  59. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
  60. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +1 -2
  61. data/lib/rubocop/cop/lint/shadowed_exception.rb +5 -11
  62. data/lib/rubocop/cop/lint/to_enum_arguments.rb +7 -1
  63. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +23 -9
  64. data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
  65. data/lib/rubocop/cop/lint/useless_assignment.rb +59 -1
  66. data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
  67. data/lib/rubocop/cop/lint/void.rb +69 -9
  68. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  69. data/lib/rubocop/cop/metrics/class_length.rb +1 -0
  70. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -2
  71. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  72. data/lib/rubocop/cop/mixin/allowed_receivers.rb +34 -0
  73. data/lib/rubocop/cop/mixin/comments_help.rb +7 -3
  74. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
  75. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  76. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
  77. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  78. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  79. data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
  80. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +22 -7
  81. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +11 -3
  82. data/lib/rubocop/cop/naming/variable_name.rb +6 -1
  83. data/lib/rubocop/cop/style/accessor_grouping.rb +5 -1
  84. data/lib/rubocop/cop/style/attr.rb +11 -1
  85. data/lib/rubocop/cop/style/begin_block.rb +1 -2
  86. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  87. data/lib/rubocop/cop/style/class_equality_comparison.rb +51 -40
  88. data/lib/rubocop/cop/style/collection_compact.rb +19 -6
  89. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  90. data/lib/rubocop/cop/style/combinable_loops.rb +26 -6
  91. data/lib/rubocop/cop/style/conditional_assignment.rb +2 -2
  92. data/lib/rubocop/cop/style/copyright.rb +6 -3
  93. data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
  94. data/lib/rubocop/cop/style/dir.rb +1 -1
  95. data/lib/rubocop/cop/style/dir_empty.rb +8 -14
  96. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
  97. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
  98. data/lib/rubocop/cop/style/documentation.rb +1 -1
  99. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  100. data/lib/rubocop/cop/style/eval_with_location.rb +5 -5
  101. data/lib/rubocop/cop/style/exact_regexp_match.rb +68 -0
  102. data/lib/rubocop/cop/style/file_empty.rb +3 -3
  103. data/lib/rubocop/cop/style/file_read.rb +2 -2
  104. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  105. data/lib/rubocop/cop/style/guard_clause.rb +2 -0
  106. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -22
  107. data/lib/rubocop/cop/style/hash_except.rb +23 -12
  108. data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
  109. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  110. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  111. data/lib/rubocop/cop/style/if_inside_else.rb +6 -0
  112. data/lib/rubocop/cop/style/if_unless_modifier.rb +41 -12
  113. data/lib/rubocop/cop/style/invertible_unless_condition.rb +9 -5
  114. data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
  115. data/lib/rubocop/cop/style/map_to_set.rb +4 -1
  116. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +4 -9
  117. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +43 -36
  118. data/lib/rubocop/cop/style/multiline_method_signature.rb +6 -3
  119. data/lib/rubocop/cop/style/multiple_comparison.rb +14 -0
  120. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  121. data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
  122. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
  123. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  124. data/lib/rubocop/cop/style/redundant_array_constructor.rb +77 -0
  125. data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
  126. data/lib/rubocop/cop/style/redundant_filter_chain.rb +101 -0
  127. data/lib/rubocop/cop/style/redundant_line_continuation.rb +183 -0
  128. data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
  129. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  130. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
  131. data/lib/rubocop/cop/style/redundant_regexp_constructor.rb +46 -0
  132. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  133. data/lib/rubocop/cop/style/redundant_string_escape.rb +2 -3
  134. data/lib/rubocop/cop/style/regexp_literal.rb +11 -2
  135. data/lib/rubocop/cop/style/require_order.rb +11 -5
  136. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -3
  137. data/lib/rubocop/cop/style/select_by_regexp.rb +15 -5
  138. data/lib/rubocop/cop/style/semicolon.rb +12 -1
  139. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  140. data/lib/rubocop/cop/style/sole_nested_conditional.rb +5 -3
  141. data/lib/rubocop/cop/style/special_global_vars.rb +3 -4
  142. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  143. data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
  144. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  145. data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
  146. data/lib/rubocop/cop/team.rb +1 -1
  147. data/lib/rubocop/cop/variable_force/assignment.rb +33 -1
  148. data/lib/rubocop/cop/variable_force/variable_table.rb +2 -2
  149. data/lib/rubocop/cop/variable_force.rb +1 -0
  150. data/lib/rubocop/cops_documentation_generator.rb +10 -3
  151. data/lib/rubocop/ext/regexp_node.rb +1 -1
  152. data/lib/rubocop/ext/regexp_parser.rb +1 -1
  153. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  154. data/lib/rubocop/options.rb +4 -1
  155. data/lib/rubocop/result_cache.rb +2 -2
  156. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  157. data/lib/rubocop/server/cache.rb +1 -1
  158. data/lib/rubocop/server/client_command/exec.rb +2 -1
  159. data/lib/rubocop/server/helper.rb +1 -1
  160. data/lib/rubocop/server/server_command/exec.rb +1 -1
  161. data/lib/rubocop/target_ruby.rb +3 -2
  162. data/lib/rubocop/version.rb +10 -6
  163. data/lib/rubocop.rb +8 -0
  164. metadata +20 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39e28428d694fdd8cf940d5e3494f62a0266b3ffd41e823cf50131d16b45cf2a
4
- data.tar.gz: 75eadde7a899742fcb5f08c4b3cd845658dd64087dd80c0dad1bda5fef30804a
3
+ metadata.gz: 84bada99408af7ceb29d5c6bb4e188f61b27a78cb52639bcbbb144a289ebbc92
4
+ data.tar.gz: 930174d41acdfd3e0f7da8ef80c496ce7e5b68e5b00312d692a2cd93605fa70a
5
5
  SHA512:
6
- metadata.gz: 21bba5ce4024ff5c66695c56e4261fbefdedc8b293396b8d0687f836d4a56d0f53ae307435cb714a3e4b059def785a1d9862504910f94fe1815223b6036b727b
7
- data.tar.gz: aec136f1e174b57ba2ae6307a3fdeda0257614bcaaf77a6d5c5eca9733cfd185970dd998ecc95a6691d9aa8310419cd69679ba9b021f5b8284b9d12ef675dcc0
6
+ metadata.gz: 9c1f475617dc4826cef3c543ed35e65117bd93ff6f80605adc2096a06ddb38f9171a95800685a92103924600158ac306c27c9168cea787d5f11dc0616bd1a9ba
7
+ data.tar.gz: 9aaba3f7148469ce255ee22950f7c11542ca1e8480388493ab90c728831e47eef306372c42769a535beaba95d2d715c4b59161852689468cbd3fcd2c2236a535
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.48', require: false
56
+ gem 'rubocop', '~> 1.52', require: false
57
57
  ```
58
58
 
59
59
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -75,8 +75,8 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
75
75
 
76
76
  RuboCop officially supports the following runtime Ruby implementations:
77
77
 
78
- * MRI 2.6+
79
- * JRuby 9.3+
78
+ * MRI 2.7+
79
+ * JRuby 9.4+
80
80
 
81
81
  Targets Ruby 2.0+ code analysis.
82
82
 
data/config/default.yml CHANGED
@@ -140,7 +140,7 @@ AllCops:
140
140
  # or gems.locked file. (Although the Ruby version is specified in the Gemfile
141
141
  # or gems.rb file, RuboCop reads the final value from the lock file.) If the
142
142
  # Ruby version is still unresolved, RuboCop will use the oldest officially
143
- # supported Ruby version (currently Ruby 2.6).
143
+ # supported Ruby version (currently Ruby 2.7).
144
144
  TargetRubyVersion: ~
145
145
  # Determines if a notification for extension libraries should be shown when
146
146
  # rubocop is run. Keys are the name of the extension, and values are an array
@@ -154,6 +154,7 @@ AllCops:
154
154
  rubocop-rake: [rake]
155
155
  rubocop-graphql: [graphql]
156
156
  rubocop-capybara: [capybara]
157
+ rubocop-factory_bot: [factory_bot, factory_bot_rails]
157
158
  # Enable/Disable checking the methods extended by Active Support.
158
159
  ActiveSupportExtensionsEnabled: false
159
160
 
@@ -1016,8 +1017,6 @@ Layout/LineContinuationLeadingSpace:
1016
1017
  Layout/LineContinuationSpacing:
1017
1018
  Description: 'Checks the spacing in front of backslash in line continuations.'
1018
1019
  Enabled: pending
1019
- AutoCorrect: true
1020
- SafeAutoCorrect: true
1021
1020
  VersionAdded: '1.31'
1022
1021
  EnforcedStyle: space
1023
1022
  SupportedStyles:
@@ -1752,6 +1751,11 @@ Lint/DuplicateMagicComment:
1752
1751
  Enabled: pending
1753
1752
  VersionAdded: '1.37'
1754
1753
 
1754
+ Lint/DuplicateMatchPattern:
1755
+ Description: 'Do not repeat patterns in `in` keywords.'
1756
+ Enabled: pending
1757
+ VersionAdded: '1.50'
1758
+
1755
1759
  Lint/DuplicateMethods:
1756
1760
  Description: 'Check for duplicate method definitions.'
1757
1761
  Enabled: true
@@ -2340,6 +2344,9 @@ Lint/TopLevelReturnWithArgument:
2340
2344
  Description: 'Detects top level return statements with argument.'
2341
2345
  Enabled: true
2342
2346
  VersionAdded: '0.89'
2347
+ # These codes are `eval`-ed in method and their return values may be used.
2348
+ Exclude:
2349
+ - '**/*.jb'
2343
2350
 
2344
2351
  Lint/TrailingCommaInAttributeDeclaration:
2345
2352
  Description: 'Checks for trailing commas in attribute declarations.'
@@ -2448,6 +2455,8 @@ Lint/UselessAssignment:
2448
2455
  StyleGuide: '#underscore-unused-vars'
2449
2456
  Enabled: true
2450
2457
  VersionAdded: '0.11'
2458
+ VersionChanged: '1.51'
2459
+ SafeAutoCorrect: false
2451
2460
 
2452
2461
  Lint/UselessElseWithoutRescue:
2453
2462
  Description: 'Checks for useless `else` in `begin..end` without `rescue`.'
@@ -2475,10 +2484,9 @@ Lint/UselessRuby2Keywords:
2475
2484
  Lint/UselessSetterCall:
2476
2485
  Description: 'Checks for useless setter call to a local variable.'
2477
2486
  Enabled: true
2478
- SafeAutoCorrect: false
2487
+ Safe: false
2479
2488
  VersionAdded: '0.13'
2480
2489
  VersionChanged: '1.2'
2481
- Safe: false
2482
2490
 
2483
2491
  Lint/UselessTimes:
2484
2492
  Description: 'Checks for useless `Integer#times` calls.'
@@ -2779,7 +2787,7 @@ Naming/InclusiveLanguage:
2779
2787
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
2780
2788
  Enabled: false
2781
2789
  VersionAdded: '1.18'
2782
- VersionChanged: '1.21'
2790
+ VersionChanged: '1.49'
2783
2791
  CheckIdentifiers: true
2784
2792
  CheckConstants: true
2785
2793
  CheckVariables: true
@@ -2939,7 +2947,9 @@ Naming/VariableNumber:
2939
2947
  Security/CompoundHash:
2940
2948
  Description: 'When overwriting Object#hash to combine values, prefer delegating to Array#hash over writing a custom implementation.'
2941
2949
  Enabled: pending
2950
+ Safe: false
2942
2951
  VersionAdded: '1.28'
2952
+ VersionChanged: '1.51'
2943
2953
 
2944
2954
  Security/Eval:
2945
2955
  Description: 'The use of eval represents a serious security risk.'
@@ -3277,7 +3287,7 @@ Style/ClassAndModuleChildren:
3277
3287
  StyleGuide: '#namespace-definition'
3278
3288
  # Moving from compact to nested children requires knowledge of whether the
3279
3289
  # outer parent is a module or a class. Moving from nested to compact requires
3280
- # verification that the outer parent is defined elsewhere. Rubocop does not
3290
+ # verification that the outer parent is defined elsewhere. RuboCop does not
3281
3291
  # have the knowledge to perform either operation safely and thus requires
3282
3292
  # manual oversight.
3283
3293
  SafeAutoCorrect: false
@@ -3352,6 +3362,7 @@ Style/CollectionCompact:
3352
3362
  Safe: false
3353
3363
  VersionAdded: '1.2'
3354
3364
  VersionChanged: '1.3'
3365
+ AllowedReceivers: []
3355
3366
 
3356
3367
  # Align with the style guide.
3357
3368
  Style/CollectionMethods:
@@ -3508,6 +3519,14 @@ Style/Copyright:
3508
3519
  Notice: '^Copyright (\(c\) )?2[0-9]{3} .+'
3509
3520
  AutocorrectNotice: ''
3510
3521
 
3522
+ Style/DataInheritance:
3523
+ Description: 'Checks for inheritance from Data.define.'
3524
+ StyleGuide: '#no-extend-data-define'
3525
+ Enabled: pending
3526
+ SafeAutoCorrect: false
3527
+ VersionAdded: '1.49'
3528
+ VersionChanged: '1.51'
3529
+
3511
3530
  Style/DateTime:
3512
3531
  Description: 'Use Time over DateTime.'
3513
3532
  StyleGuide: '#date-time'
@@ -3697,6 +3716,11 @@ Style/EvenOdd:
3697
3716
  VersionAdded: '0.12'
3698
3717
  VersionChanged: '0.29'
3699
3718
 
3719
+ Style/ExactRegexpMatch:
3720
+ Description: 'Checks for exact regexp match inside Regexp literals.'
3721
+ Enabled: pending
3722
+ VersionAdded: '1.51'
3723
+
3700
3724
  Style/ExpandPathArguments:
3701
3725
  Description: "Use `expand_path(__dir__)` instead of `expand_path('..', __FILE__)`."
3702
3726
  Enabled: true
@@ -3737,7 +3761,6 @@ Style/FileEmpty:
3737
3761
  Prefer to use `File.empty?('path/to/file')` when checking if a file is empty.
3738
3762
  Enabled: pending
3739
3763
  Safe: false
3740
- SafeAutoCorrect: false
3741
3764
  VersionAdded: '1.48'
3742
3765
 
3743
3766
  Style/FileRead:
@@ -4059,7 +4082,9 @@ Style/InverseMethods:
4059
4082
  Style/InvertibleUnlessCondition:
4060
4083
  Description: 'Favor `if` with inverted condition over `unless`.'
4061
4084
  Enabled: false
4085
+ Safe: false
4062
4086
  VersionAdded: '1.44'
4087
+ VersionChanged: '1.50'
4063
4088
  # `InverseMethods` are methods that can be inverted in a `unless` condition.
4064
4089
  # The relationship of inverse methods needs to be defined in both directions.
4065
4090
  # Keys and values both need to be defined as symbols.
@@ -4082,8 +4107,6 @@ Style/InvertibleUnlessCondition:
4082
4107
  # :blank?: :present?
4083
4108
  # :include?: :exclude?
4084
4109
  # :exclude?: :include?
4085
- # :one?: :many?
4086
- # :many?: :one?
4087
4110
 
4088
4111
  Style/IpAddresses:
4089
4112
  Description: "Don't include literal IP addresses in code."
@@ -4360,6 +4383,7 @@ Style/MultipleComparison:
4360
4383
  VersionAdded: '0.49'
4361
4384
  VersionChanged: '1.1'
4362
4385
  AllowMethodComparison: true
4386
+ ComparisonsThreshold: 2
4363
4387
 
4364
4388
  Style/MutableConstant:
4365
4389
  Description: 'Do not assign mutable objects to constants.'
@@ -4565,11 +4589,10 @@ Style/NumericPredicate:
4565
4589
  Checks for the use of predicate- or comparison methods for
4566
4590
  numeric comparisons.
4567
4591
  StyleGuide: '#predicate-methods'
4568
- Safe: false
4569
4592
  # This will change to a new method call which isn't guaranteed to be on the
4570
4593
  # object. Switching these methods has to be done with knowledge of the types
4571
4594
  # of the variables which rubocop doesn't have.
4572
- SafeAutoCorrect: false
4595
+ Safe: false
4573
4596
  Enabled: true
4574
4597
  VersionAdded: '0.42'
4575
4598
  VersionChanged: '0.59'
@@ -4615,7 +4638,9 @@ Style/OpenStructUse:
4615
4638
  - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
4616
4639
 
4617
4640
  Enabled: pending
4641
+ Safe: false
4618
4642
  VersionAdded: '1.23'
4643
+ VersionChanged: '1.51'
4619
4644
 
4620
4645
  Style/OperatorMethodCall:
4621
4646
  Description: 'Checks for redundant dot before operator method call.'
@@ -4781,6 +4806,11 @@ Style/RedundantArgument:
4781
4806
  # String#chomp!
4782
4807
  chomp!: "\n"
4783
4808
 
4809
+ Style/RedundantArrayConstructor:
4810
+ Description: 'Checks for the instantiation of array using redundant `Array` constructor.'
4811
+ Enabled: pending
4812
+ VersionAdded: '1.52'
4813
+
4784
4814
  Style/RedundantAssignment:
4785
4815
  Description: 'Checks for redundant assignment before returning.'
4786
4816
  Enabled: true
@@ -4852,6 +4882,13 @@ Style/RedundantFileExtensionInRequire:
4852
4882
  Enabled: true
4853
4883
  VersionAdded: '0.88'
4854
4884
 
4885
+ Style/RedundantFilterChain:
4886
+ Description: >-
4887
+ Identifies usages of `any?`, `empty?`, `none?` or `one?` predicate methods chained to
4888
+ `select`/`filter`/`find_all` and change them to use predicate method instead.
4889
+ Enabled: pending
4890
+ VersionAdded: '1.52'
4891
+
4855
4892
  Style/RedundantFreeze:
4856
4893
  Description: "Checks usages of Object#freeze on immutable objects."
4857
4894
  Enabled: true
@@ -4878,6 +4915,11 @@ Style/RedundantInterpolation:
4878
4915
  VersionAdded: '0.76'
4879
4916
  VersionChanged: '1.30'
4880
4917
 
4918
+ Style/RedundantLineContinuation:
4919
+ Description: 'Check for redundant line continuation.'
4920
+ Enabled: pending
4921
+ VersionAdded: '1.49'
4922
+
4881
4923
  Style/RedundantParentheses:
4882
4924
  Description: "Checks for parentheses that seem not to serve any purpose."
4883
4925
  Enabled: true
@@ -4894,6 +4936,11 @@ Style/RedundantRegexpCharacterClass:
4894
4936
  Enabled: true
4895
4937
  VersionAdded: '0.85'
4896
4938
 
4939
+ Style/RedundantRegexpConstructor:
4940
+ Description: 'Checks for the instantiation of regexp using redundant `Regexp.new` or `Regexp.compile`.'
4941
+ Enabled: pending
4942
+ VersionAdded: '1.52'
4943
+
4897
4944
  Style/RedundantRegexpEscape:
4898
4945
  Description: 'Checks for redundant escapes in Regexps.'
4899
4946
  Enabled: true
@@ -76,13 +76,18 @@ module RuboCop
76
76
  warn <<~WARNING
77
77
  Errors are usually caused by RuboCop bugs.
78
78
  Please, report your problems to RuboCop's issue tracker.
79
- #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
80
-
79
+ #{bug_tracker_uri}
81
80
  Mention the following information in the issue report:
82
81
  #{RuboCop::Version.version(debug: true)}
83
82
  WARNING
84
83
  end
85
84
 
85
+ def bug_tracker_uri
86
+ return unless Gem.loaded_specs.key?('rubocop')
87
+
88
+ "#{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}\n"
89
+ end
90
+
86
91
  def maybe_print_corrected_source
87
92
  # Integration tools (like RubyMine) expect to have only the JSON result
88
93
  # when specifying JSON format. Similar HTML and JUnit are targeted as well.
data/lib/rubocop/cli.rb CHANGED
@@ -87,20 +87,20 @@ module RuboCop
87
87
 
88
88
  tmp_dir = File.join(ConfigFinder.project_root, 'tmp')
89
89
  FileUtils.mkdir_p(tmp_dir)
90
+ cpu_profile_file = File.join(tmp_dir, 'rubocop-stackprof.dump')
90
91
  status = nil
91
92
 
92
- StackProf.run(out: File.join(tmp_dir, 'rubocop-stackprof.dump')) do
93
+ StackProf.run(out: cpu_profile_file) do
93
94
  status = yield
94
95
  end
95
- puts 'Profile report generated'
96
+ puts "Profile report generated at #{cpu_profile_file}"
96
97
 
97
98
  if with_memory
98
99
  puts 'Building memory report...'
99
100
  report = MemoryProfiler.stop
100
- report.pretty_print(
101
- to_file: File.join(tmp_dir, 'rubocop-memory_profiler.txt'),
102
- scale_bytes: true
103
- )
101
+ memory_profile_file = File.join(tmp_dir, 'rubocop-memory_profiler.txt')
102
+ report.pretty_print(to_file: memory_profile_file, scale_bytes: true)
103
+ puts "Memory report generated at #{memory_profile_file}"
104
104
  end
105
105
  status
106
106
  end
@@ -29,7 +29,7 @@ module RuboCop
29
29
  end
30
30
 
31
31
  # rubocop:disable Metrics/AbcSize
32
- def initialize(hash = {}, loaded_path = nil)
32
+ def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
33
33
  @loaded_path = loaded_path
34
34
  @for_cop = Hash.new do |h, cop|
35
35
  cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
@@ -284,6 +284,10 @@ module RuboCop
284
284
  end
285
285
  end
286
286
 
287
+ def inspect # :nodoc:
288
+ "#<#{self.class.name}:#{object_id} @loaded_path=#{loaded_path}>"
289
+ end
290
+
287
291
  private
288
292
 
289
293
  def target_rails_version_from_bundler_lock_file
@@ -23,6 +23,14 @@ module RuboCop
23
23
  class << self
24
24
  include FileFinder
25
25
 
26
+ PENDING_BANNER = <<~BANNER
27
+ The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
28
+
29
+ Please also note that you can opt-in to new cops by default by adding this to your config:
30
+ AllCops:
31
+ NewCops: enable
32
+ BANNER
33
+
26
34
  attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
27
35
  :ignore_unrecognized_cops
28
36
  attr_writer :default_configuration
@@ -165,14 +173,6 @@ module RuboCop
165
173
  ConfigFinder.project_root
166
174
  end
167
175
 
168
- PENDING_BANNER = <<~BANNER
169
- The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
170
-
171
- Please also note that you can opt-in to new cops by default by adding this to your config:
172
- AllCops:
173
- NewCops: enable
174
- BANNER
175
-
176
176
  def warn_on_pending_cops(pending_cops)
177
177
  warn Rainbow(PENDING_BANNER).yellow
178
178
 
@@ -68,11 +68,11 @@ module RuboCop
68
68
  # Cop rules are keyed by the name of the original cop
69
69
  def load_cop_rules(rules)
70
70
  rules.flat_map do |rule_type, data|
71
- data.map do |cop_name, configuration|
71
+ data.filter_map do |cop_name, configuration|
72
72
  next unless configuration # allow configurations to be disabled with `CopName: ~`
73
73
 
74
74
  COP_RULE_CLASSES[rule_type].new(@config, cop_name, configuration)
75
- end.compact
75
+ end
76
76
  end
77
77
  end
78
78
 
@@ -35,7 +35,7 @@ module RuboCop
35
35
  return false if cop_config['AutoCorrect'] == false
36
36
 
37
37
  # :safe_autocorrect is a derived option based on several command-line
38
- # arguments - see Rubocop::Options#add_autocorrection_options
38
+ # arguments - see RuboCop::Options#add_autocorrection_options
39
39
  return safe_autocorrect? if @options.fetch(:safe_autocorrect, false)
40
40
 
41
41
  true
@@ -43,18 +43,24 @@ module RuboCop
43
43
 
44
44
  private
45
45
 
46
- def disable_offense(range)
47
- heredoc_range = surrounding_heredoc(range)
48
- if heredoc_range
49
- disable_offense_before_and_after(range_by_lines(heredoc_range))
46
+ def disable_offense(offense_range)
47
+ range = surrounding_heredoc(offense_range) || surrounding_percent_array(offense_range)
48
+
49
+ if range
50
+ disable_offense_before_and_after(range_by_lines(range))
51
+ else
52
+ disable_offense_with_eol_or_surround_comment(offense_range)
53
+ end
54
+ end
55
+
56
+ def disable_offense_with_eol_or_surround_comment(range)
57
+ eol_comment = " # rubocop:todo #{cop_name}"
58
+ needed_line_length = (range.source_line + eol_comment).length
59
+
60
+ if needed_line_length <= max_line_length
61
+ disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
50
62
  else
51
- eol_comment = " # rubocop:todo #{cop_name}"
52
- needed_line_length = (range.source_line + eol_comment).length
53
- if needed_line_length <= max_line_length
54
- disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
55
- else
56
- disable_offense_before_and_after(range_by_lines(range))
57
- end
63
+ disable_offense_before_and_after(range_by_lines(range))
58
64
  end
59
65
  end
60
66
 
@@ -69,6 +75,16 @@ module RuboCop
69
75
  .find { |range| range.contains?(offense_range) }
70
76
  end
71
77
 
78
+ def surrounding_percent_array(offense_range)
79
+ return nil if offense_range.empty?
80
+
81
+ percent_array = processed_source.ast.each_descendant.select do |node|
82
+ node.array_type? && node.percent_literal?
83
+ end
84
+
85
+ percent_array.map(&:source_range).find { |range| range.overlaps?(offense_range) }
86
+ end
87
+
72
88
  def range_of_first_line(range)
73
89
  begin_of_first_line = range.begin_pos - range.column
74
90
  end_of_first_line = begin_of_first_line + range.source_line.length
@@ -284,7 +284,7 @@ module RuboCop
284
284
  # @api private
285
285
  def self.callbacks_needed
286
286
  @callbacks_needed ||= public_instance_methods.select do |m|
287
- m.match?(/^on_|^after_/) &&
287
+ m.start_with?(/on_|after_/) &&
288
288
  !Base.method_defined?(m) # exclude standard "callbacks" like 'on_begin_investigation'
289
289
  end
290
290
  end
@@ -305,6 +305,10 @@ module RuboCop
305
305
  @current_original = original
306
306
  end
307
307
 
308
+ def inspect # :nodoc:
309
+ "#<#{self.class.name}:#{object_id} @config=#{@config} @options=#{@options}>"
310
+ end
311
+
308
312
  private
309
313
 
310
314
  ### Reserved for Cop::Cop
@@ -138,10 +138,10 @@ module RuboCop
138
138
  def correction_lambda
139
139
  return unless support_autocorrect?
140
140
 
141
- dedup_on_node(@v0_argument) { autocorrect(@v0_argument) }
141
+ dedupe_on_node(@v0_argument) { autocorrect(@v0_argument) }
142
142
  end
143
143
 
144
- def dedup_on_node(node)
144
+ def dedupe_on_node(node)
145
145
  @corrected_nodes ||= {}.compare_by_identity
146
146
  yield unless @corrected_nodes.key?(node)
147
147
  ensure
@@ -54,7 +54,7 @@ module RuboCop
54
54
  def inside_string_ranges(node)
55
55
  return [] unless node.is_a?(Parser::AST::Node)
56
56
 
57
- node.each_node(:str, :dstr, :xstr).map { |n| inside_string_range(n) }.compact
57
+ node.each_node(:str, :dstr, :xstr).filter_map { |n| inside_string_range(n) }
58
58
  end
59
59
 
60
60
  def inside_string_range(node)
@@ -74,7 +74,7 @@ module RuboCop
74
74
  def add_heredoc_comma(corrector, node)
75
75
  return unless heredoc?(node)
76
76
 
77
- corrector.insert_after(node.child_nodes.last.source_range, ',')
77
+ corrector.insert_after(node.child_nodes.last, ',')
78
78
  end
79
79
 
80
80
  def heredoc?(node)
@@ -66,10 +66,10 @@ module RuboCop
66
66
  end
67
67
  end
68
68
 
69
- def line_breaks(node, source, previous_line_num, base_line_num, node_indx)
69
+ def line_breaks(node, source, previous_line_num, base_line_num, node_index)
70
70
  source_in_lines = source.split("\n")
71
71
  if first_line?(node, previous_line_num)
72
- node_indx.zero? && node.first_line == base_line_num ? '' : ' '
72
+ node_index.zero? && node.first_line == base_line_num ? '' : ' '
73
73
  else
74
74
  process_lines(node, previous_line_num, base_line_num, source_in_lines)
75
75
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Gemspec
6
- # Checks that deprecated attribute attributes are not set in a gemspec file.
6
+ # Checks that deprecated attributes are not set in a gemspec file.
7
7
  # Removing deprecated attributes allows the user to receive smaller packed gems.
8
8
  #
9
9
  # @example
@@ -75,7 +75,7 @@ module RuboCop
75
75
 
76
76
  # @!method add_development_dependency?(node)
77
77
  def_node_matcher :add_development_dependency?, <<~PATTERN
78
- (send _ :add_development_dependency (str #forbidden_gem? ...))
78
+ (send _ :add_development_dependency (str #forbidden_gem? ...) _? _?)
79
79
  PATTERN
80
80
 
81
81
  # @!method gem?(node)
@@ -12,6 +12,13 @@ module RuboCop
12
12
  # ....
13
13
  # end
14
14
  #
15
+ # # bad
16
+ # #
17
+ # # Checks ...
18
+ # class SomeCop < Base
19
+ # ...
20
+ # end
21
+ #
15
22
  # # good
16
23
  # # Checks ...
17
24
  # class SomeCop < Base
@@ -21,27 +28,47 @@ module RuboCop
21
28
  class CopDescription < Base
22
29
  extend AutoCorrector
23
30
 
24
- MSG = 'Description should be started with %<suggestion>s instead of `This cop ...`.'
31
+ MSG_STARTS_WITH_WRONG_WORD =
32
+ 'Description should be started with %<suggestion>s instead of `This cop ...`.'
33
+ MSG_STARTS_WITH_EMPTY_COMMENT_LINE =
34
+ 'Description should not start with an empty comment line.'
25
35
 
26
36
  SPECIAL_WORDS = %w[is can could should will would must may].freeze
27
- COP_DESC_OFFENSE_REGEX = \
37
+ COP_DESC_OFFENSE_REGEX =
28
38
  /^\s+# This cop (?<special>#{SPECIAL_WORDS.join('|')})?\s*(?<word>.+?) .*/.freeze
29
39
  REPLACEMENT_REGEX = /^\s+# This cop (#{SPECIAL_WORDS.join('|')})?\s*(.+?) /.freeze
40
+ EMPTY_COMMENT_LINE_REGEX = /\A\s*#\s*\n\z/.freeze
30
41
 
31
- # rubocop:disable Metrics/CyclomaticComplexity
32
42
  def on_class(node)
33
43
  return unless (module_node = node.parent) && node.parent_class
34
44
 
35
45
  description_beginning = first_comment_line(module_node)
36
46
  return unless description_beginning
37
47
 
38
- start_with_subject = description_beginning.match(COP_DESC_OFFENSE_REGEX)
39
- return unless start_with_subject
48
+ if description_beginning.match?(EMPTY_COMMENT_LINE_REGEX)
49
+ register_offense_for_empty_comment_line(module_node, description_beginning)
50
+ else
51
+ start_with_subject = description_beginning.match(COP_DESC_OFFENSE_REGEX)
52
+ return unless start_with_subject
53
+
54
+ register_offense_for_wrong_word(module_node, description_beginning, start_with_subject)
55
+ end
56
+ end
57
+
58
+ private
40
59
 
60
+ def register_offense_for_empty_comment_line(module_node, description_beginning)
61
+ range = range(module_node, description_beginning)
62
+ add_offense(range, message: MSG_STARTS_WITH_EMPTY_COMMENT_LINE) do |corrector|
63
+ corrector.remove(range)
64
+ end
65
+ end
66
+
67
+ def register_offense_for_wrong_word(module_node, description_beginning, start_with_subject)
41
68
  suggestion = start_with_subject['word']&.capitalize
42
69
  range = range(module_node, description_beginning)
43
70
  suggestion_for_message = suggestion_for_message(suggestion, start_with_subject)
44
- message = format(MSG, suggestion: suggestion_for_message)
71
+ message = format(MSG_STARTS_WITH_WRONG_WORD, suggestion: suggestion_for_message)
45
72
 
46
73
  add_offense(range, message: message) do |corrector|
47
74
  if suggestion && !start_with_subject['special']
@@ -49,9 +76,6 @@ module RuboCop
49
76
  end
50
77
  end
51
78
  end
52
- # rubocop:enable Metrics/CyclomaticComplexity
53
-
54
- private
55
79
 
56
80
  def replace_with_suggestion(corrector, range, suggestion, description_beginning)
57
81
  replacement = description_beginning.gsub(REPLACEMENT_REGEX, "#{suggestion} ")
@@ -52,7 +52,7 @@ module RuboCop
52
52
  # @return [void]
53
53
  def autocorrect(corrector, node)
54
54
  [
55
- heredoc_openning_delimiter_range_from(node),
55
+ heredoc_opening_delimiter_range_from(node),
56
56
  heredoc_closing_delimiter_range_from(node)
57
57
  ].each do |range|
58
58
  corrector.replace(range, EXPECTED_HEREDOC_DELIMITER)
@@ -90,7 +90,7 @@ module RuboCop
90
90
 
91
91
  # @param node [RuboCop::AST::StrNode]
92
92
  # @return [Parser::Source::Range]
93
- def heredoc_openning_delimiter_range_from(node)
93
+ def heredoc_opening_delimiter_range_from(node)
94
94
  match_data = node.source.match(Heredoc::OPENING_DELIMITER)
95
95
  node.source_range.begin.adjust(
96
96
  begin_pos: match_data.begin(2),
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module InternalAffairs
6
- # `RuboCop::Cop::Cop` is deprecated and will be removed in Rubocop 2.0.
6
+ # `RuboCop::Cop::Cop` is deprecated and will be removed in RuboCop 2.0.
7
7
  # Your custom cop class should inherit from `RuboCop::Cop::Base` instead of
8
8
  # `RuboCop::Cop::Cop`.
9
9
  #
@@ -59,12 +59,12 @@ module RuboCop
59
59
  def method_directives(node)
60
60
  comments = processed_source.ast_with_comments[node]
61
61
 
62
- comments.map do |comment|
62
+ comments.filter_map do |comment|
63
63
  match = comment.text.match(REGEXP)
64
64
  next unless match
65
65
 
66
66
  { node: comment, method_name: match[:method_name], args: match[:args] }
67
- end.compact
67
+ end
68
68
  end
69
69
 
70
70
  def too_many_directives(node)