rubocop-sorbet 0.6.7 → 0.6.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb +8 -2
- data/lib/rubocop/cop/sorbet/forbid_t_untyped.rb +29 -0
- data/lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb +29 -0
- data/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +1 -1
- data/lib/rubocop/cop/sorbet_cops.rb +3 -0
- data/lib/rubocop/sorbet/version.rb +1 -1
- data/manual/cops.md +6 -0
- data/manual/cops_sorbet.md +22 -2
- data/{shipit.yml → shipit.production.yml} +0 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eda9e8cef015959394e43c9aa03ba35fd39ce07b629e285799c65670a1694b64
|
4
|
+
data.tar.gz: 9be1efcb8eaa30dcfe7fa1e9fb8a59ae73257392d78f432440d98566bb5e3333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb3cfc072f18d9d8a30db0429b8998e2c1971a5d662dcade2abdf51c3ee122d9e1db1e0ee1d43682ef2ed2459b11d9f40afc9fbdec8b429ba89f00cd24413dc
|
7
|
+
data.tar.gz: 4217f8c4cda4881cb7d89fd0c2644008f3f5fd41660bdb3aa7a647c9b8e1a69981a9522e2b47de4440d75bf5541544ce35c9b7a12b88ecaacb5a9182cd43c346
|
data/.github/workflows/ci.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,13 +60,15 @@ end
|
|
60
60
|
|
61
61
|
### Rubocop rules for RBI files
|
62
62
|
|
63
|
-
|
63
|
+
To enable the cops related to RBI files under the `sorbet/rbi/` directory, put this in `sorbet/rbi/.rubocop.yml`:
|
64
64
|
|
65
65
|
```yaml
|
66
66
|
inherit_gem:
|
67
67
|
rubocop-sorbet: config/rbi.yml
|
68
68
|
```
|
69
69
|
|
70
|
+
This will turn off default cops for `**/*.rbi` files and enable the RBI specific cops.
|
71
|
+
|
70
72
|
## The Cops
|
71
73
|
All cops are located under [`lib/rubocop/cop/sorbet`](lib/rubocop/cop/sorbet), and contain examples/documentation.
|
72
74
|
|
data/config/default.yml
CHANGED
@@ -97,6 +97,12 @@ Sorbet/ForbidTUnsafe:
|
|
97
97
|
VersionAdded: 0.7.0
|
98
98
|
VersionChanged: 0.7.0
|
99
99
|
|
100
|
+
Sorbet/ForbidTUntyped:
|
101
|
+
Description: 'Forbid usage of T.untyped'
|
102
|
+
Enabled: false
|
103
|
+
VersionAdded: 0.6.9
|
104
|
+
VersionChanged: 0.7.0
|
105
|
+
|
100
106
|
Sorbet/ForbidUntypedStructProps:
|
101
107
|
Description: >-
|
102
108
|
Disallows use of `T.untyped` or `T.nilable(T.untyped)` as a
|
@@ -57,12 +57,18 @@ module RuboCop
|
|
57
57
|
)
|
58
58
|
PATTERN
|
59
59
|
|
60
|
-
def_node_matcher(:
|
60
|
+
def_node_matcher(:generic_parameter_decl_call?, <<-PATTERN)
|
61
61
|
(
|
62
62
|
send nil? {:type_template :type_member} ...
|
63
63
|
)
|
64
64
|
PATTERN
|
65
65
|
|
66
|
+
def_node_matcher(:generic_parameter_decl_block_call?, <<-PATTERN)
|
67
|
+
(block
|
68
|
+
(send nil? {:type_template :type_member} ...) ...
|
69
|
+
)
|
70
|
+
PATTERN
|
71
|
+
|
66
72
|
def_node_search(:method_needing_aliasing_on_t?, <<-PATTERN)
|
67
73
|
(
|
68
74
|
send
|
@@ -81,7 +87,7 @@ module RuboCop
|
|
81
87
|
end
|
82
88
|
|
83
89
|
def not_generic_parameter_decl?(node)
|
84
|
-
!
|
90
|
+
!generic_parameter_decl_call?(node) && !generic_parameter_decl_block_call?(node)
|
85
91
|
end
|
86
92
|
|
87
93
|
def not_nil?(node)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Sorbet
|
8
|
+
# This cop disallows using `T.untyped` anywhere.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# sig { params(my_argument: T.untyped).void }
|
14
|
+
# def foo(my_argument); end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# sig { params(my_argument: String).void }
|
18
|
+
# def foo(my_argument); end
|
19
|
+
#
|
20
|
+
class ForbidTUntyped < RuboCop::Cop::Cop
|
21
|
+
def_node_matcher(:t_untyped?, "(send (const nil? :T) :untyped)")
|
22
|
+
|
23
|
+
def on_send(node)
|
24
|
+
add_offense(node, message: "Do not use `T.untyped`.") if t_untyped?(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop/cop/style/mutable_constant"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Sorbet
|
8
|
+
module MutableConstantSorbetAwareBehaviour
|
9
|
+
def self.prepended(base)
|
10
|
+
base.def_node_matcher(:t_let, <<~PATTERN)
|
11
|
+
(send (const nil? :T) :let $_constant _type)
|
12
|
+
PATTERN
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_assignment(value)
|
16
|
+
t_let(value) do |constant|
|
17
|
+
value = constant
|
18
|
+
end
|
19
|
+
|
20
|
+
super(value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
RuboCop::Cop::Style::MutableConstant.prepend(
|
28
|
+
RuboCop::Cop::Sorbet::MutableConstantSorbetAwareBehaviour
|
29
|
+
)
|
@@ -7,6 +7,7 @@ require_relative "sorbet/forbid_untyped_struct_props"
|
|
7
7
|
require_relative "sorbet/one_ancestor_per_line"
|
8
8
|
require_relative "sorbet/callback_conditionals_binding"
|
9
9
|
require_relative "sorbet/forbid_t_unsafe"
|
10
|
+
require_relative "sorbet/forbid_t_untyped"
|
10
11
|
require_relative "sorbet/type_alias_name"
|
11
12
|
|
12
13
|
require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims"
|
@@ -28,3 +29,5 @@ require_relative "sorbet/sigils/strict_sigil"
|
|
28
29
|
require_relative "sorbet/sigils/strong_sigil"
|
29
30
|
require_relative "sorbet/sigils/enforce_sigil_order"
|
30
31
|
require_relative "sorbet/sigils/enforce_single_sigil"
|
32
|
+
|
33
|
+
require_relative "sorbet/mutable_constant_sorbet_aware_behaviour"
|
data/manual/cops.md
CHANGED
@@ -19,6 +19,7 @@ In the following section you find all available cops:
|
|
19
19
|
* [Sorbet/ForbidRBIOutsideOfAllowedPaths](cops_sorbet.md#sorbetforbidrbioutsideofallowedpaths)
|
20
20
|
* [Sorbet/ForbidSuperclassConstLiteral](cops_sorbet.md#sorbetforbidsuperclassconstliteral)
|
21
21
|
* [Sorbet/ForbidTUnsafe](cops_sorbet.md#sorbetforbidtunsafe)
|
22
|
+
* [Sorbet/ForbidTUntyped](cops_sorbet.md#sorbetforbidtuntyped)
|
22
23
|
* [Sorbet/ForbidUntypedStructProps](cops_sorbet.md#sorbetforbiduntypedstructprops)
|
23
24
|
* [Sorbet/HasSigil](cops_sorbet.md#sorbethassigil)
|
24
25
|
* [Sorbet/IgnoreSigil](cops_sorbet.md#sorbetignoresigil)
|
@@ -34,3 +35,8 @@ In the following section you find all available cops:
|
|
34
35
|
* [Sorbet/ValidSigil](cops_sorbet.md#sorbetvalidsigil)
|
35
36
|
|
36
37
|
<!-- END_COP_LIST -->
|
38
|
+
|
39
|
+
In addition to the cops defined in this gem, it also modifies the behaviour of some other cops
|
40
|
+
defined in other RuboCop gems:
|
41
|
+
|
42
|
+
* [Style/MutableConstant](https://docs.rubocop.org/rubocop/cops_style.html#stylemutableconstant): In addition to the default behaviour, RuboCop Sorbet makes this cop `T.let` aware, so that `CONST = T.let([1, 2, 3], T::Array[Integer])` is also treated as a mutable literal constant value.
|
data/manual/cops_sorbet.md
CHANGED
@@ -274,7 +274,7 @@ Include | `**/*.rbi` | Array
|
|
274
274
|
|
275
275
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
276
276
|
--- | --- | --- | --- | ---
|
277
|
-
Disabled | Yes |
|
277
|
+
Disabled | Yes | Yes | 0.2.0 | 0.5.0
|
278
278
|
|
279
279
|
No documentation
|
280
280
|
|
@@ -284,7 +284,7 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
|
|
284
284
|
--- | --- | --- | --- | ---
|
285
285
|
Enabled | Yes | No | 0.6.1 | -
|
286
286
|
|
287
|
-
This cop makes sure that RBI files are always located under the defined allowed paths
|
287
|
+
This cop makes sure that RBI files are always located under the defined allowed paths.
|
288
288
|
|
289
289
|
Options:
|
290
290
|
|
@@ -341,6 +341,26 @@ T.unsafe(foo)
|
|
341
341
|
foo
|
342
342
|
```
|
343
343
|
|
344
|
+
## Sorbet/ForbidTUntyped
|
345
|
+
|
346
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
347
|
+
--- | --- | --- | --- | ---
|
348
|
+
Disabled | Yes | No | 0.6.9 | 0.7.0
|
349
|
+
|
350
|
+
This cop disallows using `T.untyped` anywhere.
|
351
|
+
|
352
|
+
### Examples
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
# bad
|
356
|
+
sig { params(my_argument: T.untyped).void }
|
357
|
+
def foo(my_argument); end
|
358
|
+
|
359
|
+
# good
|
360
|
+
sig { params(my_argument: String).void }
|
361
|
+
def foo(my_argument); end
|
362
|
+
```
|
363
|
+
|
344
364
|
## Sorbet/ForbidUntypedStructProps
|
345
365
|
|
346
366
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
File without changes
|
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.6.
|
4
|
+
version: 0.6.10
|
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: 2022-
|
14
|
+
date: 2022-06-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
@@ -91,7 +91,9 @@ files:
|
|
91
91
|
- lib/rubocop/cop/sorbet/forbid_include_const_literal.rb
|
92
92
|
- lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
|
93
93
|
- lib/rubocop/cop/sorbet/forbid_t_unsafe.rb
|
94
|
+
- lib/rubocop/cop/sorbet/forbid_t_untyped.rb
|
94
95
|
- lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb
|
96
|
+
- lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb
|
95
97
|
- lib/rubocop/cop/sorbet/one_ancestor_per_line.rb
|
96
98
|
- lib/rubocop/cop/sorbet/rbi/forbid_extend_t_sig_helpers_in_shims.rb
|
97
99
|
- lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb
|
@@ -120,7 +122,7 @@ files:
|
|
120
122
|
- manual/cops_sorbet.md
|
121
123
|
- rubocop-sorbet.gemspec
|
122
124
|
- service.yml
|
123
|
-
- shipit.yml
|
125
|
+
- shipit.production.yml
|
124
126
|
- tasks/cops_documentation.rake
|
125
127
|
homepage: https://github.com/shopify/rubocop-sorbet
|
126
128
|
licenses:
|
@@ -144,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
146
|
- !ruby/object:Gem::Version
|
145
147
|
version: '0'
|
146
148
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.3.3
|
148
150
|
signing_key:
|
149
151
|
specification_version: 4
|
150
152
|
summary: Automatic Sorbet code style checking tool.
|