rubocop-sorbet 0.7.0 → 0.7.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +1 -1
  3. data/.rubocop.yml +12 -1
  4. data/.yardopts +1 -0
  5. data/Gemfile +1 -0
  6. data/Gemfile.lock +23 -17
  7. data/README.md +1 -1
  8. data/Rakefile +1 -1
  9. data/bin/rspec +4 -2
  10. data/bin/rubocop +4 -2
  11. data/config/default.yml +23 -2
  12. data/lib/rubocop/cop/sorbet/binding_constant_without_type_alias.rb +105 -0
  13. data/lib/rubocop/cop/sorbet/callback_conditionals_binding.rb +39 -11
  14. data/lib/rubocop/cop/sorbet/constants_from_strings.rb +5 -3
  15. data/lib/rubocop/cop/sorbet/forbid_include_const_literal.rb +27 -23
  16. data/lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb +26 -27
  17. data/lib/rubocop/cop/sorbet/forbid_t_unsafe.rb +7 -3
  18. data/lib/rubocop/cop/sorbet/forbid_t_untyped.rb +7 -3
  19. data/lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb +13 -11
  20. data/lib/rubocop/cop/sorbet/implicit_conversion_method.rb +56 -0
  21. data/lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb +49 -0
  22. data/lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb +8 -5
  23. data/lib/rubocop/cop/sorbet/obsolete_strict_memoization.rb +92 -0
  24. data/lib/rubocop/cop/sorbet/one_ancestor_per_line.rb +8 -3
  25. data/lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb +12 -18
  26. data/lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb +8 -7
  27. data/lib/rubocop/cop/sorbet/rbi/single_line_rbi_class_module_definitions.rb +12 -18
  28. data/lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb +5 -6
  29. data/lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb +3 -2
  30. data/lib/rubocop/cop/sorbet/sigils/enforce_single_sigil.rb +6 -5
  31. data/lib/rubocop/cop/sorbet/sigils/false_sigil.rb +1 -1
  32. data/lib/rubocop/cop/sorbet/sigils/has_sigil.rb +1 -1
  33. data/lib/rubocop/cop/sorbet/sigils/ignore_sigil.rb +1 -1
  34. data/lib/rubocop/cop/sorbet/sigils/strict_sigil.rb +1 -1
  35. data/lib/rubocop/cop/sorbet/sigils/strong_sigil.rb +1 -1
  36. data/lib/rubocop/cop/sorbet/sigils/true_sigil.rb +1 -1
  37. data/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +50 -25
  38. data/lib/rubocop/cop/sorbet/signatures/allow_incompatible_override.rb +19 -30
  39. data/lib/rubocop/cop/sorbet/signatures/checked_true_in_signature.rb +3 -2
  40. data/lib/rubocop/cop/sorbet/signatures/empty_line_after_sig.rb +3 -3
  41. data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +8 -4
  42. data/lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb +5 -4
  43. data/lib/rubocop/cop/sorbet/signatures/signature_build_order.rb +8 -3
  44. data/lib/rubocop/cop/sorbet/signatures/signature_cop.rb +6 -1
  45. data/lib/rubocop/cop/sorbet/type_alias_name.rb +10 -17
  46. data/lib/rubocop/cop/sorbet_cops.rb +6 -1
  47. data/lib/rubocop/sorbet/inject.rb +9 -7
  48. data/lib/rubocop/sorbet/version.rb +2 -1
  49. data/lib/rubocop/sorbet.rb +1 -0
  50. data/manual/cops.md +2 -0
  51. data/manual/cops_sorbet.md +137 -31
  52. data/rubocop-sorbet.gemspec +1 -0
  53. data/tasks/cops_documentation.rake +16 -5
  54. metadata +8 -4
  55. data/lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb +0 -127
@@ -6,10 +6,10 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
6
6
  --- | --- | --- | --- | ---
7
7
  Enabled | Yes | No | 0.2.0 | -
8
8
 
9
- This cop disallows using `.override(allow_incompatible: true)`.
9
+ Disallows using `.override(allow_incompatible: true)`.
10
10
  Using `allow_incompatible` suggests a violation of the Liskov
11
11
  Substitution Principle, meaning that a subclass is not a valid
12
- subtype of it's superclass. This Cop prevents these design smells
12
+ subtype of its superclass. This Cop prevents these design smells
13
13
  from occurring.
14
14
 
15
15
  ### Examples
@@ -28,7 +28,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
28
28
  --- | --- | --- | --- | ---
29
29
  Enabled | Yes | Yes | 0.2.0 | -
30
30
 
31
- This cop disallows binding the return value of `T.any`, `T.all`, `T.enum`
31
+ Disallows binding the return value of `T.any`, `T.all`, `T.enum`
32
32
  to a constant directly. To bind the value, one must use `T.type_alias`.
33
33
 
34
34
  ### Examples
@@ -47,7 +47,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
47
47
  --- | --- | --- | --- | ---
48
48
  Disabled | No | Yes | 0.7.0 | -
49
49
 
50
- This cop ensures that callback conditionals are bound to the right type
50
+ Ensures that callback conditionals are bound to the right type
51
51
  so that they are type checked properly.
52
52
 
53
53
  Auto-correction is unsafe because other libraries define similar style callbacks as Rails, but don't always need
@@ -85,7 +85,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
85
85
  --- | --- | --- | --- | ---
86
86
  Enabled | Yes | No | 0.2.0 | -
87
87
 
88
- This cop disallows the usage of `checked(true)`. This usage could cause
88
+ Disallows the usage of `checked(true)`. This usage could cause
89
89
  confusion; it could lead some people to believe that a method would be checked
90
90
  even if runtime checks have not been enabled on the class or globally.
91
91
  Additionally, in the event where checks are enabled, `checked(true)` would
@@ -107,7 +107,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
107
107
  --- | --- | --- | --- | ---
108
108
  Enabled | Yes | No | 0.2.0 | -
109
109
 
110
- This cop disallows the calls that are used to get constants fom Strings
110
+ Disallows the calls that are used to get constants fom Strings
111
111
  such as +constantize+, +const_get+, and +constants+.
112
112
 
113
113
  The goal of this cop is to make the code easier to statically analyze,
@@ -144,7 +144,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
144
144
  --- | --- | --- | --- | ---
145
145
  Enabled | Yes | Yes | 0.7.0 | -
146
146
 
147
- This cop checks for blank lines after signatures.
147
+ Checks for blank lines after signatures.
148
148
 
149
149
  It also suggests an autocorrect
150
150
 
@@ -167,7 +167,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
167
167
  --- | --- | --- | --- | ---
168
168
  Enabled | Yes | Yes | 0.3.4 | -
169
169
 
170
- This cop checks that the Sorbet sigil comes as the first magic comment in the file.
170
+ Checks that the Sorbet sigil comes as the first magic comment in the file.
171
171
 
172
172
  The expected order for magic comments is: (en)?coding, typed, warn_indent then frozen_string_literal.
173
173
 
@@ -196,7 +196,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
196
196
  --- | --- | --- | --- | ---
197
197
  Disabled | Yes | Yes | 0.3.4 | -
198
198
 
199
- This cop checks that every method definition and attribute accessor has a Sorbet signature.
199
+ Checks that every method definition and attribute accessor has a Sorbet signature.
200
200
 
201
201
  It also suggest an autocorrect with placeholders so the following code:
202
202
 
@@ -222,7 +222,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
222
222
  --- | --- | --- | --- | ---
223
223
  Enabled | Yes | Yes | 0.7.0 | -
224
224
 
225
- This cop checks that there is only one Sorbet sigil in a given file
225
+ Checks that there is only one Sorbet sigil in a given file
226
226
 
227
227
  For example, the following class with two sigils
228
228
 
@@ -249,7 +249,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
249
249
  --- | --- | --- | --- | ---
250
250
  Enabled | Yes | Yes | 0.3.3 | -
251
251
 
252
- This cop makes the Sorbet `false` sigil mandatory in all files.
252
+ Makes the Sorbet `false` sigil mandatory in all files.
253
253
 
254
254
  ### Configurable attributes
255
255
 
@@ -265,7 +265,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
265
265
  --- | --- | --- | --- | ---
266
266
  Enabled | Yes | Yes | 0.6.0 | -
267
267
 
268
- This cop ensures RBI shims do not include a call to extend T::Sig
268
+ Ensures RBI shims do not include a call to extend T::Sig
269
269
  or to extend T::Helpers
270
270
 
271
271
  ### Examples
@@ -299,7 +299,26 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
299
299
  --- | --- | --- | --- | ---
300
300
  Disabled | Yes | Yes | 0.2.0 | 0.5.0
301
301
 
302
- No documentation
302
+ Correct `send` expressions in include statements by constant literals.
303
+
304
+ Sorbet, the static checker, is not (yet) able to support constructs on the
305
+ following form:
306
+
307
+ ```ruby
308
+ class MyClass
309
+ include send_expr
310
+ end
311
+ ```
312
+
313
+ Multiple occurences of this can be found in Shopify's code base like:
314
+
315
+ ```ruby
316
+ include Rails.application.routes.url_helpers
317
+ ```
318
+ or
319
+ ```ruby
320
+ include Polaris::Engine.helpers
321
+ ```
303
322
 
304
323
  ## Sorbet/ForbidRBIOutsideOfAllowedPaths
305
324
 
@@ -307,7 +326,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
307
326
  --- | --- | --- | --- | ---
308
327
  Enabled | Yes | No | 0.6.1 | -
309
328
 
310
- This cop makes sure that RBI files are always located under the defined allowed paths.
329
+ Makes sure that RBI files are always located under the defined allowed paths.
311
330
 
312
331
  Options:
313
332
 
@@ -339,7 +358,24 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
339
358
  --- | --- | --- | --- | ---
340
359
  Disabled | Yes | No | 0.2.0 | 0.6.1
341
360
 
342
- No documentation
361
+ Correct superclass `send` expressions by constant literals.
362
+
363
+ Sorbet, the static checker, is not (yet) able to support constructs on the
364
+ following form:
365
+
366
+ ```ruby
367
+ class Foo < send_expr; end
368
+ ```
369
+
370
+ Multiple occurences of this can be found in Shopify's code base like:
371
+
372
+ ```ruby
373
+ class ShopScope < Component::TrustedIdScope[ShopIdentity::ShopId]
374
+ ```
375
+ or
376
+ ```ruby
377
+ class ApiClientEligibility < Struct.new(:api_client, :match_results, :shop)
378
+ ```
343
379
 
344
380
  ### Configurable attributes
345
381
 
@@ -353,7 +389,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
353
389
  --- | --- | --- | --- | ---
354
390
  Disabled | Yes | No | 0.7.0 | 0.7.0
355
391
 
356
- This cop disallows using `T.unsafe` anywhere.
392
+ Disallows using `T.unsafe` anywhere.
357
393
 
358
394
  ### Examples
359
395
 
@@ -371,7 +407,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
371
407
  --- | --- | --- | --- | ---
372
408
  Disabled | Yes | No | 0.6.9 | 0.7.0
373
409
 
374
- This cop disallows using `T.untyped` anywhere.
410
+ Disallows using `T.untyped` anywhere.
375
411
 
376
412
  ### Examples
377
413
 
@@ -391,7 +427,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
391
427
  --- | --- | --- | --- | ---
392
428
  Enabled | Yes | No | 0.4.0 | -
393
429
 
394
- This cop disallows use of `T.untyped` or `T.nilable(T.untyped)`
430
+ Disallows use of `T.untyped` or `T.nilable(T.untyped)`
395
431
  as a prop type for `T::Struct` or `T::ImmutableStruct`.
396
432
 
397
433
  ### Examples
@@ -416,7 +452,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
416
452
  --- | --- | --- | --- | ---
417
453
  Disabled | Yes | Yes | 0.3.3 | -
418
454
 
419
- This cop makes the Sorbet typed sigil mandatory in all files.
455
+ Makes the Sorbet typed sigil mandatory in all files.
420
456
 
421
457
  Options:
422
458
 
@@ -430,7 +466,8 @@ If a `MinimumStrictness` level is specified, it will be used in offense messages
430
466
  Name | Default value | Configurable values
431
467
  --- | --- | ---
432
468
  SuggestedStrictness | `false` | String
433
- MinimumStrictness | `false` | String
469
+ MinimumStrictness | `nil` | String
470
+ ExactStrictness | `nil` | String
434
471
  Include | `**/*.{rb,rbi,rake,ru}` | Array
435
472
  Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
436
473
 
@@ -440,7 +477,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
440
477
  --- | --- | --- | --- | ---
441
478
  Disabled | Yes | Yes | 0.3.3 | -
442
479
 
443
- This cop makes the Sorbet `ignore` sigil mandatory in all files.
480
+ Makes the Sorbet `ignore` sigil mandatory in all files.
444
481
 
445
482
  ### Configurable attributes
446
483
 
@@ -450,13 +487,42 @@ SuggestedStrictness | `ignore` | String
450
487
  Include | `**/*.{rb,rbi,rake,ru}` | Array
451
488
  Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
452
489
 
490
+ ## Sorbet/ImplicitConversionMethod
491
+
492
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
493
+ --- | --- | --- | --- | ---
494
+ Disabled | Yes | No | <<next>> | -
495
+
496
+ Disallows declaring implicit conversion methods.
497
+ Since Sorbet is a nominal (not structural) type system,
498
+ implicit conversion is currently unsupported.
499
+
500
+ ### Examples
501
+
502
+ ```ruby
503
+ # bad
504
+ def to_str; end
505
+
506
+ # good
507
+ def to_str(x); end
508
+
509
+ # bad
510
+ def self.to_str; end
511
+
512
+ # good
513
+ def self.to_str(x); end
514
+
515
+ # bad
516
+ alias to_str to_s
517
+ ```
518
+
453
519
  ## Sorbet/KeywordArgumentOrdering
454
520
 
455
521
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
456
522
  --- | --- | --- | --- | ---
457
523
  Enabled | Yes | No | 0.2.0 | -
458
524
 
459
- This cop checks for the ordering of keyword arguments required by
525
+ Checks for the ordering of keyword arguments required by
460
526
  sorbet-runtime. The ordering requires that all keyword arguments
461
527
  are at the end of the parameters list, and all keyword arguments
462
528
  with a default value must be after those without default values.
@@ -473,13 +539,50 @@ sig { params(b: String, a: Integer).void }
473
539
  def foo(b:, a: 1); end
474
540
  ```
475
541
 
542
+ ## Sorbet/ObsoleteStrictMemoization
543
+
544
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
545
+ --- | --- | --- | --- | ---
546
+ Enabled | Yes | Yes | 0.7.1 | -
547
+
548
+ Checks for the obsolete pattern for initializing instance variables that was required for older Sorbet
549
+ versions in `#typed: strict` files.
550
+
551
+ It's no longer required, as of Sorbet 0.5.10210
552
+ See https://sorbet.org/docs/type-assertions#put-type-assertions-behind-memoization
553
+
554
+ ### Examples
555
+
556
+ ```ruby
557
+ # bad
558
+ sig { returns(Foo) }
559
+ def foo
560
+ @foo = T.let(@foo, T.nilable(Foo))
561
+ @foo ||= Foo.new
562
+ end
563
+
564
+ # bad
565
+ sig { returns(Foo) }
566
+ def foo
567
+ # This would have been a mistake, causing the memoized value to be discarded and recomputed on every call.
568
+ @foo = T.let(nil, T.nilable(Foo))
569
+ @foo ||= Foo.new
570
+ end
571
+
572
+ # good
573
+ sig { returns(Foo) }
574
+ def foo
575
+ @foo ||= T.let(Foo.new, T.nilable(Foo))
576
+ end
577
+ ```
578
+
476
579
  ## Sorbet/OneAncestorPerLine
477
580
 
478
581
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
479
582
  --- | --- | --- | --- | ---
480
583
  Disabled | Yes | Yes | 0.6.0 | -
481
584
 
482
- This cop ensures one ancestor per requires_ancestor line
585
+ Ensures one ancestor per requires_ancestor line
483
586
  rather than chaining them as a comma-separated list.
484
587
 
485
588
  ### Examples
@@ -548,7 +651,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
548
651
  --- | --- | --- | --- | ---
549
652
  Disabled | Yes | Yes | 0.6.0 | -
550
653
 
551
- This cop ensures empty class/module definitions in RBI files are
654
+ Ensures empty class/module definitions in RBI files are
552
655
  done on a single line rather than being split across multiple lines.
553
656
 
554
657
  ### Examples
@@ -574,7 +677,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
574
677
  --- | --- | --- | --- | ---
575
678
  Disabled | Yes | Yes | 0.3.3 | -
576
679
 
577
- This cop makes the Sorbet `strict` sigil mandatory in all files.
680
+ Makes the Sorbet `strict` sigil mandatory in all files.
578
681
 
579
682
  ### Configurable attributes
580
683
 
@@ -590,7 +693,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
590
693
  --- | --- | --- | --- | ---
591
694
  Disabled | Yes | Yes | 0.3.3 | -
592
695
 
593
- This cop makes the Sorbet `strong` sigil mandatory in all files.
696
+ Makes the Sorbet `strong` sigil mandatory in all files.
594
697
 
595
698
  ### Configurable attributes
596
699
 
@@ -606,7 +709,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
606
709
  --- | --- | --- | --- | ---
607
710
  Disabled | Yes | Yes | 0.3.3 | -
608
711
 
609
- This cop makes the Sorbet `true` sigil mandatory in all files.
712
+ Makes the Sorbet `true` sigil mandatory in all files.
610
713
 
611
714
  ### Configurable attributes
612
715
 
@@ -622,7 +725,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
622
725
  --- | --- | --- | --- | ---
623
726
  Enabled | Yes | No | 0.6.6 | -
624
727
 
625
- This cop ensures all constants used as `T.type_alias` are using CamelCase.
728
+ Ensures all constants used as `T.type_alias` are using CamelCase.
626
729
 
627
730
  ### Examples
628
731
 
@@ -647,7 +750,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
647
750
  --- | --- | --- | --- | ---
648
751
  Enabled | Yes | Yes | 0.3.3 | -
649
752
 
650
- This cop checks that every Ruby file contains a valid Sorbet sigil.
753
+ Checks that every Ruby file contains a valid Sorbet sigil.
651
754
  Adapted from: https://gist.github.com/clarkdave/85aca4e16f33fd52aceb6a0a29936e52
652
755
 
653
756
  Options:
@@ -655,8 +758,10 @@ Options:
655
758
  * `RequireSigilOnAllFiles`: make offense if the Sorbet typed is not found in the file (default: false)
656
759
  * `SuggestedStrictness`: Sorbet strictness level suggested in offense messages (default: 'false')
657
760
  * `MinimumStrictness`: If set, make offense if the strictness level in the file is below this one
761
+ * `ExactStrictness`: If set, make offense if the strictness level in the file is different than this one
658
762
 
659
- If a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
763
+ If an `ExactStrictness` level is specified, it will be used in offense messages and autocorrect.
764
+ Otherwise, if a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
660
765
 
661
766
  ### Configurable attributes
662
767
 
@@ -664,6 +769,7 @@ Name | Default value | Configurable values
664
769
  --- | --- | ---
665
770
  RequireSigilOnAllFiles | `false` | Boolean
666
771
  SuggestedStrictness | `false` | String
667
- MinimumStrictness | `false` | String
772
+ MinimumStrictness | `nil` | String
773
+ ExactStrictness | `nil` | String
668
774
  Include | `**/*.{rb,rbi,rake,ru}` | Array
669
775
  Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "lib/rubocop/sorbet/version"
3
4
 
4
5
  Gem::Specification.new do |spec|
@@ -46,12 +46,15 @@ task generate_cops_documentation: :yard_for_generate_documentation do
46
46
 
47
47
  def properties(config, cop)
48
48
  header = [
49
- "Enabled by default", "Safe", "Supports autocorrection", "VersionAdded",
50
- "VersionChanged"
49
+ "Enabled by default",
50
+ "Safe",
51
+ "Supports autocorrection",
52
+ "VersionAdded",
53
+ "VersionChanged",
51
54
  ]
52
55
  config = config.for_cop(cop)
53
56
  safe_auto_correct = config.fetch("SafeAutoCorrect", true)
54
- autocorrect = if cop.new.support_autocorrect?
57
+ autocorrect = if cop.support_autocorrect?
55
58
  "Yes #{"(Unsafe)" unless safe_auto_correct}"
56
59
  else
57
60
  "No"
@@ -192,8 +195,16 @@ task generate_cops_documentation: :yard_for_generate_documentation do
192
195
 
193
196
  def print_cop_with_doc(cop, config)
194
197
  t = config.for_cop(cop)
195
- non_display_keys = ["Description", "Enabled", "StyleGuide", "Reference", "Safe", "SafeAutoCorrect", "VersionAdded",
196
- "VersionChanged"]
198
+ non_display_keys = [
199
+ "Description",
200
+ "Enabled",
201
+ "StyleGuide",
202
+ "Reference",
203
+ "Safe",
204
+ "SafeAutoCorrect",
205
+ "VersionAdded",
206
+ "VersionChanged",
207
+ ]
197
208
  pars = t.reject { |k| non_display_keys.include?(k) }
198
209
  description = "No documentation"
199
210
  examples_object = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2023-02-03 00:00:00.000000000 Z
14
+ date: 2023-08-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -71,6 +71,7 @@ files:
71
71
  - ".rspec"
72
72
  - ".rubocop.yml"
73
73
  - ".travis.yml"
74
+ - ".yardopts"
74
75
  - CODE_OF_CONDUCT.md
75
76
  - Gemfile
76
77
  - Gemfile.lock
@@ -85,7 +86,7 @@ files:
85
86
  - config/rbi.yml
86
87
  - dev.yml
87
88
  - lib/rubocop-sorbet.rb
88
- - lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb
89
+ - lib/rubocop/cop/sorbet/binding_constant_without_type_alias.rb
89
90
  - lib/rubocop/cop/sorbet/callback_conditionals_binding.rb
90
91
  - lib/rubocop/cop/sorbet/constants_from_strings.rb
91
92
  - lib/rubocop/cop/sorbet/forbid_include_const_literal.rb
@@ -93,7 +94,10 @@ files:
93
94
  - lib/rubocop/cop/sorbet/forbid_t_unsafe.rb
94
95
  - lib/rubocop/cop/sorbet/forbid_t_untyped.rb
95
96
  - lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb
97
+ - lib/rubocop/cop/sorbet/implicit_conversion_method.rb
98
+ - lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb
96
99
  - lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb
100
+ - lib/rubocop/cop/sorbet/obsolete_strict_memoization.rb
97
101
  - lib/rubocop/cop/sorbet/one_ancestor_per_line.rb
98
102
  - lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb
99
103
  - lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb
@@ -148,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
152
  - !ruby/object:Gem::Version
149
153
  version: '0'
150
154
  requirements: []
151
- rubygems_version: 3.3.3
155
+ rubygems_version: 3.4.17
152
156
  signing_key:
153
157
  specification_version: 4
154
158
  summary: Automatic Sorbet code style checking tool.
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubocop"
4
-
5
- module RuboCop
6
- module Cop
7
- module Sorbet
8
- # This cop disallows binding the return value of `T.any`, `T.all`, `T.enum`
9
- # to a constant directly. To bind the value, one must use `T.type_alias`.
10
- #
11
- # @example
12
- #
13
- # # bad
14
- # FooOrBar = T.any(Foo, Bar)
15
- #
16
- # # good
17
- # FooOrBar = T.type_alias { T.any(Foo, Bar) }
18
- class BindingConstantWithoutTypeAlias < RuboCop::Cop::Cop
19
- def_node_matcher(:binding_unaliased_type?, <<-PATTERN)
20
- (casgn _ _ [#not_nil? #not_t_let? #not_dynamic_type_creation_with_block? #not_generic_parameter_decl? #method_needing_aliasing_on_t?])
21
- PATTERN
22
-
23
- def_node_matcher(:using_type_alias?, <<-PATTERN)
24
- (block
25
- (send
26
- (const nil? :T) :type_alias)
27
- _
28
- _
29
- )
30
- PATTERN
31
-
32
- def_node_matcher(:using_deprecated_type_alias_syntax?, <<-PATTERN)
33
- (
34
- send
35
- (const nil? :T)
36
- :type_alias
37
- _
38
- )
39
- PATTERN
40
-
41
- def_node_matcher(:t_let?, <<-PATTERN)
42
- (
43
- send
44
- (const nil? :T)
45
- :let
46
- _
47
- _
48
- )
49
- PATTERN
50
-
51
- def_node_matcher(:dynamic_type_creation_with_block?, <<-PATTERN)
52
- (block
53
- (send
54
- const :new ...)
55
- _
56
- _
57
- )
58
- PATTERN
59
-
60
- def_node_matcher(:generic_parameter_decl_call?, <<-PATTERN)
61
- (
62
- send nil? {:type_template :type_member} ...
63
- )
64
- PATTERN
65
-
66
- def_node_matcher(:generic_parameter_decl_block_call?, <<-PATTERN)
67
- (block
68
- (send nil? {:type_template :type_member} ...) ...
69
- )
70
- PATTERN
71
-
72
- def_node_search(:method_needing_aliasing_on_t?, <<-PATTERN)
73
- (
74
- send
75
- (const nil? :T)
76
- {:any :all :noreturn :class_of :untyped :nilable :self_type :enum :proc}
77
- ...
78
- )
79
- PATTERN
80
-
81
- def not_t_let?(node)
82
- !t_let?(node)
83
- end
84
-
85
- def not_dynamic_type_creation_with_block?(node)
86
- !dynamic_type_creation_with_block?(node)
87
- end
88
-
89
- def not_generic_parameter_decl?(node)
90
- !generic_parameter_decl_call?(node) && !generic_parameter_decl_block_call?(node)
91
- end
92
-
93
- def not_nil?(node)
94
- !node.nil?
95
- end
96
-
97
- def on_casgn(node)
98
- return unless binding_unaliased_type?(node) && !using_type_alias?(node.children[2])
99
- if using_deprecated_type_alias_syntax?(node.children[2])
100
- add_offense(
101
- node.children[2],
102
- message: "It looks like you're using the old `T.type_alias` syntax. " \
103
- "`T.type_alias` now expects a block." \
104
- 'Run Sorbet with the options "--autocorrect --error-white-list=5043" ' \
105
- "to automatically upgrade to the new syntax."
106
- )
107
- return
108
- end
109
- add_offense(
110
- node.children[2],
111
- message: "It looks like you're trying to bind a type to a constant. " \
112
- "To do this, you must alias the type using `T.type_alias`."
113
- )
114
- end
115
-
116
- def autocorrect(node)
117
- lambda do |corrector|
118
- corrector.replace(
119
- node.source_range,
120
- "T.type_alias { #{node.source} }"
121
- )
122
- end
123
- end
124
- end
125
- end
126
- end
127
- end