rubocop-sorbet 0.8.7 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a44258e5997d8d76d11a35e921aaa0312daaadb5d159a2cf8425213baabdc1e
4
- data.tar.gz: de2a3ed4f84838094981247acce55eb873c620fbcea454ed145c174008734cd7
3
+ metadata.gz: '048bbf857fc0e733a27de48597f476ca59d22efb8a8eded11de5252f604b5804'
4
+ data.tar.gz: 39d1335d326dc98b38041d5bfe66547d1398c10a6c1556f31bb22d5698db5bd9
5
5
  SHA512:
6
- metadata.gz: af324556ad44f2eda2a26ba9cd006a92af766c8cc46872d761f1db769f9aa0b528d4d828b7d6a5e335a557cbce277f271da5a295f9c7d4a74f7babda35be6106
7
- data.tar.gz: a927134808ef57e9ddaa7fb0798d61e2e00011b68c86f429e8c53d12f693072ef69368657963e587165693d84f0d814abdc2b1ff29531aa58fa36fb9ad849ae1
6
+ metadata.gz: feda39cdafbc2c3a06138bc9e34d6900423fefcbd3906e7b9104f725f15c3469e3f9e8aa03148ba12b4e2ee5fd0d4f3b54930810d8ed1715ba31881748a9a0a1
7
+ data.tar.gz: 5c626f9c2f15436297415e01dad6f758452e79289ede0ae74d22a3cb39fd77b2188598e199f123d263a99ffb183208ee83fff175f700cc44be40e559ef4031a6
@@ -11,7 +11,7 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- ruby: ["3.1", "3.2", "3.3"]
14
+ ruby: ["3.1", "3.2", "3.3", "3.4"]
15
15
  name: Test Ruby ${{ matrix.ruby }}
16
16
  steps:
17
17
  - uses: actions/checkout@v4
@@ -42,5 +42,7 @@ jobs:
42
42
  bin/rubocop --config config/default.yml config -r rubocop-sorbet
43
43
  - name: Lint Ruby files
44
44
  run: bin/rubocop
45
+ - name: Verify cop examples
46
+ run: bundle exec rake documentation_syntax_check
45
47
  - name: Verify documentation is up to date
46
48
  run: bundle exec rake generate_cops_documentation
data/.rubocop.yml CHANGED
@@ -24,3 +24,18 @@ Layout/LineLength:
24
24
 
25
25
  InternalAffairs/UndefinedConfig:
26
26
  Enabled: false # Bug in implementation fails to find our configs
27
+
28
+ InternalAffairs/OnSendWithoutOnCSend:
29
+ Exclude:
30
+ # Cases where we don't expect a conditional send
31
+ - lib/rubocop/cop/sorbet/callback_conditionals_binding.rb
32
+ - lib/rubocop/cop/sorbet/forbid_include_const_literal.rb
33
+ - lib/rubocop/cop/sorbet/forbid_t_struct.rb
34
+ - lib/rubocop/cop/sorbet/forbid_t_untyped.rb
35
+ - lib/rubocop/cop/sorbet/implicit_conversion_method.rb
36
+ - lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb
37
+ - lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb
38
+ - lib/rubocop/cop/sorbet/refinement.rb
39
+ - lib/rubocop/cop/sorbet/signatures/allow_incompatible_override.rb
40
+ - lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb
41
+ - lib/rubocop/cop/sorbet/t_enum/forbid_comparable_t_enum.rb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.3.3
1
+ 3.4.1
data/Gemfile.lock CHANGED
@@ -1,36 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.8.7)
4
+ rubocop-sorbet (0.8.9)
5
5
  rubocop (>= 1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.2)
11
- debug (1.9.2)
11
+ date (3.4.1)
12
+ debug (1.10.0)
12
13
  irb (~> 1.10)
13
14
  reline (>= 0.3.8)
14
15
  diff-lcs (1.5.1)
15
- io-console (0.7.2)
16
- irb (1.12.0)
17
- rdoc
16
+ io-console (0.8.0)
17
+ irb (1.14.3)
18
+ rdoc (>= 4.0.0)
18
19
  reline (>= 0.4.2)
19
- json (2.7.2)
20
- language_server-protocol (3.17.0.3)
20
+ json (2.10.1)
21
+ language_server-protocol (3.17.0.4)
22
+ lint_roller (1.1.0)
21
23
  parallel (1.26.3)
22
- parser (3.3.5.0)
24
+ parser (3.3.7.1)
23
25
  ast (~> 2.4.1)
24
26
  racc
25
- psych (5.1.2)
27
+ psych (5.2.2)
28
+ date
26
29
  stringio
27
30
  racc (1.8.1)
28
31
  rainbow (3.1.1)
29
32
  rake (13.2.1)
30
- rdoc (6.6.3.1)
33
+ rdoc (6.10.0)
31
34
  psych (>= 4.0.0)
32
- regexp_parser (2.9.2)
33
- reline (0.5.1)
35
+ regexp_parser (2.10.0)
36
+ reline (0.6.0)
34
37
  io-console (~> 0.5)
35
38
  rspec (3.13.0)
36
39
  rspec-core (~> 3.13.0)
@@ -45,23 +48,26 @@ GEM
45
48
  diff-lcs (>= 1.2.0, < 2.0)
46
49
  rspec-support (~> 3.13.0)
47
50
  rspec-support (3.13.1)
48
- rubocop (1.67.0)
51
+ rubocop (1.72.1)
49
52
  json (~> 2.3)
50
- language_server-protocol (>= 3.17.0)
53
+ language_server-protocol (~> 3.17.0.2)
54
+ lint_roller (~> 1.1.0)
51
55
  parallel (~> 1.10)
52
56
  parser (>= 3.3.0.2)
53
57
  rainbow (>= 2.2.2, < 4.0)
54
- regexp_parser (>= 2.4, < 3.0)
55
- rubocop-ast (>= 1.32.2, < 2.0)
58
+ regexp_parser (>= 2.9.3, < 3.0)
59
+ rubocop-ast (>= 1.38.0, < 2.0)
56
60
  ruby-progressbar (~> 1.7)
57
- unicode-display_width (>= 2.4.0, < 3.0)
58
- rubocop-ast (1.32.3)
61
+ unicode-display_width (>= 2.4.0, < 4.0)
62
+ rubocop-ast (1.38.0)
59
63
  parser (>= 3.3.1.0)
60
64
  rubocop-shopify (2.15.1)
61
65
  rubocop (~> 1.51)
62
66
  ruby-progressbar (1.13.0)
63
- stringio (3.1.0)
64
- unicode-display_width (2.6.0)
67
+ stringio (3.1.2)
68
+ unicode-display_width (3.1.4)
69
+ unicode-emoji (~> 4.0, >= 4.0.4)
70
+ unicode-emoji (4.0.4)
65
71
  yard (0.9.37)
66
72
 
67
73
  PLATFORMS
data/config/default.yml CHANGED
@@ -110,6 +110,13 @@ Sorbet/ForbidSuperclassConstLiteral:
110
110
  Exclude:
111
111
  - db/migrate/*.rb
112
112
 
113
+ Sorbet/ForbidTEnum:
114
+ Description: 'Forbid usage of T::Enum.'
115
+ Enabled: false
116
+ VersionAdded: <<next>>
117
+ VersionChanged: <<next>>
118
+ Safe: false
119
+
113
120
  Sorbet/ForbidTStruct:
114
121
  Description: 'Forbid usage of T::Struct.'
115
122
  Enabled: false
@@ -252,6 +259,7 @@ Sorbet/SingleLineRbiClassModuleDefinitions:
252
259
  Sorbet/StrictSigil:
253
260
  Description: 'All files must be at least at strictness `strict`.'
254
261
  Enabled: false
262
+ Safe: false
255
263
  SuggestedStrictness: "strict"
256
264
  VersionAdded: 0.3.3
257
265
  Include:
data/config/rbi.yml CHANGED
@@ -103,11 +103,11 @@ Layout/InitialIndentation:
103
103
 
104
104
  Layout/LeadingCommentSpace:
105
105
  Enabled: true
106
+ AllowRBSInlineAnnotation: true
106
107
 
107
108
  Layout/LeadingEmptyLines:
108
109
  Enabled: true
109
110
 
110
- # TODO: make Tapioca break long lines?
111
111
  Layout/LineLength:
112
112
  Enabled: false
113
113
 
@@ -6,6 +6,7 @@ module RuboCop
6
6
  # Ensures that callback conditionals are bound to the right type
7
7
  # so that they are type checked properly.
8
8
  #
9
+ # @safety
9
10
  # Auto-correction is unsafe because other libraries define similar style callbacks as Rails, but don't always need
10
11
  # binding to the attached class. Auto-correcting those usages can lead to false positives and auto-correction
11
12
  # introduces new typing errors.
@@ -50,14 +50,14 @@ module RuboCop
50
50
  private
51
51
 
52
52
  def neither_const_nor_self?(node)
53
- !node.const_type? && !node.self_type?
53
+ !node.type?(:const, :self)
54
54
  end
55
55
 
56
56
  # Returns true if the node is within a module declaration that is not anonymous.
57
57
  def within_onymous_module?(node)
58
58
  parent = node.parent
59
- parent = parent.parent while parent&.begin_type? || parent&.block_type?
60
- parent && (parent.module_type? || parent.class_type? || parent.sclass_type?)
59
+ parent = parent.parent while parent&.type?(:begin, :block)
60
+ parent&.type?(:module, :class, :sclass)
61
61
  end
62
62
  end
63
63
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Sorbet
8
+ # Disallow using `T::Enum`.
9
+ #
10
+ # @example
11
+ #
12
+ # # bad
13
+ # class MyEnum < T::Enum
14
+ # enums do
15
+ # A = new
16
+ # B = new
17
+ # end
18
+ # end
19
+ #
20
+ # # good
21
+ # class MyEnum
22
+ # A = "a"
23
+ # B = "b"
24
+ # C = "c"
25
+ # end
26
+ class ForbidTEnum < RuboCop::Cop::Base
27
+ MSG = "Using `T::Enum` is deprecated in this codebase."
28
+
29
+ # @!method t_enum?(node)
30
+ def_node_matcher(:t_enum?, <<~PATTERN)
31
+ (const (const {nil? cbase} :T) :Enum)
32
+ PATTERN
33
+
34
+ def on_class(node)
35
+ add_offense(node) if t_enum?(node.parent_class)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -43,8 +43,8 @@ module RuboCop
43
43
 
44
44
  RESTRICT_ON_SEND = [:include, :prepend, :extend].freeze
45
45
 
46
- MSG_STRUCT = "Using `T::Struct` or its variants is deprecated."
47
- MSG_PROPS = "Using `T::Props` or its variants is deprecated."
46
+ MSG_STRUCT = "Using `T::Struct` or its variants is deprecated in this codebase."
47
+ MSG_PROPS = "Using `T::Props` or its variants is deprecated in this codebase."
48
48
 
49
49
  # This class walks down the class body of a T::Struct and collects all the properties that will need to be
50
50
  # translated into `attr_reader` and `attr_accessor` methods.
@@ -24,6 +24,7 @@ module RuboCop
24
24
  def on_send(node)
25
25
  add_offense(node) if t_unsafe?(node)
26
26
  end
27
+ alias_method :on_csend, :on_send
27
28
  end
28
29
  end
29
30
  end
@@ -13,6 +13,7 @@ module RuboCop
13
13
  # * `SuggestedStrictness`: Sorbet strictness level suggested in offense messages (default: 'false')
14
14
  # * `MinimumStrictness`: If set, make offense if the strictness level in the file is below this one
15
15
  #
16
+ # If a `SuggestedStrictness` level is specified, it will be used in autocorrect.
16
17
  # If a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
17
18
  class HasSigil < ValidSigil
18
19
  def require_sigil_on_all_files?
@@ -7,6 +7,21 @@ module RuboCop
7
7
  module Cop
8
8
  module Sorbet
9
9
  # Makes the Sorbet `strict` sigil mandatory in all files.
10
+ #
11
+ # @safety
12
+ # This cop is unsafe because Sorbet sigils may not exist yet when it is run.
13
+ #
14
+ # @example
15
+ #
16
+ # # bad
17
+ # # typed: true
18
+ #
19
+ # # bad
20
+ # # typed: false
21
+ #
22
+ # # good
23
+ # # typed: strict
24
+ #
10
25
  class StrictSigil < HasSigil
11
26
  def minimum_strictness
12
27
  "strict"
@@ -16,6 +16,7 @@ module RuboCop
16
16
  # * `ExactStrictness`: If set, make offense if the strictness level in the file is different than this one
17
17
  #
18
18
  # If an `ExactStrictness` level is specified, it will be used in offense messages and autocorrect.
19
+ # If a `SuggestedStrictness` level is specified, it will be used in autocorrect.
19
20
  # Otherwise, if a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
20
21
  class ValidSigil < RuboCop::Cop::Base
21
22
  extend AutoCorrector
@@ -35,7 +35,7 @@ module RuboCop
35
35
  out_of_kwoptarg = false
36
36
 
37
37
  parameters.reverse.each do |param|
38
- out_of_kwoptarg = true unless param.kwoptarg_type? || param.blockarg_type? || param.kwrestarg_type?
38
+ out_of_kwoptarg = true unless param.type?(:kwoptarg, :blockarg, :kwrestarg)
39
39
 
40
40
  next unless param.kwoptarg_type? && out_of_kwoptarg
41
41
 
@@ -35,7 +35,7 @@ module RuboCop
35
35
 
36
36
  # @!method checked_tests(node)
37
37
  def_node_search(:checked_tests, <<~PATTERN)
38
- ({csend send} _ :checked (sym :tests))
38
+ (call _ :checked (sym :tests))
39
39
  PATTERN
40
40
 
41
41
  MESSAGE =
@@ -12,6 +12,7 @@ require_relative "sorbet/forbid_type_aliased_shapes"
12
12
  require_relative "sorbet/forbid_untyped_struct_props"
13
13
  require_relative "sorbet/implicit_conversion_method"
14
14
  require_relative "sorbet/callback_conditionals_binding"
15
+ require_relative "sorbet/forbid_t_enum"
15
16
  require_relative "sorbet/forbid_t_struct"
16
17
  require_relative "sorbet/forbid_t_unsafe"
17
18
  require_relative "sorbet/forbid_t_untyped"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Sorbet
5
- VERSION = "0.8.7"
5
+ VERSION = "0.8.9"
6
6
  end
7
7
  end
data/manual/cops.md CHANGED
@@ -21,6 +21,7 @@ In the following section you find all available cops:
21
21
  * [Sorbet/ForbidIncludeConstLiteral](cops_sorbet.md#sorbetforbidincludeconstliteral)
22
22
  * [Sorbet/ForbidRBIOutsideOfAllowedPaths](cops_sorbet.md#sorbetforbidrbioutsideofallowedpaths)
23
23
  * [Sorbet/ForbidSuperclassConstLiteral](cops_sorbet.md#sorbetforbidsuperclassconstliteral)
24
+ * [Sorbet/ForbidTEnum](cops_sorbet.md#sorbetforbidtenum)
24
25
  * [Sorbet/ForbidTStruct](cops_sorbet.md#sorbetforbidtstruct)
25
26
  * [Sorbet/ForbidTUnsafe](cops_sorbet.md#sorbetforbidtunsafe)
26
27
  * [Sorbet/ForbidTUntyped](cops_sorbet.md#sorbetforbidtuntyped)
@@ -448,6 +448,33 @@ Name | Default value | Configurable values
448
448
  --- | --- | ---
449
449
  Exclude | `db/migrate/*.rb` | Array
450
450
 
451
+ ## Sorbet/ForbidTEnum
452
+
453
+ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
454
+ --- | --- | --- | --- | ---
455
+ Disabled | No | No | <<next>> | <<next>>
456
+
457
+ Disallow using `T::Enum`.
458
+
459
+ ### Examples
460
+
461
+ ```ruby
462
+ # bad
463
+ class MyEnum < T::Enum
464
+ enums do
465
+ A = new
466
+ B = new
467
+ end
468
+ end
469
+
470
+ # good
471
+ class MyEnum
472
+ A = "a"
473
+ B = "b"
474
+ C = "c"
475
+ end
476
+ ```
477
+
451
478
  ## Sorbet/ForbidTStruct
452
479
 
453
480
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
@@ -588,6 +615,7 @@ Options:
588
615
  * `SuggestedStrictness`: Sorbet strictness level suggested in offense messages (default: 'false')
589
616
  * `MinimumStrictness`: If set, make offense if the strictness level in the file is below this one
590
617
 
618
+ If a `SuggestedStrictness` level is specified, it will be used in autocorrect.
591
619
  If a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
592
620
 
593
621
  ### Configurable attributes
@@ -860,10 +888,23 @@ Include | `**/*.rbi` | Array
860
888
 
861
889
  Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
862
890
  --- | --- | --- | --- | ---
863
- Disabled | Yes | Yes | 0.3.3 | -
891
+ Disabled | No | Yes | 0.3.3 | -
864
892
 
865
893
  Makes the Sorbet `strict` sigil mandatory in all files.
866
894
 
895
+ ### Examples
896
+
897
+ ```ruby
898
+ # bad
899
+ # typed: true
900
+
901
+ # bad
902
+ # typed: false
903
+
904
+ # good
905
+ # typed: strict
906
+ ```
907
+
867
908
  ### Configurable attributes
868
909
 
869
910
  Name | Default value | Configurable values
@@ -970,6 +1011,7 @@ Options:
970
1011
  * `ExactStrictness`: If set, make offense if the strictness level in the file is different than this one
971
1012
 
972
1013
  If an `ExactStrictness` level is specified, it will be used in offense messages and autocorrect.
1014
+ If a `SuggestedStrictness` level is specified, it will be used in autocorrect.
973
1015
  Otherwise, if a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
974
1016
 
975
1017
  ### Configurable attributes
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
8
8
  - Alan Wu
9
9
  - Alexandre Terrasa
10
10
  - Peter Zhu
11
- autorequire:
12
11
  bindir: exe
13
12
  cert_chain: []
14
- date: 2024-11-01 00:00:00.000000000 Z
13
+ date: 2025-02-20 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rubocop
@@ -27,7 +26,6 @@ dependencies:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
28
  version: '1'
30
- description:
31
29
  email:
32
30
  - ruby@shopify.com
33
31
  executables: []
@@ -68,6 +66,7 @@ files:
68
66
  - lib/rubocop/cop/sorbet/constants_from_strings.rb
69
67
  - lib/rubocop/cop/sorbet/forbid_include_const_literal.rb
70
68
  - lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
69
+ - lib/rubocop/cop/sorbet/forbid_t_enum.rb
71
70
  - lib/rubocop/cop/sorbet/forbid_t_struct.rb
72
71
  - lib/rubocop/cop/sorbet/forbid_t_unsafe.rb
73
72
  - lib/rubocop/cop/sorbet/forbid_t_untyped.rb
@@ -122,7 +121,6 @@ metadata:
122
121
  allowed_push_host: https://rubygems.org
123
122
  homepage_uri: https://github.com/shopify/rubocop-sorbet
124
123
  source_code_uri: https://github.com/shopify/rubocop-sorbet
125
- post_install_message:
126
124
  rdoc_options: []
127
125
  require_paths:
128
126
  - lib
@@ -137,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
135
  - !ruby/object:Gem::Version
138
136
  version: '0'
139
137
  requirements: []
140
- rubygems_version: 3.5.22
141
- signing_key:
138
+ rubygems_version: 3.6.3
142
139
  specification_version: 4
143
140
  summary: Automatic Sorbet code style checking tool.
144
141
  test_files: []