rubocop 1.2.0 → 1.3.0

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -10
  3. data/config/default.yml +59 -7
  4. data/lib/rubocop.rb +4 -0
  5. data/lib/rubocop/config_loader.rb +7 -6
  6. data/lib/rubocop/cop/bundler/duplicated_gem.rb +3 -3
  7. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  8. data/lib/rubocop/cop/commissioner.rb +1 -1
  9. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -3
  10. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +4 -5
  11. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  12. data/lib/rubocop/cop/generator.rb +1 -1
  13. data/lib/rubocop/cop/layout/block_alignment.rb +3 -4
  14. data/lib/rubocop/cop/layout/line_length.rb +8 -1
  15. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +23 -2
  16. data/lib/rubocop/cop/lint/debugger.rb +17 -27
  17. data/lib/rubocop/cop/lint/duplicate_branch.rb +93 -0
  18. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +2 -12
  19. data/lib/rubocop/cop/lint/empty_block.rb +23 -0
  20. data/lib/rubocop/cop/lint/empty_class.rb +93 -0
  21. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +21 -3
  22. data/lib/rubocop/cop/lint/loop.rb +4 -0
  23. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +19 -16
  24. data/lib/rubocop/cop/lint/shadowed_exception.rb +4 -5
  25. data/lib/rubocop/cop/lint/useless_method_definition.rb +2 -4
  26. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  27. data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -4
  28. data/lib/rubocop/cop/naming/variable_number.rb +16 -0
  29. data/lib/rubocop/cop/style/and_or.rb +1 -3
  30. data/lib/rubocop/cop/style/collection_compact.rb +6 -0
  31. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +100 -5
  32. data/lib/rubocop/cop/style/identical_conditional_branches.rb +7 -2
  33. data/lib/rubocop/cop/style/if_inside_else.rb +37 -1
  34. data/lib/rubocop/cop/style/if_unless_modifier.rb +7 -3
  35. data/lib/rubocop/cop/style/infinite_loop.rb +4 -0
  36. data/lib/rubocop/cop/style/multiple_comparison.rb +3 -2
  37. data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -2
  38. data/lib/rubocop/cop/style/nil_lambda.rb +52 -0
  39. data/lib/rubocop/cop/style/static_class.rb +97 -0
  40. data/lib/rubocop/cop/style/while_until_modifier.rb +9 -0
  41. data/lib/rubocop/target_ruby.rb +57 -1
  42. data/lib/rubocop/version.rb +1 -1
  43. metadata +9 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9139e9c7213e73e6f44db7e88265254dc4b4e11ab0fa38b0fa88268070ff0a6a
4
- data.tar.gz: 5590d626e845237529e7e21dbc162b2704fdbe5f37a39f0e29d3e164b550a03e
3
+ metadata.gz: 5013f1930869ad961d7fe1cf2cd8bad7a36a15bc37f6cf42e1663fbdb61f2cc2
4
+ data.tar.gz: 1ac4e658406f0f6e22a068f28fab225a8e9f53c59a79f89f0e52157cdc076efc
5
5
  SHA512:
6
- metadata.gz: 04ce9f16ffe193e6a048a2fe2b5c0015a148becdfc25bcd67efdd5cf207727eed3ab3440bbf5f8f2473868d9f697fb88b2c2f810bfe217fb23153d010318bde8
7
- data.tar.gz: bd33137303ca551db1a8e67ad96bb14b376207caf88ba0c82efb3202c2373b94f22bd9e19f3a8b9cfd475bc6955078c13a87b8236e6703e8ad48c2b14a2cb271
6
+ metadata.gz: 555adab63cf768a150f37d2ca84e08f2322e84182528949e09bd5eda4c79348e4c41dc17d23737785ea044a78f54f99d99d512047446d7437efdeaf306147f32
7
+ data.tar.gz: 3fe186c044fd8733f4edef4055c036106d739e485dbfdcdbffe7882961175695edb79aafe27c1b11a8bbe9791f0754f26e7bd7534571dd09955bd5caf6aa6afe
data/README.md CHANGED
@@ -11,11 +11,6 @@
11
11
  [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop-hq/rubocop/maintainability)
12
12
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)
13
13
 
14
- [![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/bbatsov)
15
- [![OpenCollective](https://opencollective.com/rubocop/backers/badge.svg)](#open-collective-backers)
16
- [![OpenCollective](https://opencollective.com/rubocop/sponsors/badge.svg)](#open-collective-sponsors)
17
- [![Tidelift](https://tidelift.com/badges/package/rubygems/rubocop)](https://tidelift.com/subscription/pkg/rubygems-rubocop?utm_source=rubygems-rubocop&utm_medium=referral&utm_campaign=readme)
18
-
19
14
  > Role models are important. <br/>
20
15
  > -- Officer Alex J. Murphy / RoboCop
21
16
 
@@ -27,6 +22,12 @@ RuboCop can also automatically fix many of them for you.
27
22
  RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various
28
23
  [configuration options](https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml).
29
24
 
25
+ ----------
26
+ [![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/bbatsov)
27
+ [![OpenCollective](https://opencollective.com/rubocop/backers/badge.svg)](#open-collective-backers)
28
+ [![OpenCollective](https://opencollective.com/rubocop/sponsors/badge.svg)](#open-collective-sponsors)
29
+ [![Tidelift](https://tidelift.com/badges/package/rubygems/rubocop)](https://tidelift.com/subscription/pkg/rubygems-rubocop?utm_source=rubygems-rubocop&utm_medium=referral&utm_campaign=readme)
30
+
30
31
  **Please consider [financially supporting its ongoing development](#funding).**
31
32
 
32
33
  ## Installation
@@ -50,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
50
51
  in your `Gemfile`:
51
52
 
52
53
  ```rb
53
- gem 'rubocop', '~> 1.2', require: false
54
+ gem 'rubocop', '~> 1.3', require: false
54
55
  ```
55
56
 
56
57
  See [versioning](https://docs.rubocop.org/rubocop/1.0/versioning.html) for further details.
@@ -150,14 +151,19 @@ wide array of funding channels to account for your preferences
150
151
  currently [Open Collective](https://opencollective.com/rubocop) is our
151
152
  preferred funding platform).
152
153
 
153
- If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company
154
- to become a RuboCop sponsor.
154
+ **If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company
155
+ to become a RuboCop sponsor.**
155
156
 
156
157
  You can support the development of RuboCop via
157
158
  [GitHub Sponsors](https://github.com/sponsors/bbatsov),
158
159
  [Patreon](https://www.patreon.com/bbatsov),
159
- [PayPal](https://paypal.me/bbatsov)
160
- and [Open Collective](https://opencollective.com/rubocop).
160
+ [PayPal](https://paypal.me/bbatsov),
161
+ [Open Collective](https://opencollective.com/rubocop)
162
+ and [Tidelift](https://tidelift.com/subscription/pkg/rubygems-rubocop?utm_source=rubygems-rubocop&utm_medium=referral&utm_campaign=readme)
163
+ .
164
+
165
+ **Note:** If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend
166
+ the use of Tidelift, where you can get a support-like subscription instead.
161
167
 
162
168
  ### Open Collective Backers
163
169
 
@@ -891,7 +891,7 @@ Layout/LineLength:
891
891
  StyleGuide: '#max-line-length'
892
892
  Enabled: true
893
893
  VersionAdded: '0.25'
894
- VersionChanged: '0.84'
894
+ VersionChanged: '1.3'
895
895
  AutoCorrect: false
896
896
  Max: 120
897
897
  # To make it possible to copy or click on URIs in the code, we allow lines
@@ -1400,6 +1400,8 @@ Lint/ConstantDefinitionInBlock:
1400
1400
  StyleGuide: '#no-constant-definition-in-block'
1401
1401
  Enabled: true
1402
1402
  VersionAdded: '0.91'
1403
+ VersionChanged: '1.3'
1404
+ AllowedMethods: []
1403
1405
 
1404
1406
  Lint/ConstantResolution:
1405
1407
  Description: 'Check that constants are fully qualified with `::`.'
@@ -1415,6 +1417,22 @@ Lint/Debugger:
1415
1417
  Enabled: true
1416
1418
  VersionAdded: '0.14'
1417
1419
  VersionChanged: '0.49'
1420
+ DebuggerReceivers:
1421
+ - binding
1422
+ - Kernel
1423
+ - Pry
1424
+ DebuggerMethods:
1425
+ - debugger
1426
+ - byebug
1427
+ - remote_byebug
1428
+ - pry
1429
+ - remote_pry
1430
+ - pry_remote
1431
+ - console
1432
+ - rescue
1433
+ - save_and_open_page
1434
+ - save_and_open_screenshot
1435
+ - irb
1418
1436
 
1419
1437
  Lint/DeprecatedClassMethods:
1420
1438
  Description: 'Check for deprecated class method calls.'
@@ -1433,6 +1451,11 @@ Lint/DisjunctiveAssignmentInConstructor:
1433
1451
  VersionAdded: '0.62'
1434
1452
  VersionChanged: '0.88'
1435
1453
 
1454
+ Lint/DuplicateBranch:
1455
+ Description: Checks that there are no repeated bodies within `if/unless`, `case-when` and `rescue` constructs.
1456
+ Enabled: pending
1457
+ VersionAdded: '1.3'
1458
+
1436
1459
  Lint/DuplicateCaseCondition:
1437
1460
  Description: 'Do not repeat values in case conditionals.'
1438
1461
  Enabled: true
@@ -1484,7 +1507,15 @@ Lint/EmptyBlock:
1484
1507
  Description: 'This cop checks for blocks without a body.'
1485
1508
  Enabled: pending
1486
1509
  VersionAdded: '1.1'
1510
+ VersionChanged: '1.3'
1487
1511
  AllowComments: true
1512
+ AllowEmptyLambdas: true
1513
+
1514
+ Lint/EmptyClass:
1515
+ Description: 'Checks for classes and metaclasses without a body.'
1516
+ Enabled: pending
1517
+ VersionAdded: '1.3'
1518
+ AllowComments: false
1488
1519
 
1489
1520
  Lint/EmptyConditionalBody:
1490
1521
  Description: 'This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.'
@@ -1628,7 +1659,8 @@ Lint/Loop:
1628
1659
  StyleGuide: '#loop-with-break'
1629
1660
  Enabled: true
1630
1661
  VersionAdded: '0.9'
1631
- VersionChanged: '0.89'
1662
+ VersionChanged: '1.3'
1663
+ Safe: false
1632
1664
 
1633
1665
  Lint/MissingCopEnableDirective:
1634
1666
  Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`.'
@@ -2416,7 +2448,7 @@ Naming/VariableNumber:
2416
2448
  StyleGuide: '#snake-case-symbols-methods-vars-with-numbers'
2417
2449
  Enabled: true
2418
2450
  VersionAdded: '0.50'
2419
- VersionChanged: '1.2'
2451
+ VersionChanged: '1.3'
2420
2452
  EnforcedStyle: normalcase
2421
2453
  SupportedStyles:
2422
2454
  - snake_case
@@ -2424,6 +2456,7 @@ Naming/VariableNumber:
2424
2456
  - non_integer
2425
2457
  CheckMethodNames: true
2426
2458
  CheckSymbols: true
2459
+ AllowedIdentifiers: []
2427
2460
 
2428
2461
  #################### Security ##############################
2429
2462
 
@@ -2805,7 +2838,9 @@ Style/ClassVars:
2805
2838
  Style/CollectionCompact:
2806
2839
  Description: 'Use `{Array,Hash}#{compact,compact!}` instead of custom logic to reject nils.'
2807
2840
  Enabled: pending
2841
+ Safe: false
2808
2842
  VersionAdded: '1.2'
2843
+ VersionChanged: '1.3'
2809
2844
 
2810
2845
  # Align with the style guide.
2811
2846
  Style/CollectionMethods:
@@ -2870,17 +2905,18 @@ Style/CommandLiteral:
2870
2905
  Style/CommentAnnotation:
2871
2906
  Description: >-
2872
2907
  Checks formatting of special comments
2873
- (TODO, FIXME, OPTIMIZE, HACK, REVIEW).
2908
+ (TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE).
2874
2909
  StyleGuide: '#annotate-keywords'
2875
2910
  Enabled: true
2876
2911
  VersionAdded: '0.10'
2877
- VersionChanged: '0.31'
2912
+ VersionChanged: '1.3'
2878
2913
  Keywords:
2879
2914
  - TODO
2880
2915
  - FIXME
2881
2916
  - OPTIMIZE
2882
2917
  - HACK
2883
2918
  - REVIEW
2919
+ - NOTE
2884
2920
 
2885
2921
  Style/CommentedKeyword:
2886
2922
  Description: 'Do not place comments on the same line as certain keywords.'
@@ -2976,6 +3012,7 @@ Style/DocumentDynamicEvalDefinition:
2976
3012
  StyleGuide: '#eval-comment-docs'
2977
3013
  Enabled: pending
2978
3014
  VersionAdded: '1.1'
3015
+ VersionChanged: '1.3'
2979
3016
 
2980
3017
  Style/Documentation:
2981
3018
  Description: 'Document classes and non-namespace modules.'
@@ -3303,6 +3340,7 @@ Style/IfInsideElse:
3303
3340
  Enabled: true
3304
3341
  AllowIfModifier: false
3305
3342
  VersionAdded: '0.36'
3343
+ VersionChanged: '1.3'
3306
3344
 
3307
3345
  Style/IfUnlessModifier:
3308
3346
  Description: >-
@@ -3335,12 +3373,14 @@ Style/ImplicitRuntimeError:
3335
3373
  VersionAdded: '0.41'
3336
3374
 
3337
3375
  Style/InfiniteLoop:
3338
- Description: 'Use Kernel#loop for infinite loops.'
3376
+ Description: >-
3377
+ Use Kernel#loop for infinite loops.
3378
+ This cop is unsafe in the body may raise a `StopIteration` exception.
3379
+ Safe: false
3339
3380
  StyleGuide: '#infinite-loop'
3340
3381
  Enabled: true
3341
3382
  VersionAdded: '0.26'
3342
3383
  VersionChanged: '0.61'
3343
- SafeAutoCorrect: true
3344
3384
 
3345
3385
  Style/InlineComment:
3346
3386
  Description: 'Avoid trailing inline comments.'
@@ -3723,6 +3763,11 @@ Style/NilComparison:
3723
3763
  - predicate
3724
3764
  - comparison
3725
3765
 
3766
+ Style/NilLambda:
3767
+ Description: 'Prefer `-> {}` to `-> { nil }`.'
3768
+ Enabled: pending
3769
+ VersionAdded: '1.3'
3770
+
3726
3771
  Style/NonNilCheck:
3727
3772
  Description: 'Checks for redundant nil checks.'
3728
3773
  StyleGuide: '#no-non-nil-checks'
@@ -4222,6 +4267,13 @@ Style/StabbyLambdaParentheses:
4222
4267
  - require_parentheses
4223
4268
  - require_no_parentheses
4224
4269
 
4270
+ Style/StaticClass:
4271
+ Description: 'Prefer modules to classes with only class methods.'
4272
+ StyleGuide: '#modules-vs-classes'
4273
+ Enabled: false
4274
+ Safe: false
4275
+ VersionAdded: '1.3'
4276
+
4225
4277
  Style/StderrPuts:
4226
4278
  Description: 'Use `warn` instead of `$stderr.puts`.'
4227
4279
  StyleGuide: '#warn'
@@ -259,6 +259,7 @@ require_relative 'rubocop/cop/lint/debugger'
259
259
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
260
260
  require_relative 'rubocop/cop/lint/deprecated_open_ssl_constant'
261
261
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
262
+ require_relative 'rubocop/cop/lint/duplicate_branch'
262
263
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
263
264
  require_relative 'rubocop/cop/lint/duplicate_elsif_condition'
264
265
  require_relative 'rubocop/cop/lint/duplicate_hash_key'
@@ -269,6 +270,7 @@ require_relative 'rubocop/cop/lint/duplicate_rescue_exception'
269
270
  require_relative 'rubocop/cop/lint/each_with_object_argument'
270
271
  require_relative 'rubocop/cop/lint/else_layout'
271
272
  require_relative 'rubocop/cop/lint/empty_block'
273
+ require_relative 'rubocop/cop/lint/empty_class'
272
274
  require_relative 'rubocop/cop/lint/empty_conditional_body'
273
275
  require_relative 'rubocop/cop/lint/empty_ensure'
274
276
  require_relative 'rubocop/cop/lint/empty_expression'
@@ -480,6 +482,7 @@ require_relative 'rubocop/cop/style/redundant_fetch_block'
480
482
  require_relative 'rubocop/cop/style/redundant_file_extension_in_require'
481
483
  require_relative 'rubocop/cop/style/redundant_self_assignment'
482
484
  require_relative 'rubocop/cop/style/sole_nested_conditional'
485
+ require_relative 'rubocop/cop/style/static_class'
483
486
  require_relative 'rubocop/cop/style/method_called_on_do_end_block'
484
487
  require_relative 'rubocop/cop/style/method_def_parentheses'
485
488
  require_relative 'rubocop/cop/style/min_max'
@@ -506,6 +509,7 @@ require_relative 'rubocop/cop/style/nested_parenthesized_calls'
506
509
  require_relative 'rubocop/cop/style/nested_ternary_operator'
507
510
  require_relative 'rubocop/cop/style/next'
508
511
  require_relative 'rubocop/cop/style/nil_comparison'
512
+ require_relative 'rubocop/cop/style/nil_lambda'
509
513
  require_relative 'rubocop/cop/style/non_nil_check'
510
514
  require_relative 'rubocop/cop/style/not'
511
515
  require_relative 'rubocop/cop/style/numeric_literals'
@@ -255,17 +255,18 @@ module RuboCop
255
255
  "Configuration file not found: #{absolute_path}"
256
256
  end
257
257
 
258
- def yaml_safe_load(yaml_code, filename)
259
- if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
260
- SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
261
- # Ruby 2.6+
262
- elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
258
+ raise 'SafeYAML is unmaintained, no longer needed and should be removed' if defined?(SafeYAML)
259
+
260
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
261
+ def yaml_safe_load(yaml_code, filename)
263
262
  YAML.safe_load(yaml_code,
264
263
  permitted_classes: [Regexp, Symbol],
265
264
  permitted_symbols: [],
266
265
  aliases: true,
267
266
  filename: filename)
268
- else
267
+ end
268
+ else # Ruby < 2.6
269
+ def yaml_safe_load(yaml_code, filename)
269
270
  YAML.safe_load(yaml_code, [Regexp, Symbol], [], true, filename)
270
271
  end
271
272
  end
@@ -35,13 +35,13 @@ module RuboCop
35
35
  # gem 'rubocop', '~> 0.90.0'
36
36
  # end
37
37
  #
38
- class DuplicatedGem < Cop
38
+ class DuplicatedGem < Base
39
39
  include RangeHelp
40
40
 
41
41
  MSG = 'Gem `%<gem_name>s` requirements already given on line '\
42
42
  '%<line_of_first_occurrence>d of the Gemfile.'
43
43
 
44
- def investigate(processed_source)
44
+ def on_new_investigation
45
45
  return if processed_source.blank?
46
46
 
47
47
  duplicated_gem_nodes.each do |nodes|
@@ -89,7 +89,7 @@ module RuboCop
89
89
  gem_name: gem_name,
90
90
  line_of_first_occurrence: line_of_first_occurrence
91
91
  )
92
- add_offense(node, location: offense_location, message: message)
92
+ add_offense(offense_location, message: message)
93
93
  end
94
94
  end
95
95
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  # # Version 2.1 introduces breaking change baz
59
59
  # gem 'bar', '< 2.1'
60
60
  #
61
- class GemComment < Cop
61
+ class GemComment < Base
62
62
  include DefNode
63
63
 
64
64
  MSG = 'Missing gem description comment.'
@@ -138,7 +138,7 @@ module RuboCop
138
138
  end
139
139
  end
140
140
 
141
- # Note: mutates `callbacks` in place
141
+ # NOTE: mutates `callbacks` in place
142
142
  def restricted_map(callbacks)
143
143
  map = {}
144
144
  callbacks&.select! do |cop|
@@ -34,7 +34,7 @@ module RuboCop
34
34
  # spec.add_runtime_dependency('parallel', '~> 1.10')
35
35
  # spec.add_runtime_dependency('parser', '>= 2.3.3.1', '< 3.0')
36
36
  # end
37
- class DuplicatedAssignment < Cop
37
+ class DuplicatedAssignment < Base
38
38
  include RangeHelp
39
39
 
40
40
  MSG = '`%<assignment>s` method calls already given on line '\
@@ -54,7 +54,7 @@ module RuboCop
54
54
  (lvar #match_block_variable_name?) #assignment_method? ...)
55
55
  PATTERN
56
56
 
57
- def investigate(processed_source)
57
+ def on_new_investigation
58
58
  return if processed_source.blank?
59
59
 
60
60
  duplicated_assignment_method_nodes.each do |nodes|
@@ -96,7 +96,7 @@ module RuboCop
96
96
  assignment: assignment,
97
97
  line_of_first_occurrence: line_of_first_occurrence
98
98
  )
99
- add_offense(node, location: offense_location, message: message)
99
+ add_offense(offense_location, message: message)
100
100
  end
101
101
  end
102
102
  end
@@ -45,7 +45,7 @@ module RuboCop
45
45
  # Gem::Specification.new do |spec|
46
46
  # spec.required_ruby_version = '~> 2.5'
47
47
  # end
48
- class RequiredRubyVersion < Cop
48
+ class RequiredRubyVersion < Base
49
49
  include RangeHelp
50
50
 
51
51
  NOT_EQUAL_MSG = '`required_ruby_version` (%<required_ruby_version>s, ' \
@@ -64,7 +64,7 @@ module RuboCop
64
64
  PATTERN
65
65
 
66
66
  # rubocop:disable Metrics/AbcSize
67
- def investigate(processed_source)
67
+ def on_new_investigation
68
68
  version_def = required_ruby_version(processed_source.ast).first
69
69
 
70
70
  if version_def
@@ -72,13 +72,12 @@ module RuboCop
72
72
  return if !ruby_version || ruby_version == target_ruby_version.to_s
73
73
 
74
74
  add_offense(
75
- processed_source.ast,
76
- location: version_def.loc.expression,
75
+ version_def.loc.expression,
77
76
  message: not_equal_message(ruby_version, target_ruby_version)
78
77
  )
79
78
  else
80
79
  range = source_range(processed_source.buffer, 1, 0)
81
- add_offense(nil, location: range, message: MISSING_MSG)
80
+ add_offense(range, message: MISSING_MSG)
82
81
  end
83
82
  end
84
83
  # rubocop:enable Metrics/AbcSize
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # spec.add_runtime_dependency 'gem_a'
26
26
  # end
27
27
  #
28
- class RubyVersionGlobalsUsage < Cop
28
+ class RubyVersionGlobalsUsage < Base
29
29
  MSG = 'Do not use `RUBY_VERSION` in gemspec file.'
30
30
 
31
31
  def_node_matcher :ruby_version?, '(const {cbase nil?} :RUBY_VERSION)'
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # and spec file when given a valid qualified cop name.
9
9
  # @api private
10
10
  class Generator
11
- # Note: RDoc 5.1.0 or lower has the following issue.
11
+ # NOTE: RDoc 5.1.0 or lower has the following issue.
12
12
  # https://github.com/rubocop-hq/rubocop/issues/7043
13
13
  #
14
14
  # The following `String#gsub` can be replaced with
@@ -210,10 +210,9 @@ module RuboCop
210
210
  end
211
211
 
212
212
  def alt_start_msg(start_loc, source_line_column)
213
- if style != :either
214
- ''
215
- elsif start_loc.line == source_line_column[:line] &&
216
- start_loc.column == source_line_column[:column]
213
+ if style != :either ||
214
+ (start_loc.line == source_line_column[:line] &&
215
+ start_loc.column == source_line_column[:column])
217
216
  ''
218
217
  else
219
218
  " or #{format_source_line_column(source_line_column)}"
@@ -88,6 +88,10 @@ module RuboCop
88
88
  end
89
89
  end
90
90
 
91
+ def correctable?
92
+ super && !breakable_range.nil?
93
+ end
94
+
91
95
  def autocorrect(range)
92
96
  return if range.nil?
93
97
 
@@ -98,6 +102,8 @@ module RuboCop
98
102
 
99
103
  private
100
104
 
105
+ attr_accessor :breakable_range
106
+
101
107
  def check_for_breakable_node(node)
102
108
  breakable_node = extract_breakable_node(node, max)
103
109
  return if breakable_node.nil?
@@ -195,7 +201,8 @@ module RuboCop
195
201
  def register_offense(loc, line, line_index)
196
202
  message = format(MSG, length: line_length(line), max: max)
197
203
 
198
- breakable_range = breakable_range_by_line_index[line_index]
204
+ self.breakable_range = breakable_range_by_line_index[line_index]
205
+
199
206
  add_offense(breakable_range, location: loc, message: message) do
200
207
  self.max = line_length(line)
201
208
  end