rubocop-sorbet 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +2 -0
- data/.github/probots.yml +1 -1
- data/.github/stale.yml +20 -0
- data/.gitignore +0 -2
- data/.rspec +3 -0
- data/.rubocop.yml +2 -12
- data/.travis.yml +3 -1
- data/Gemfile +6 -7
- data/Gemfile.lock +26 -41
- data/README.md +64 -6
- data/Rakefile +34 -5
- data/config/default.yml +124 -1
- data/lib/rubocop-sorbet.rb +9 -1
- data/lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb +21 -2
- data/lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb +58 -0
- data/lib/rubocop/cop/sorbet/sigils/enforce_sigil_order.rb +105 -0
- data/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +29 -4
- data/lib/rubocop/cop/sorbet/{allow_incompatible_override.rb → signatures/allow_incompatible_override.rb} +0 -0
- data/lib/rubocop/cop/sorbet/{checked_true_in_signature.rb → signatures/checked_true_in_signature.rb} +3 -8
- data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +135 -0
- data/lib/rubocop/cop/sorbet/{keyword_argument_ordering.rb → signatures/keyword_argument_ordering.rb} +4 -9
- data/lib/rubocop/cop/sorbet/{parameters_ordering_in_signature.rb → signatures/parameters_ordering_in_signature.rb} +17 -14
- data/lib/rubocop/cop/sorbet/{signature_build_order.rb → signatures/signature_build_order.rb} +6 -12
- data/lib/rubocop/cop/sorbet/signatures/signature_cop.rb +28 -0
- data/lib/rubocop/cop/sorbet_cops.rb +22 -0
- data/lib/rubocop/sorbet.rb +15 -0
- data/lib/rubocop/sorbet/inject.rb +20 -0
- data/lib/rubocop/sorbet/version.rb +6 -0
- data/manual/cops.md +29 -0
- data/manual/cops_sorbet.md +340 -0
- data/rubocop-sorbet.gemspec +18 -18
- data/tasks/cops_documentation.rake +317 -0
- metadata +31 -17
- data/lib/rubocop_sorbet.rb +0 -19
data/lib/rubocop/cop/sorbet/{keyword_argument_ordering.rb → signatures/keyword_argument_ordering.rb}
RENAMED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
+
require_relative 'signature_cop'
|
4
5
|
|
5
6
|
module RuboCop
|
6
7
|
module Cop
|
@@ -19,14 +20,8 @@ module RuboCop
|
|
19
20
|
# # good
|
20
21
|
# sig { params(b: String, a: Integer).void }
|
21
22
|
# def foo(b:, a: 1); end
|
22
|
-
class KeywordArgumentOrdering <
|
23
|
-
|
24
|
-
(block (send nil? :sig) (args) ...)
|
25
|
-
PATTERN
|
26
|
-
|
27
|
-
def on_block(node)
|
28
|
-
return unless signature?(node)
|
29
|
-
|
23
|
+
class KeywordArgumentOrdering < SignatureCop
|
24
|
+
def on_signature(node)
|
30
25
|
method_node = node.parent.children[node.sibling_index + 1]
|
31
26
|
return if method_node.nil?
|
32
27
|
method_parameters = method_node.arguments
|
@@ -40,7 +35,7 @@ module RuboCop
|
|
40
35
|
out_of_kwoptarg = false
|
41
36
|
|
42
37
|
parameters.reverse.each do |param|
|
43
|
-
out_of_kwoptarg = true unless param.type == :kwoptarg || param.type == :blockarg
|
38
|
+
out_of_kwoptarg = true unless param.type == :kwoptarg || param.type == :blockarg || param.type == :kwrestarg
|
44
39
|
|
45
40
|
next unless param.type == :kwoptarg && out_of_kwoptarg
|
46
41
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
+
require_relative 'signature_cop'
|
4
5
|
|
5
6
|
module RuboCop
|
6
7
|
module Cop
|
@@ -18,26 +19,16 @@ module RuboCop
|
|
18
19
|
# # good
|
19
20
|
# sig { params(a: Integer, b: String).void }
|
20
21
|
# def foo(a:, b:); end
|
21
|
-
class ParametersOrderingInSignature <
|
22
|
-
def_node_matcher(:signature?, <<-PATTERN)
|
23
|
-
(block (send nil? :sig) (args) ...)
|
24
|
-
PATTERN
|
25
|
-
|
22
|
+
class ParametersOrderingInSignature < SignatureCop
|
26
23
|
def_node_search(:signature_params, <<-PATTERN)
|
27
24
|
(send _ :params ...)
|
28
25
|
PATTERN
|
29
26
|
|
30
|
-
def
|
31
|
-
return unless signature?(node)
|
32
|
-
|
27
|
+
def on_signature(node)
|
33
28
|
sig_params = signature_params(node).first
|
34
|
-
sig_params_order =
|
35
|
-
if sig_params.nil?
|
36
|
-
[]
|
37
|
-
else
|
38
|
-
sig_params.arguments.first.keys.map(&:value)
|
39
|
-
end
|
40
29
|
|
30
|
+
sig_params_order = extract_parameters(sig_params)
|
31
|
+
return if sig_params_order.nil?
|
41
32
|
method_node = node.parent.children[node.sibling_index + 1]
|
42
33
|
return if method_node.nil? || method_node.type != :def
|
43
34
|
method_parameters = method_node.arguments
|
@@ -47,6 +38,18 @@ module RuboCop
|
|
47
38
|
|
48
39
|
private
|
49
40
|
|
41
|
+
def extract_parameters(sig_params)
|
42
|
+
return [] if sig_params.nil?
|
43
|
+
|
44
|
+
arguments = sig_params.arguments.first
|
45
|
+
return arguments.keys.map(&:value) if RuboCop::AST::HashNode === arguments
|
46
|
+
|
47
|
+
add_offense(
|
48
|
+
sig_params,
|
49
|
+
message: "Invalid signature."
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
50
53
|
def check_for_inconsistent_param_ordering(sig_params_order, parameters)
|
51
54
|
parameters.each_with_index do |param, index|
|
52
55
|
param_name = param.children[0]
|
data/lib/rubocop/cop/sorbet/{signature_build_order.rb → signatures/signature_build_order.rb}
RENAMED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
+
require_relative 'signature_cop'
|
4
5
|
|
5
6
|
begin
|
6
7
|
require 'unparser'
|
@@ -11,33 +12,26 @@ end
|
|
11
12
|
module RuboCop
|
12
13
|
module Cop
|
13
14
|
module Sorbet
|
14
|
-
class SignatureBuildOrder <
|
15
|
+
class SignatureBuildOrder < SignatureCop
|
15
16
|
ORDER =
|
16
17
|
[
|
18
|
+
:abstract,
|
19
|
+
:override,
|
20
|
+
:overridable,
|
17
21
|
:type_parameters,
|
18
22
|
:params,
|
19
23
|
:returns,
|
20
24
|
:void,
|
21
|
-
:abstract,
|
22
|
-
:implementation,
|
23
|
-
:override,
|
24
|
-
:overridable,
|
25
25
|
:soft,
|
26
26
|
:checked,
|
27
27
|
:on_failure,
|
28
28
|
].each_with_index.to_h.freeze
|
29
29
|
|
30
|
-
def_node_matcher(:signature?, <<~PATTERN)
|
31
|
-
(block (send nil? :sig) (args) ...)
|
32
|
-
PATTERN
|
33
|
-
|
34
30
|
def_node_search(:root_call, <<~PATTERN)
|
35
31
|
(send nil? {#{ORDER.keys.map(&:inspect).join(' ')}} ...)
|
36
32
|
PATTERN
|
37
33
|
|
38
|
-
def
|
39
|
-
return unless signature?(node)
|
40
|
-
|
34
|
+
def on_signature(node)
|
41
35
|
calls = call_chain(node.children[2]).map(&:method_name)
|
42
36
|
return unless calls.any?
|
43
37
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Sorbet
|
8
|
+
# Abstract cop specific to Sorbet signatures
|
9
|
+
#
|
10
|
+
# You can subclass it to use the `on_signature` trigger and the `signature?` node matcher.
|
11
|
+
class SignatureCop < RuboCop::Cop::Cop
|
12
|
+
@registry = Cop.registry # So we can properly subclass this cop
|
13
|
+
|
14
|
+
def_node_matcher(:signature?, <<~PATTERN)
|
15
|
+
(block (send nil? :sig) (args) ...)
|
16
|
+
PATTERN
|
17
|
+
|
18
|
+
def on_block(node)
|
19
|
+
on_signature(node) if signature?(node)
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_signature(_)
|
23
|
+
# To be defined in subclasses
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'sorbet/binding_constants_without_type_alias'
|
3
|
+
require_relative 'sorbet/constants_from_strings'
|
4
|
+
require_relative 'sorbet/forbid_superclass_const_literal'
|
5
|
+
require_relative 'sorbet/forbid_include_const_literal'
|
6
|
+
require_relative 'sorbet/forbid_untyped_struct_props'
|
7
|
+
|
8
|
+
require_relative 'sorbet/signatures/allow_incompatible_override'
|
9
|
+
require_relative 'sorbet/signatures/checked_true_in_signature'
|
10
|
+
require_relative 'sorbet/signatures/keyword_argument_ordering'
|
11
|
+
require_relative 'sorbet/signatures/parameters_ordering_in_signature'
|
12
|
+
require_relative 'sorbet/signatures/signature_build_order'
|
13
|
+
require_relative 'sorbet/signatures/enforce_signatures'
|
14
|
+
|
15
|
+
require_relative 'sorbet/sigils/valid_sigil'
|
16
|
+
require_relative 'sorbet/sigils/has_sigil'
|
17
|
+
require_relative 'sorbet/sigils/ignore_sigil'
|
18
|
+
require_relative 'sorbet/sigils/false_sigil'
|
19
|
+
require_relative 'sorbet/sigils/true_sigil'
|
20
|
+
require_relative 'sorbet/sigils/strict_sigil'
|
21
|
+
require_relative 'sorbet/sigils/strong_sigil'
|
22
|
+
require_relative 'sorbet/sigils/enforce_sigil_order'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rubocop/sorbet/version"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Sorbet
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
10
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
11
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
12
|
+
|
13
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
+
# See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
|
+
module RuboCop
|
6
|
+
module Sorbet
|
7
|
+
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
8
|
+
# bit of our configuration.
|
9
|
+
module Inject
|
10
|
+
def self.defaults!
|
11
|
+
path = CONFIG_DEFAULT.to_s
|
12
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
13
|
+
config = Config.new(hash, path).tap(&:make_excludes_absolute)
|
14
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
15
|
+
config = ConfigLoader.merge_with_default(config, path)
|
16
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/manual/cops.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
## Available cops
|
2
|
+
|
3
|
+
In the following section you find all available cops:
|
4
|
+
|
5
|
+
<!-- START_COP_LIST -->
|
6
|
+
#### Department [Sorbet](cops_sorbet.md)
|
7
|
+
|
8
|
+
* [Sorbet/AllowIncompatibleOverride](cops_sorbet.md#sorbetallowincompatibleoverride)
|
9
|
+
* [Sorbet/BindingConstantWithoutTypeAlias](cops_sorbet.md#sorbetbindingconstantwithouttypealias)
|
10
|
+
* [Sorbet/CheckedTrueInSignature](cops_sorbet.md#sorbetcheckedtrueinsignature)
|
11
|
+
* [Sorbet/ConstantsFromStrings](cops_sorbet.md#sorbetconstantsfromstrings)
|
12
|
+
* [Sorbet/EnforceSigilOrder](cops_sorbet.md#sorbetenforcesigilorder)
|
13
|
+
* [Sorbet/EnforceSignatures](cops_sorbet.md#sorbetenforcesignatures)
|
14
|
+
* [Sorbet/FalseSigil](cops_sorbet.md#sorbetfalsesigil)
|
15
|
+
* [Sorbet/ForbidIncludeConstLiteral](cops_sorbet.md#sorbetforbidincludeconstliteral)
|
16
|
+
* [Sorbet/ForbidSuperclassConstLiteral](cops_sorbet.md#sorbetforbidsuperclassconstliteral)
|
17
|
+
* [Sorbet/ForbidUntypedStructProps](cops_sorbet.md#sorbetforbiduntypedstructprops)
|
18
|
+
* [Sorbet/HasSigil](cops_sorbet.md#sorbethassigil)
|
19
|
+
* [Sorbet/IgnoreSigil](cops_sorbet.md#sorbetignoresigil)
|
20
|
+
* [Sorbet/KeywordArgumentOrdering](cops_sorbet.md#sorbetkeywordargumentordering)
|
21
|
+
* [Sorbet/ParametersOrderingInSignature](cops_sorbet.md#sorbetparametersorderinginsignature)
|
22
|
+
* [Sorbet/SignatureBuildOrder](cops_sorbet.md#sorbetsignaturebuildorder)
|
23
|
+
* [Sorbet/SignatureCop](cops_sorbet.md#sorbetsignaturecop)
|
24
|
+
* [Sorbet/StrictSigil](cops_sorbet.md#sorbetstrictsigil)
|
25
|
+
* [Sorbet/StrongSigil](cops_sorbet.md#sorbetstrongsigil)
|
26
|
+
* [Sorbet/TrueSigil](cops_sorbet.md#sorbettruesigil)
|
27
|
+
* [Sorbet/ValidSigil](cops_sorbet.md#sorbetvalidsigil)
|
28
|
+
|
29
|
+
<!-- END_COP_LIST -->
|
@@ -0,0 +1,340 @@
|
|
1
|
+
# Sorbet
|
2
|
+
|
3
|
+
## Sorbet/AllowIncompatibleOverride
|
4
|
+
|
5
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
6
|
+
--- | --- | --- | --- | ---
|
7
|
+
Enabled | Yes | No | 0.2.0 | -
|
8
|
+
|
9
|
+
This cop disallows using `.override(allow_incompatible: true)`.
|
10
|
+
Using `allow_incompatible` suggests a violation of the Liskov
|
11
|
+
Substitution Principle, meaning that a subclass is not a valid
|
12
|
+
subtype of it's superclass. This Cop prevents these design smells
|
13
|
+
from occurring.
|
14
|
+
|
15
|
+
### Examples
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# bad
|
19
|
+
sig.override(allow_incompatible: true)
|
20
|
+
|
21
|
+
# good
|
22
|
+
sig.override
|
23
|
+
```
|
24
|
+
|
25
|
+
## Sorbet/BindingConstantWithoutTypeAlias
|
26
|
+
|
27
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
28
|
+
--- | --- | --- | --- | ---
|
29
|
+
Enabled | Yes | Yes | 0.2.0 | -
|
30
|
+
|
31
|
+
This cop disallows binding the return value of `T.any`, `T.all`, `T.enum`
|
32
|
+
to a constant directly. To bind the value, one must use `T.type_alias`.
|
33
|
+
|
34
|
+
### Examples
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# bad
|
38
|
+
FooOrBar = T.any(Foo, Bar)
|
39
|
+
|
40
|
+
# good
|
41
|
+
FooOrBar = T.type_alias { T.any(Foo, Bar) }
|
42
|
+
```
|
43
|
+
|
44
|
+
## Sorbet/CheckedTrueInSignature
|
45
|
+
|
46
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
47
|
+
--- | --- | --- | --- | ---
|
48
|
+
Enabled | Yes | No | 0.2.0 | -
|
49
|
+
|
50
|
+
This cop disallows the usage of `checked(true)`. This usage could cause
|
51
|
+
confusion; it could lead some people to believe that a method would be checked
|
52
|
+
even if runtime checks have not been enabled on the class or globally.
|
53
|
+
Additionally, in the event where checks are enabled, `checked(true)` would
|
54
|
+
be redundant; only `checked(false)` or `soft` would change the behaviour.
|
55
|
+
|
56
|
+
### Examples
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# bad
|
60
|
+
sig { void.checked(true) }
|
61
|
+
|
62
|
+
# good
|
63
|
+
sig { void }
|
64
|
+
```
|
65
|
+
|
66
|
+
## Sorbet/ConstantsFromStrings
|
67
|
+
|
68
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
69
|
+
--- | --- | --- | --- | ---
|
70
|
+
Enabled | Yes | No | 0.2.0 | -
|
71
|
+
|
72
|
+
This cop disallows the calls that are used to get constants fom Strings
|
73
|
+
such as +constantize+, +const_get+, and +constants+.
|
74
|
+
|
75
|
+
The goal of this cop is to make the code easier to statically analyze,
|
76
|
+
more IDE-friendly, and more predictable. It leads to code that clearly
|
77
|
+
expresses which values the constant can have.
|
78
|
+
|
79
|
+
### Examples
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# bad
|
83
|
+
class_name.constantize
|
84
|
+
|
85
|
+
# bad
|
86
|
+
constants.detect { |c| c.name == "User" }
|
87
|
+
|
88
|
+
# bad
|
89
|
+
const_get(class_name)
|
90
|
+
|
91
|
+
# good
|
92
|
+
case class_name
|
93
|
+
when "User"
|
94
|
+
User
|
95
|
+
else
|
96
|
+
raise ArgumentError
|
97
|
+
end
|
98
|
+
|
99
|
+
# good
|
100
|
+
{ "User" => User }.fetch(class_name)
|
101
|
+
```
|
102
|
+
|
103
|
+
## Sorbet/EnforceSigilOrder
|
104
|
+
|
105
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
106
|
+
--- | --- | --- | --- | ---
|
107
|
+
Enabled | Yes | Yes | 0.3.4 | -
|
108
|
+
|
109
|
+
This cop checks that the Sorbet sigil comes as the first magic comment in the file.
|
110
|
+
|
111
|
+
The expected order for magic comments is: typed, (en)?coding, warn_indent then frozen_string_literal.
|
112
|
+
|
113
|
+
For example, the following bad ordering:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# frozen_string_literal: true
|
117
|
+
# typed: true
|
118
|
+
class Foo; end
|
119
|
+
```
|
120
|
+
|
121
|
+
Will be corrected as:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# typed: true
|
125
|
+
# frozen_string_literal: true
|
126
|
+
class Foo; end
|
127
|
+
```
|
128
|
+
|
129
|
+
Only `typed`, `(en)?coding`, `warn_indent` and `frozen_string_literal` magic comments are considered,
|
130
|
+
other comments or magic comments are left in the same place.
|
131
|
+
|
132
|
+
## Sorbet/EnforceSignatures
|
133
|
+
|
134
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
135
|
+
--- | --- | --- | --- | ---
|
136
|
+
Disabled | Yes | Yes | 0.3.4 | -
|
137
|
+
|
138
|
+
This cop checks that every method definition and attribute accessor has a Sorbet signature.
|
139
|
+
|
140
|
+
It also suggest an autocorrect with placeholders so the following code:
|
141
|
+
|
142
|
+
```
|
143
|
+
def foo(a, b, c); end
|
144
|
+
```
|
145
|
+
|
146
|
+
Will be corrected as:
|
147
|
+
|
148
|
+
```
|
149
|
+
sig { params(a: T.untyped, b: T.untyped, c: T.untyped).returns(T.untyped)
|
150
|
+
def foo(a, b, c); end
|
151
|
+
```
|
152
|
+
|
153
|
+
You can configure the placeholders used by changing the following options:
|
154
|
+
|
155
|
+
* `ParameterTypePlaceholder`: placeholders used for parameter types (default: 'T.untyped')
|
156
|
+
* `ReturnTypePlaceholder`: placeholders used for return types (default: 'T.untyped')
|
157
|
+
|
158
|
+
## Sorbet/FalseSigil
|
159
|
+
|
160
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
161
|
+
--- | --- | --- | --- | ---
|
162
|
+
Enabled | Yes | Yes | 0.3.3 | -
|
163
|
+
|
164
|
+
This cop makes the Sorbet `false` sigil mandatory in all files.
|
165
|
+
|
166
|
+
### Configurable attributes
|
167
|
+
|
168
|
+
Name | Default value | Configurable values
|
169
|
+
--- | --- | ---
|
170
|
+
SuggestedStrictness | `true` | Boolean
|
171
|
+
Include | `**/*.rb`, `**/*.rbi`, `**/*.rake`, `**/*.ru` | Array
|
172
|
+
Exclude | `bin/**/*`, `db/**/*.rb`, `script/**/*` | Array
|
173
|
+
|
174
|
+
## Sorbet/ForbidIncludeConstLiteral
|
175
|
+
|
176
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
177
|
+
--- | --- | --- | --- | ---
|
178
|
+
Enabled | Yes | Yes | 0.2.0 | -
|
179
|
+
|
180
|
+
No documentation
|
181
|
+
|
182
|
+
## Sorbet/ForbidSuperclassConstLiteral
|
183
|
+
|
184
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
185
|
+
--- | --- | --- | --- | ---
|
186
|
+
Enabled | Yes | Yes | 0.2.0 | -
|
187
|
+
|
188
|
+
No documentation
|
189
|
+
|
190
|
+
## Sorbet/ForbidUntypedStructProps
|
191
|
+
|
192
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
193
|
+
--- | --- | --- | --- | ---
|
194
|
+
Enabled | Yes | No | 0.3.8 | -
|
195
|
+
|
196
|
+
This cop disallows use of `T.untyped` or `T.nilable(T.untyped)`
|
197
|
+
as a prop type for `T::Struct`.
|
198
|
+
|
199
|
+
### Examples
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
# bad
|
203
|
+
class SomeClass
|
204
|
+
const :foo, T.untyped
|
205
|
+
prop :bar, T.nilable(T.untyped)
|
206
|
+
end
|
207
|
+
|
208
|
+
# good
|
209
|
+
class SomeClass
|
210
|
+
const :foo, Integer
|
211
|
+
prop :bar, T.nilable(String)
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
## Sorbet/HasSigil
|
216
|
+
|
217
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
218
|
+
--- | --- | --- | --- | ---
|
219
|
+
Disabled | Yes | Yes | 0.3.3 | -
|
220
|
+
|
221
|
+
This cop makes the Sorbet typed sigil mandatory in all files.
|
222
|
+
|
223
|
+
Options:
|
224
|
+
|
225
|
+
* `SuggestedStrictness`: Sorbet strictness level suggested in offense messages (default: 'false')
|
226
|
+
* `MinimumStrictness`: If set, make offense if the strictness level in the file is below this one
|
227
|
+
|
228
|
+
If a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
|
229
|
+
|
230
|
+
## Sorbet/IgnoreSigil
|
231
|
+
|
232
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
233
|
+
--- | --- | --- | --- | ---
|
234
|
+
Disabled | Yes | Yes | 0.3.3 | -
|
235
|
+
|
236
|
+
This cop makes the Sorbet `ignore` sigil mandatory in all files.
|
237
|
+
|
238
|
+
## Sorbet/KeywordArgumentOrdering
|
239
|
+
|
240
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
241
|
+
--- | --- | --- | --- | ---
|
242
|
+
Enabled | Yes | No | 0.2.0 | -
|
243
|
+
|
244
|
+
This cop checks for the ordering of keyword arguments required by
|
245
|
+
sorbet-runtime. The ordering requires that all keyword arguments
|
246
|
+
are at the end of the parameters list, and all keyword arguments
|
247
|
+
with a default value must be after those without default values.
|
248
|
+
|
249
|
+
### Examples
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
# bad
|
253
|
+
sig { params(a: Integer, b: String).void }
|
254
|
+
def foo(a: 1, b:); end
|
255
|
+
|
256
|
+
# good
|
257
|
+
sig { params(b: String, a: Integer).void }
|
258
|
+
def foo(b:, a: 1); end
|
259
|
+
```
|
260
|
+
|
261
|
+
## Sorbet/ParametersOrderingInSignature
|
262
|
+
|
263
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
264
|
+
--- | --- | --- | --- | ---
|
265
|
+
Enabled | Yes | No | 0.2.0 | -
|
266
|
+
|
267
|
+
This cop checks for inconsistent ordering of parameters between the
|
268
|
+
signature and the method definition. The sorbet-runtime gem raises
|
269
|
+
when such inconsistency occurs.
|
270
|
+
|
271
|
+
### Examples
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
# bad
|
275
|
+
sig { params(a: Integer, b: String).void }
|
276
|
+
def foo(b:, a:); end
|
277
|
+
|
278
|
+
# good
|
279
|
+
sig { params(a: Integer, b: String).void }
|
280
|
+
def foo(a:, b:); end
|
281
|
+
```
|
282
|
+
|
283
|
+
## Sorbet/SignatureBuildOrder
|
284
|
+
|
285
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
286
|
+
--- | --- | --- | --- | ---
|
287
|
+
Enabled | Yes | Yes | 0.3.0 | -
|
288
|
+
|
289
|
+
No documentation
|
290
|
+
|
291
|
+
## Sorbet/SignatureCop
|
292
|
+
|
293
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
294
|
+
--- | --- | --- | --- | ---
|
295
|
+
Enabled | Yes | No | - | -
|
296
|
+
|
297
|
+
Abstract cop specific to Sorbet signatures
|
298
|
+
|
299
|
+
You can subclass it to use the `on_signature` trigger and the `signature?` node matcher.
|
300
|
+
|
301
|
+
## Sorbet/StrictSigil
|
302
|
+
|
303
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
304
|
+
--- | --- | --- | --- | ---
|
305
|
+
Disabled | Yes | Yes | 0.3.3 | -
|
306
|
+
|
307
|
+
This cop makes the Sorbet `strict` sigil mandatory in all files.
|
308
|
+
|
309
|
+
## Sorbet/StrongSigil
|
310
|
+
|
311
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
312
|
+
--- | --- | --- | --- | ---
|
313
|
+
Disabled | Yes | Yes | 0.3.3 | -
|
314
|
+
|
315
|
+
This cop makes the Sorbet `strong` sigil mandatory in all files.
|
316
|
+
|
317
|
+
## Sorbet/TrueSigil
|
318
|
+
|
319
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
320
|
+
--- | --- | --- | --- | ---
|
321
|
+
Disabled | Yes | Yes | 0.3.3 | -
|
322
|
+
|
323
|
+
This cop makes the Sorbet `true` sigil mandatory in all files.
|
324
|
+
|
325
|
+
## Sorbet/ValidSigil
|
326
|
+
|
327
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
328
|
+
--- | --- | --- | --- | ---
|
329
|
+
Enabled | Yes | Yes | 0.3.3 | -
|
330
|
+
|
331
|
+
This cop checks that every Ruby file contains a valid Sorbet sigil.
|
332
|
+
Adapted from: https://gist.github.com/clarkdave/85aca4e16f33fd52aceb6a0a29936e52
|
333
|
+
|
334
|
+
Options:
|
335
|
+
|
336
|
+
* `RequireSigilOnAllFiles`: make offense if the Sorbet typed is not found in the file (default: false)
|
337
|
+
* `SuggestedStrictness`: Sorbet strictness level suggested in offense messages (default: 'false')
|
338
|
+
* `MinimumStrictness`: If set, make offense if the strictness level in the file is below this one
|
339
|
+
|
340
|
+
If a `MinimumStrictness` level is specified, it will be used in offense messages and autocorrect.
|