rubocop 1.77.0 → 1.80.2

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -3
  3. data/config/default.yml +36 -20
  4. data/exe/rubocop +1 -8
  5. data/lib/rubocop/cli.rb +17 -1
  6. data/lib/rubocop/config_loader.rb +1 -38
  7. data/lib/rubocop/cop/correctors/alignment_corrector.rb +6 -3
  8. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  9. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  10. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +3 -2
  11. data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
  12. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
  13. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
  14. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  15. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -0
  16. data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
  17. data/lib/rubocop/cop/layout/space_around_operators.rb +8 -0
  18. data/lib/rubocop/cop/lint/duplicate_methods.rb +25 -4
  19. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  20. data/lib/rubocop/cop/lint/literal_as_condition.rb +15 -1
  21. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -2
  22. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
  23. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
  24. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +4 -4
  25. data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
  26. data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
  27. data/lib/rubocop/cop/lint/self_assignment.rb +5 -4
  28. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  29. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
  30. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
  31. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  32. data/lib/rubocop/cop/naming/method_name.rb +127 -13
  33. data/lib/rubocop/cop/naming/predicate_method.rb +30 -4
  34. data/lib/rubocop/cop/security/eval.rb +2 -1
  35. data/lib/rubocop/cop/security/open.rb +1 -0
  36. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
  37. data/lib/rubocop/cop/style/accessor_grouping.rb +13 -1
  38. data/lib/rubocop/cop/style/arguments_forwarding.rb +11 -17
  39. data/lib/rubocop/cop/style/array_intersect.rb +98 -34
  40. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  41. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  42. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  43. data/lib/rubocop/cop/style/dig_chain.rb +1 -1
  44. data/lib/rubocop/cop/style/exponential_notation.rb +1 -0
  45. data/lib/rubocop/cop/style/hash_conversion.rb +8 -9
  46. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  47. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  48. data/lib/rubocop/cop/style/it_assignment.rb +69 -12
  49. data/lib/rubocop/cop/style/it_block_parameter.rb +3 -1
  50. data/lib/rubocop/cop/style/map_to_hash.rb +1 -3
  51. data/lib/rubocop/cop/style/map_to_set.rb +1 -3
  52. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
  53. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
  54. data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
  55. data/lib/rubocop/cop/style/redundant_begin.rb +34 -0
  56. data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
  57. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
  58. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  59. data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -1
  60. data/lib/rubocop/cop/style/redundant_parentheses.rb +28 -11
  61. data/lib/rubocop/cop/style/safe_navigation.rb +20 -1
  62. data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
  63. data/lib/rubocop/cop/style/sole_nested_conditional.rb +30 -1
  64. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
  65. data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
  66. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  67. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  68. data/lib/rubocop/cop/variable_force.rb +25 -8
  69. data/lib/rubocop/cops_documentation_generator.rb +1 -0
  70. data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -5
  71. data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
  72. data/lib/rubocop/formatter/pacman_formatter.rb +1 -0
  73. data/lib/rubocop/lsp/routes.rb +35 -6
  74. data/lib/rubocop/pending_cops_reporter.rb +56 -0
  75. data/lib/rubocop/result_cache.rb +14 -12
  76. data/lib/rubocop/runner.rb +6 -4
  77. data/lib/rubocop/server/cache.rb +4 -2
  78. data/lib/rubocop/server/client_command/base.rb +10 -0
  79. data/lib/rubocop/server/client_command/exec.rb +2 -1
  80. data/lib/rubocop/server/client_command/start.rb +11 -1
  81. data/lib/rubocop/target_finder.rb +9 -9
  82. data/lib/rubocop/version.rb +1 -1
  83. data/lib/rubocop.rb +3 -0
  84. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 871a632c96e6a5c92e57b651037eaf7efd7412e64ac77440d5275027ef791d4e
4
- data.tar.gz: f375ec6479b1f90193cd39e863411707d60cd071e170888005339d89a19ea65b
3
+ metadata.gz: 427aedeb12fa3d9d84e7ccd8ea4c125b418a3170c0f91d02e66ef8717006fc0a
4
+ data.tar.gz: f5a5b09520f27ed77d9cc5e2077ce9a55fa77db97bdd1d593e399551abd45bb8
5
5
  SHA512:
6
- metadata.gz: f8dac3eb5cb12741c110c8726ec64595cefb89700527144cc590d7febb676164e3902dff171594278f7895d1c3df336dea3e14f869d285a0c7080b1467bd6362
7
- data.tar.gz: 4aadc7a712774810e1815f4f31bea43fc6d9e121a547621f57894c7df848a6459dfc962af0fb725f4fef6e2017b6a499c203cc05a4d2879d0e50aceaee156b95
6
+ metadata.gz: ddcf6fc4b8e900f900f5734c647b3d681d731d6d4bf37729c4960a751ace231d8835ca9800d4e499d1908f7e0474445bbf2490f5c8b9408d1301d6bff1196794
7
+ data.tar.gz: 94f856e78e6af3c0c78fd926268ae8349af663c2e7a1bc40a11842bb04db7a6baa1f239cb2c537ef8b442a4a76dfc09a8a7bfe10244abb2a78ed3b3b6600d38b
data/README.md CHANGED
@@ -6,8 +6,6 @@
6
6
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
7
7
  [![Gem Version](https://badge.fury.io/rb/rubocop.svg)](https://badge.fury.io/rb/rubocop)
8
8
  [![CI](https://github.com/rubocop/rubocop/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop/actions/workflows/rubocop.yml)
9
- [![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
10
- [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop/rubocop/maintainability)
11
9
  [![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?sanitize=true)](https://discord.gg/wJjWvGRDmm)
12
10
 
13
11
  > Role models are important. <br/>
@@ -53,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
53
51
  in your `Gemfile`:
54
52
 
55
53
  ```rb
56
- gem 'rubocop', '~> 1.77', require: false
54
+ gem 'rubocop', '~> 1.80', require: false
57
55
  ```
58
56
 
59
57
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -378,7 +378,7 @@ Gemspec/RubyVersionGlobalsUsage:
378
378
  #################### Layout ###########################
379
379
 
380
380
  Layout/AccessModifierIndentation:
381
- Description: Check indentation of private/protected visibility modifiers.
381
+ Description: Checks indentation of private/protected visibility modifiers.
382
382
  StyleGuide: '#indent-public-private-protected'
383
383
  Enabled: true
384
384
  VersionAdded: '0.49'
@@ -638,6 +638,12 @@ Layout/EmptyLines:
638
638
  Enabled: true
639
639
  VersionAdded: '0.49'
640
640
 
641
+ Layout/EmptyLinesAfterModuleInclusion:
642
+ Description: 'Keeps track of empty lines after module inclusion methods.'
643
+ StyleGuide: '#empty-lines-after-module-inclusion'
644
+ Enabled: pending
645
+ VersionAdded: '1.79'
646
+
641
647
  Layout/EmptyLinesAroundAccessModifier:
642
648
  Description: "Keep blank lines around access modifiers."
643
649
  StyleGuide: '#empty-lines-around-access-modifier'
@@ -1051,7 +1057,7 @@ Layout/LeadingCommentSpace:
1051
1057
  AllowSteepAnnotation: false
1052
1058
 
1053
1059
  Layout/LeadingEmptyLines:
1054
- Description: Check for unnecessary blank lines at the beginning of a file.
1060
+ Description: Checks for unnecessary blank lines at the beginning of a file.
1055
1061
  Enabled: true
1056
1062
  VersionAdded: '0.57'
1057
1063
  VersionChanged: '0.77'
@@ -1141,7 +1147,7 @@ Layout/MultilineArrayLineBreaks:
1141
1147
  AllowMultilineFinalElement: false
1142
1148
 
1143
1149
  Layout/MultilineAssignmentLayout:
1144
- Description: 'Check for a newline after the assignment operator in multi-line assignments.'
1150
+ Description: 'Checks for a newline after the assignment operator in multi-line assignments.'
1145
1151
  StyleGuide: '#indent-conditional-assignment'
1146
1152
  Enabled: false
1147
1153
  VersionAdded: '0.49'
@@ -1655,7 +1661,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
1655
1661
  VersionChanged: '1.69'
1656
1662
 
1657
1663
  Lint/BooleanSymbol:
1658
- Description: 'Check for `:true` and `:false` symbols.'
1664
+ Description: 'Checks for `:true` and `:false` symbols.'
1659
1665
  Enabled: true
1660
1666
  SafeAutoCorrect: false
1661
1667
  VersionAdded: '0.50'
@@ -1688,7 +1694,7 @@ Lint/ConstantReassignment:
1688
1694
  VersionAdded: '1.70'
1689
1695
 
1690
1696
  Lint/ConstantResolution:
1691
- Description: 'Check that constants are fully qualified with `::`.'
1697
+ Description: 'Checks that constants are fully qualified with `::`.'
1692
1698
  Enabled: false
1693
1699
  VersionAdded: '0.86'
1694
1700
  # Restrict this cop to only looking at certain names
@@ -1702,7 +1708,7 @@ Lint/CopDirectiveSyntax:
1702
1708
  VersionAdded: '1.72'
1703
1709
 
1704
1710
  Lint/Debugger:
1705
- Description: 'Check for debugger calls.'
1711
+ Description: 'Checks for debugger calls.'
1706
1712
  Enabled: true
1707
1713
  VersionAdded: '0.14'
1708
1714
  VersionChanged: '1.63'
@@ -1753,7 +1759,7 @@ Lint/Debugger:
1753
1759
  - debug/start
1754
1760
 
1755
1761
  Lint/DeprecatedClassMethods:
1756
- Description: 'Check for deprecated class method calls.'
1762
+ Description: 'Checks for deprecated class method calls.'
1757
1763
  Enabled: true
1758
1764
  VersionAdded: '0.19'
1759
1765
 
@@ -1827,13 +1833,13 @@ Lint/DuplicateElsifCondition:
1827
1833
  VersionAdded: '0.88'
1828
1834
 
1829
1835
  Lint/DuplicateHashKey:
1830
- Description: 'Check for duplicate keys in hash literals.'
1836
+ Description: 'Checks for duplicate keys in hash literals.'
1831
1837
  Enabled: true
1832
1838
  VersionAdded: '0.34'
1833
1839
  VersionChanged: '0.77'
1834
1840
 
1835
1841
  Lint/DuplicateMagicComment:
1836
- Description: 'Check for duplicated magic comments.'
1842
+ Description: 'Checks for duplicated magic comments.'
1837
1843
  Enabled: pending
1838
1844
  VersionAdded: '1.37'
1839
1845
 
@@ -1843,7 +1849,7 @@ Lint/DuplicateMatchPattern:
1843
1849
  VersionAdded: '1.50'
1844
1850
 
1845
1851
  Lint/DuplicateMethods:
1846
- Description: 'Check for duplicate method definitions.'
1852
+ Description: 'Checks for duplicate method definitions.'
1847
1853
  Enabled: true
1848
1854
  VersionAdded: '0.29'
1849
1855
 
@@ -1853,7 +1859,7 @@ Lint/DuplicateRegexpCharacterClassElement:
1853
1859
  VersionAdded: '1.1'
1854
1860
 
1855
1861
  Lint/DuplicateRequire:
1856
- Description: 'Check for duplicate `require`s and `require_relative`s.'
1862
+ Description: 'Checks for duplicate `require`s and `require_relative`s.'
1857
1863
  Enabled: true
1858
1864
  SafeAutoCorrect: false
1859
1865
  VersionAdded: '0.90'
@@ -1870,12 +1876,12 @@ Lint/DuplicateSetElement:
1870
1876
  VersionAdded: '1.67'
1871
1877
 
1872
1878
  Lint/EachWithObjectArgument:
1873
- Description: 'Check for immutable argument given to each_with_object.'
1879
+ Description: 'Checks for immutable argument given to each_with_object.'
1874
1880
  Enabled: true
1875
1881
  VersionAdded: '0.31'
1876
1882
 
1877
1883
  Lint/ElseLayout:
1878
- Description: 'Check for odd code arrangement in an else block.'
1884
+ Description: 'Checks for odd code arrangement in an else block.'
1879
1885
  Enabled: true
1880
1886
  VersionAdded: '0.17'
1881
1887
  VersionChanged: '1.2'
@@ -2278,6 +2284,7 @@ Lint/RedundantSafeNavigation:
2278
2284
  Description: 'Checks for redundant safe navigation calls.'
2279
2285
  Enabled: true
2280
2286
  VersionAdded: '0.93'
2287
+ VersionChanged: '1.79'
2281
2288
  AllowedMethods:
2282
2289
  - instance_of?
2283
2290
  - kind_of?
@@ -2285,6 +2292,12 @@ Lint/RedundantSafeNavigation:
2285
2292
  - eql?
2286
2293
  - respond_to?
2287
2294
  - equal?
2295
+ InferNonNilReceiver: false
2296
+ AdditionalNilMethods:
2297
+ - present?
2298
+ - blank?
2299
+ - try
2300
+ - try!
2288
2301
  Safe: false
2289
2302
 
2290
2303
  Lint/RedundantSplatExpansion:
@@ -2817,7 +2830,7 @@ Migration/DepartmentName:
2817
2830
  #################### Naming ##############################
2818
2831
 
2819
2832
  Naming/AccessorMethodName:
2820
- Description: Check the naming of accessor methods for get_/set_.
2833
+ Description: Checks the naming of accessor methods for get_/set_.
2821
2834
  StyleGuide: '#accessor_mutator_method_names'
2822
2835
  Enabled: true
2823
2836
  VersionAdded: '0.50'
@@ -3072,7 +3085,7 @@ Naming/PredicateMethod:
3072
3085
  Description: 'Checks that predicate methods end with `?` and non-predicate methods do not.'
3073
3086
  Enabled: pending
3074
3087
  VersionAdded: '1.76'
3075
- VersionChanged: '1.76'
3088
+ VersionChanged: '1.78'
3076
3089
  # In `aggressive` mode, the cop will register an offense for predicate methods that
3077
3090
  # may return a non-boolean value.
3078
3091
  # In `conservative` mode, the cop will *not* register an offense for predicate methods
@@ -3082,6 +3095,9 @@ Naming/PredicateMethod:
3082
3095
  - call
3083
3096
  AllowedPatterns: []
3084
3097
  AllowBangMethods: false
3098
+ # Methods that are known to not return a boolean value, despite ending in `?`.
3099
+ WaywardPredicates:
3100
+ - nonzero?
3085
3101
 
3086
3102
  Naming/PredicatePrefix:
3087
3103
  Description: 'Predicate method names should not be prefixed and end with a `?`.'
@@ -4221,7 +4237,7 @@ Style/GlobalVars:
4221
4237
  AllowedVariables: []
4222
4238
 
4223
4239
  Style/GuardClause:
4224
- Description: 'Check for conditionals that can be replaced with guard clauses.'
4240
+ Description: 'Checks for conditionals that can be replaced with guard clauses.'
4225
4241
  StyleGuide: '#no-nested-conditionals'
4226
4242
  Enabled: true
4227
4243
  VersionAdded: '0.20'
@@ -4483,7 +4499,7 @@ Style/IpAddresses:
4483
4499
  - '**/*.gemspec'
4484
4500
 
4485
4501
  Style/ItAssignment:
4486
- Description: 'Checks for assignment to `it` inside a block.'
4502
+ Description: 'Checks for local variables and method parameters named `it`.'
4487
4503
  Enabled: pending
4488
4504
  VersionAdded: '1.70'
4489
4505
 
@@ -5184,7 +5200,7 @@ Style/RandomWithOffset:
5184
5200
  VersionAdded: '0.52'
5185
5201
 
5186
5202
  Style/RedundantArgument:
5187
- Description: 'Check for a redundant argument passed to certain methods.'
5203
+ Description: 'Checks for a redundant argument passed to certain methods.'
5188
5204
  Enabled: pending
5189
5205
  Safe: false
5190
5206
  VersionAdded: '1.4'
@@ -5345,7 +5361,7 @@ Style/RedundantInterpolationUnfreeze:
5345
5361
  VersionAdded: '1.66'
5346
5362
 
5347
5363
  Style/RedundantLineContinuation:
5348
- Description: 'Check for redundant line continuation.'
5364
+ Description: 'Checks for redundant line continuation.'
5349
5365
  Enabled: pending
5350
5366
  VersionAdded: '1.49'
5351
5367
 
@@ -5639,7 +5655,7 @@ Style/SpecialGlobalVars:
5639
5655
  - use_builtin_english_names
5640
5656
 
5641
5657
  Style/StabbyLambdaParentheses:
5642
- Description: 'Check for the usage of parentheses around stabby lambda arguments.'
5658
+ Description: 'Checks for the usage of parentheses around stabby lambda arguments.'
5643
5659
  StyleGuide: '#stabby-lambda-with-args'
5644
5660
  Enabled: true
5645
5661
  VersionAdded: '0.35'
data/exe/rubocop CHANGED
@@ -12,13 +12,6 @@ if RuboCop::Server.running?
12
12
  exit_status = RuboCop::Server::ClientCommand::Exec.new.run
13
13
  else
14
14
  require 'rubocop'
15
-
16
- cli = RuboCop::CLI.new
17
-
18
- time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
- exit_status = cli.run
20
- elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
21
-
22
- puts "Finished in #{elapsed_time} seconds" if cli.options[:debug] || cli.options[:display_time]
15
+ exit_status = RuboCop::CLI.new.run
23
16
  end
24
17
  exit exit_status
data/lib/rubocop/cli.rb CHANGED
@@ -12,7 +12,7 @@ module RuboCop
12
12
  STATUS_INTERRUPTED = Signal.list['INT'] + 128
13
13
  DEFAULT_PARALLEL_OPTIONS = %i[
14
14
  color config debug display_style_guide display_time display_only_fail_level_offenses
15
- display_only_failed editor_mode except extra_details fail_level fix_layout format
15
+ display_only_failed editor_mode except extra_details fail_level fix_layout format formatters
16
16
  ignore_disable_comments lint only only_guide_cops require safe
17
17
  autocorrect safe_autocorrect autocorrect_all
18
18
  ].freeze
@@ -37,6 +37,8 @@ module RuboCop
37
37
  #
38
38
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39
39
  def run(args = ARGV)
40
+ time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
+
40
42
  @options, paths = Options.new.parse(args)
41
43
  @env = Environment.new(@options, @config_store, paths)
42
44
 
@@ -48,6 +50,7 @@ module RuboCop
48
50
  validate_options_vs_config
49
51
  parallel_by_default!
50
52
  apply_default_formatter
53
+ report_pending_cops
51
54
  execute_runners
52
55
  end
53
56
  end
@@ -71,6 +74,9 @@ module RuboCop
71
74
  warn e.message
72
75
  warn e.backtrace
73
76
  STATUS_ERROR
77
+ ensure
78
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
79
+ puts "Finished in #{elapsed_time} seconds" if @options[:debug] || @options[:display_time]
74
80
  end
75
81
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
76
82
 
@@ -155,6 +161,7 @@ module RuboCop
155
161
 
156
162
  def act_on_options
157
163
  set_options_to_config_loader
164
+ set_options_to_pending_cops_reporter
158
165
  handle_editor_mode
159
166
 
160
167
  @config_store.options_config = @options[:config] if @options[:config]
@@ -179,6 +186,11 @@ module RuboCop
179
186
  ConfigLoader.ignore_unrecognized_cops = @options[:ignore_unrecognized_cops]
180
187
  end
181
188
 
189
+ def set_options_to_pending_cops_reporter
190
+ PendingCopsReporter.disable_pending_cops = @options[:disable_pending_cops]
191
+ PendingCopsReporter.enable_pending_cops = @options[:enable_pending_cops]
192
+ end
193
+
182
194
  def handle_editor_mode
183
195
  RuboCop::LSP.enable if @options[:editor_mode]
184
196
  end
@@ -208,5 +220,9 @@ module RuboCop
208
220
  [[formatter, @options[:output_path]]]
209
221
  end
210
222
  end
223
+
224
+ def report_pending_cops
225
+ PendingCopsReporter.warn_if_needed(@config_store.for_pwd)
226
+ end
211
227
  end
212
228
  end
@@ -22,14 +22,6 @@ module RuboCop
22
22
  class << self
23
23
  include FileFinder
24
24
 
25
- PENDING_BANNER = <<~BANNER
26
- The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
27
-
28
- Please also note that you can opt-in to new cops by default by adding this to your config:
29
- AllCops:
30
- NewCops: enable
31
- BANNER
32
-
33
25
  attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
34
26
  :ignore_unrecognized_cops
35
27
  attr_writer :default_configuration
@@ -132,21 +124,7 @@ module RuboCop
132
124
  add_excludes_from_files(config, config_file)
133
125
  end
134
126
 
135
- merge_with_default(config, config_file).tap do |merged_config|
136
- unless possible_new_cops?(merged_config)
137
- pending_cops = pending_cops_only_qualified(merged_config.pending_cops)
138
- warn_on_pending_cops(pending_cops) unless pending_cops.empty?
139
- end
140
- end
141
- end
142
-
143
- def pending_cops_only_qualified(pending_cops)
144
- pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
145
- end
146
-
147
- def possible_new_cops?(config)
148
- disable_pending_cops || enable_pending_cops ||
149
- config.disabled_new_cops? || config.enabled_new_cops?
127
+ merge_with_default(config, config_file)
150
128
  end
151
129
 
152
130
  def add_excludes_from_files(config, config_file)
@@ -208,21 +186,6 @@ module RuboCop
208
186
  ConfigFinder.project_root
209
187
  end
210
188
 
211
- def warn_on_pending_cops(pending_cops)
212
- warn Rainbow(PENDING_BANNER).yellow
213
-
214
- pending_cops.each { |cop| warn_pending_cop cop }
215
-
216
- warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
217
- end
218
-
219
- def warn_pending_cop(cop)
220
- version = cop.metadata['VersionAdded'] || 'N/A'
221
-
222
- warn Rainbow("#{cop.name}: # new in #{version}").yellow
223
- warn Rainbow(' Enabled: true').yellow
224
- end
225
-
226
189
  # Merges the given configuration with the default one.
227
190
  def merge_with_default(config, config_file, unset_nil: true)
228
191
  resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
@@ -29,10 +29,13 @@ module RuboCop
29
29
  def align_end(corrector, processed_source, node, align_to)
30
30
  @processed_source = processed_source
31
31
  whitespace = whitespace_range(node)
32
- return false unless whitespace.source.strip.empty?
33
-
34
32
  column = alignment_column(align_to)
35
- corrector.replace(whitespace, ' ' * column)
33
+
34
+ if whitespace.source.strip.empty?
35
+ corrector.replace(whitespace, ' ' * column)
36
+ else
37
+ corrector.insert_after(whitespace, "\n#{' ' * column}")
38
+ end
36
39
  end
37
40
 
38
41
  private
@@ -6,7 +6,7 @@ module RuboCop
6
6
  class ForToEachCorrector
7
7
  extend NodePattern::Macros
8
8
 
9
- CORRECTION = '%<collection>s.each do |%<argument>s|'
9
+ CORRECTION = '%<collection>s%<dot>seach do |%<argument>s|'
10
10
 
11
11
  def initialize(for_node)
12
12
  @for_node = for_node
@@ -25,7 +25,12 @@ module RuboCop
25
25
  attr_reader :for_node, :variable_node, :collection_node
26
26
 
27
27
  def correction
28
- format(CORRECTION, collection: collection_source, argument: variable_node.source)
28
+ format(
29
+ CORRECTION,
30
+ collection: collection_source,
31
+ dot: collection_node.csend_type? ? '&.' : '.',
32
+ argument: variable_node.source
33
+ )
29
34
  end
30
35
 
31
36
  def collection_source
@@ -46,7 +46,7 @@ module RuboCop
46
46
  /\A(does not|doesn't) (register|find|flag|report)/ => 'registers',
47
47
  /\A(does not|doesn't) add (a|an|any )?offense/ => 'registers an offense',
48
48
  /\Aregisters no offense/ => 'registers an offense',
49
- /\A(accepts|register)\b/ => 'registers'
49
+ /\A(accepts|allows|register)\b/ => 'registers'
50
50
  }.freeze
51
51
 
52
52
  EXPECT_NO_CORRECTIONS_DESCRIPTION_MAPPING = {
@@ -66,8 +66,9 @@ module RuboCop
66
66
  end
67
67
 
68
68
  def autocorrect_to_explicit_predicate(corrector, node, group_name)
69
- corrector.replace(node.selector, "#{group_name}_type?")
70
- corrector.remove(arguments_range(node))
69
+ range = node.loc.selector.begin.join(node.source_range.end)
70
+
71
+ corrector.replace(range, "#{group_name}_type?")
71
72
  end
72
73
 
73
74
  def autocorrect_keep_method(corrector, symbol_args, group_name, group_types)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module InternalAffairs
6
- # Check for useless `RESTRICT_ON_SEND`.
6
+ # Checks for useless `RESTRICT_ON_SEND`.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Layout
6
+ # Checks for an empty line after a module inclusion method (`extend`,
7
+ # `include` and `prepend`), or a group of them.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # class Foo
12
+ # include Bar
13
+ # attr_reader :baz
14
+ # end
15
+ #
16
+ # # good
17
+ # class Foo
18
+ # include Bar
19
+ #
20
+ # attr_reader :baz
21
+ # end
22
+ #
23
+ # # also good - multiple module inclusions grouped together
24
+ # class Foo
25
+ # extend Bar
26
+ # include Baz
27
+ # prepend Qux
28
+ # end
29
+ #
30
+ class EmptyLinesAfterModuleInclusion < Base
31
+ include RangeHelp
32
+ extend AutoCorrector
33
+
34
+ MSG = 'Add an empty line after module inclusion.'
35
+
36
+ MODULE_INCLUSION_METHODS = %i[include extend prepend].freeze
37
+
38
+ RESTRICT_ON_SEND = MODULE_INCLUSION_METHODS
39
+
40
+ def on_send(node)
41
+ return if node.receiver || node.arguments.empty?
42
+ return if node.parent&.type?(:send, :any_block)
43
+
44
+ return if next_line_empty_or_enable_directive_comment?(node.last_line)
45
+
46
+ next_line_node = next_line_node(node)
47
+ return unless require_empty_line?(next_line_node)
48
+
49
+ add_offense(node) { |corrector| autocorrect(corrector, node) }
50
+ end
51
+
52
+ private
53
+
54
+ def autocorrect(corrector, node)
55
+ node_range = range_by_whole_lines(node.source_range)
56
+
57
+ next_line = node_range.last_line + 1
58
+ if enable_directive_comment?(next_line)
59
+ node_range = processed_source.comment_at_line(next_line)
60
+ end
61
+
62
+ corrector.insert_after(node_range, "\n")
63
+ end
64
+
65
+ def next_line_empty_or_enable_directive_comment?(line)
66
+ line_empty?(line) || (enable_directive_comment?(line + 1) && line_empty?(line + 1))
67
+ end
68
+
69
+ def enable_directive_comment?(line)
70
+ return false unless (comment = processed_source.comment_at_line(line))
71
+
72
+ DirectiveComment.new(comment).enabled?
73
+ end
74
+
75
+ def line_empty?(line)
76
+ processed_source[line].nil? || processed_source[line].blank?
77
+ end
78
+
79
+ def require_empty_line?(node)
80
+ return false unless node
81
+
82
+ !allowed_method?(node)
83
+ end
84
+
85
+ def allowed_method?(node)
86
+ node = node.body if node.respond_to?(:modifier_form?) && node.modifier_form?
87
+
88
+ return false unless node.send_type?
89
+
90
+ MODULE_INCLUSION_METHODS.include?(node.method_name)
91
+ end
92
+
93
+ def next_line_node(node)
94
+ return if node.parent.if_type?
95
+
96
+ node.right_sibling
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -62,40 +62,19 @@ module RuboCop
62
62
  node.receiver && node.receiver.loc.last_line != node.loc.selector&.line
63
63
  end
64
64
 
65
- def empty_lines(node)
66
- lines = processed_lines(node)
67
- lines.select! { |code, _| code.empty? }
68
- lines.map { |_, line| line }
69
- end
70
-
71
- def extra_lines(node)
72
- empty_lines(node).each do |line|
73
- range = source_range(processed_source.buffer, line, 0)
74
- yield(range)
75
- end
76
- end
77
-
78
- def processed_lines(node)
79
- line_numbers(node).each_with_object([]) do |num, array|
80
- array << [processed_source.lines[num - 1], num]
65
+ def extra_lines(node, &block)
66
+ node.arguments.each do |arg|
67
+ empty_range_for_starting_point(arg.source_range.begin, &block)
81
68
  end
82
- end
83
69
 
84
- def line_numbers(node)
85
- inner_lines = []
86
- line_nums = node.arguments.each_with_object([]) do |arg_node, lines|
87
- lines << outer_lines(arg_node)
88
- inner_lines << inner_lines(arg_node) if arg_node.multiline?
89
- end
90
- line_nums.flatten.uniq - inner_lines.flatten - outer_lines(node)
70
+ empty_range_for_starting_point(node.loc.end.begin, &block) if node.loc.end
91
71
  end
92
72
 
93
- def inner_lines(node)
94
- [node.first_line + 1, node.last_line - 1]
95
- end
73
+ def empty_range_for_starting_point(start)
74
+ range = range_with_surrounding_space(start, whitespace: true, side: :left)
75
+ return unless range.last_line - range.first_line > 1
96
76
 
97
- def outer_lines(node)
98
- [node.first_line - 1, node.last_line + 1]
77
+ yield range.source_buffer.line_range(range.last_line - 1).adjust(end_pos: 1)
99
78
  end
100
79
  end
101
80
  end
@@ -71,7 +71,7 @@ module RuboCop
71
71
  KIND = 'class'
72
72
 
73
73
  def on_class(node)
74
- first_line = node.parent_class.first_line if node.parent_class
74
+ first_line = node.parent_class.last_line if node.parent_class
75
75
 
76
76
  check(node, node.body, adjusted_first_line: first_line)
77
77
  end
@@ -10,6 +10,8 @@ module RuboCop
10
10
  # condition, an explicit `return` statement, etc. In other contexts, the second operand should
11
11
  # be indented regardless of enforced style.
12
12
  #
13
+ # In both styles, operators should be aligned when an assignment begins on the next line.
14
+ #
13
15
  # @example EnforcedStyle: aligned (default)
14
16
  # # bad
15
17
  # if a +
@@ -16,6 +16,8 @@ module RuboCop
16
16
  #
17
17
  # something = 123if test
18
18
  #
19
+ # return(foo + bar)
20
+ #
19
21
  # # good
20
22
  # something 'test' do |x|
21
23
  # end
@@ -24,6 +26,9 @@ module RuboCop
24
26
  # end
25
27
  #
26
28
  # something = 123 if test
29
+ #
30
+ # return (foo + bar)
31
+ #
27
32
  class SpaceAroundKeyword < Base
28
33
  extend AutoCorrector
29
34
 
@@ -33,7 +38,7 @@ module RuboCop
33
38
  DO = 'do'
34
39
  SAFE_NAVIGATION = '&.'
35
40
  NAMESPACE_OPERATOR = '::'
36
- ACCEPT_LEFT_PAREN = %w[break defined? next not rescue return super yield].freeze
41
+ ACCEPT_LEFT_PAREN = %w[break defined? next not rescue super yield].freeze
37
42
  ACCEPT_LEFT_SQUARE_BRACKET = %w[super yield].freeze
38
43
  ACCEPT_NAMESPACE_OPERATOR = 'super'
39
44
  RESTRICT_ON_SEND = %i[!].freeze
@@ -151,6 +151,14 @@ module RuboCop
151
151
  check_operator(:match_pattern, node.loc.operator, node)
152
152
  end
153
153
 
154
+ def on_match_alt(node)
155
+ check_operator(:match_alt, node.loc.operator, node)
156
+ end
157
+
158
+ def on_match_as(node)
159
+ check_operator(:match_as, node.loc.operator, node)
160
+ end
161
+
154
162
  alias on_or on_binary
155
163
  alias on_and on_binary
156
164
  alias on_lvasgn on_assignment