rubocop-sorbet 0.7.4 → 0.7.6
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +17 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/config/default.yml +5 -0
- data/config/rbi.yml +3 -0
- data/lib/rubocop/cop/sorbet/forbid_include_const_literal.rb +22 -28
- data/lib/rubocop/cop/sorbet/forbid_t_struct.rb +14 -5
- data/lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb +44 -0
- data/lib/rubocop/cop/sorbet/{signatures/signature_cop.rb → mixin/signature_help.rb} +7 -11
- data/lib/rubocop/cop/sorbet/rbi/forbid_rbi_outside_of_allowed_paths.rb +1 -1
- data/lib/rubocop/cop/sorbet/sigils/valid_sigil.rb +5 -5
- data/lib/rubocop/cop/sorbet/signatures/allow_incompatible_override.rb +1 -1
- data/lib/rubocop/cop/sorbet/signatures/checked_true_in_signature.rb +2 -4
- data/lib/rubocop/cop/sorbet/signatures/empty_line_after_sig.rb +46 -28
- data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +3 -3
- data/lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb +3 -4
- data/lib/rubocop/cop/sorbet/signatures/signature_build_order.rb +22 -4
- data/lib/rubocop/cop/sorbet_cops.rb +2 -0
- data/lib/rubocop/sorbet/version.rb +1 -1
- data/manual/cops.md +1 -1
- data/manual/cops_sorbet.md +43 -9
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb19df178a322278126862ef69ee548a1480a3273b2fa7cb390efea682076d3
|
4
|
+
data.tar.gz: a4808b614e42b591e1254298ae40b41327b5762f5d7e494e5dbd476034d7f5a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 495f4c62a3e669483d4a2fb958672480e1f50519589bbef0efab007b32f56c32fad54a795a47ee8da6157d4595da0a50f845744578e0f44fab34e57fc67aa28e
|
7
|
+
data.tar.gz: 3e07de7f56533ed0c86dfb510e8efa0a3d1c9eb79cd130f24235cd6919a1f05ca88afc8fa7ae114de9de3ed49beac2ddc16d0d0c3e37a0a2bf6f7404ac80dcaa
|
data/.github/workflows/ci.yml
CHANGED
@@ -6,12 +6,12 @@ env:
|
|
6
6
|
SRB_SKIP_GEM_RBIS: true
|
7
7
|
|
8
8
|
jobs:
|
9
|
-
|
9
|
+
test:
|
10
10
|
runs-on: ubuntu-latest
|
11
11
|
strategy:
|
12
12
|
fail-fast: false
|
13
13
|
matrix:
|
14
|
-
ruby: [
|
14
|
+
ruby: ["2.7", "3.0", "3.1", "3.2"]
|
15
15
|
name: Test Ruby ${{ matrix.ruby }}
|
16
16
|
steps:
|
17
17
|
- uses: actions/checkout@v2
|
@@ -20,9 +20,22 @@ jobs:
|
|
20
20
|
with:
|
21
21
|
ruby-version: ${{ matrix.ruby }}
|
22
22
|
bundler-cache: true
|
23
|
+
- name: Run tests
|
24
|
+
run: bin/rspec
|
25
|
+
|
26
|
+
lint-and-docs:
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
strategy:
|
29
|
+
fail-fast: false
|
30
|
+
name: Lint & Docs
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby
|
34
|
+
uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: 3.2
|
37
|
+
bundler-cache: true
|
23
38
|
- name: Lint Ruby files
|
24
39
|
run: bin/rubocop
|
25
40
|
- name: Verify documentation is up to date
|
26
41
|
run: bundle exec rake generate_cops_documentation
|
27
|
-
- name: Run tests
|
28
|
-
run: bin/rspec
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/config/default.yml
CHANGED
@@ -89,6 +89,11 @@ Sorbet/ForbidIncludeConstLiteral:
|
|
89
89
|
VersionAdded: 0.2.0
|
90
90
|
VersionChanged: 0.5.0
|
91
91
|
|
92
|
+
Sorbet/ForbidTypeAliasedShapes:
|
93
|
+
Description: 'Forbids defining type aliases that contain shapes'
|
94
|
+
Enabled: false
|
95
|
+
VersionAdded: 0.7.6
|
96
|
+
|
92
97
|
Sorbet/ForbidSuperclassConstLiteral:
|
93
98
|
Description: 'Forbid superclasses which are non-literal constants.'
|
94
99
|
Enabled: false
|
data/config/rbi.yml
CHANGED
@@ -26,44 +26,38 @@ module RuboCop
|
|
26
26
|
# ```ruby
|
27
27
|
# include Polaris::Engine.helpers
|
28
28
|
# ```
|
29
|
-
class ForbidIncludeConstLiteral < RuboCop::Cop::
|
30
|
-
|
29
|
+
class ForbidIncludeConstLiteral < RuboCop::Cop::Base
|
30
|
+
extend AutoCorrector
|
31
31
|
|
32
|
-
|
32
|
+
MSG = "`%<inclusion_method>s` must only be used with constant literals as arguments"
|
33
|
+
RESTRICT_ON_SEND = [:include, :extend, :prepend].freeze
|
33
34
|
|
34
|
-
# @!method
|
35
|
-
def_node_matcher :
|
36
|
-
(send nil? {:include :extend :prepend}
|
37
|
-
$_
|
38
|
-
)
|
35
|
+
# @!method dynamic_inclusion?(node)
|
36
|
+
def_node_matcher :dynamic_inclusion?, <<~PATTERN
|
37
|
+
(send nil? ${:include :extend :prepend} $#neither_const_nor_self?)
|
39
38
|
PATTERN
|
40
39
|
|
41
|
-
def initialize(*)
|
42
|
-
super
|
43
|
-
self.used_names = Set.new
|
44
|
-
end
|
45
|
-
|
46
40
|
def on_send(node)
|
47
|
-
|
48
|
-
|
49
|
-
end
|
41
|
+
dynamic_inclusion?(node) do |inclusion_method, included|
|
42
|
+
return unless within_onymous_module?(node)
|
50
43
|
|
51
|
-
|
52
|
-
|
44
|
+
add_offense(node, message: format(MSG, inclusion_method: inclusion_method)) do |corrector|
|
45
|
+
corrector.replace(node, "T.unsafe(self).#{inclusion_method} #{included.source}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
53
49
|
|
54
|
-
|
55
|
-
return unless [:module, :class, :sclass].include?(parent.type)
|
50
|
+
private
|
56
51
|
|
57
|
-
|
52
|
+
def neither_const_nor_self?(node)
|
53
|
+
!node.const_type? && !node.self_type?
|
58
54
|
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
)
|
66
|
-
end
|
56
|
+
# Returns true if the node is within a module declaration that is not anonymous.
|
57
|
+
def within_onymous_module?(node)
|
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?)
|
67
61
|
end
|
68
62
|
end
|
69
63
|
end
|
@@ -131,8 +131,13 @@ module RuboCop
|
|
131
131
|
def initialize_param
|
132
132
|
rb = String.new
|
133
133
|
rb << "#{name}:"
|
134
|
-
|
135
|
-
|
134
|
+
if default
|
135
|
+
rb << " #{default}"
|
136
|
+
elsif factory
|
137
|
+
rb << " #{factory}"
|
138
|
+
elsif nilable?
|
139
|
+
rb << " nil"
|
140
|
+
end
|
136
141
|
rb
|
137
142
|
end
|
138
143
|
|
@@ -142,6 +147,10 @@ module RuboCop
|
|
142
147
|
rb << ".call" if factory
|
143
148
|
rb
|
144
149
|
end
|
150
|
+
|
151
|
+
def nilable?
|
152
|
+
type.start_with?("T.nilable(")
|
153
|
+
end
|
145
154
|
end
|
146
155
|
|
147
156
|
# @!method t_struct?(node)
|
@@ -203,11 +212,11 @@ module RuboCop
|
|
203
212
|
|
204
213
|
def initialize_method(indent, props)
|
205
214
|
# We sort optional keyword arguments after required ones
|
206
|
-
|
215
|
+
sorted_props = props.sort_by { |prop| prop.default || prop.factory || prop.nilable? ? 1 : 0 }
|
207
216
|
|
208
217
|
string = +"\n"
|
209
|
-
string << "#{indent}sig { params(#{
|
210
|
-
string << "#{indent}def initialize(#{
|
218
|
+
string << "#{indent}sig { params(#{sorted_props.map(&:initialize_sig_param).join(", ")}).void }\n"
|
219
|
+
string << "#{indent}def initialize(#{sorted_props.map(&:initialize_param).join(", ")})\n"
|
211
220
|
props.each do |prop|
|
212
221
|
string << "#{indent} #{prop.initialize_assign}\n"
|
213
222
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
module Sorbet
|
8
|
+
# Disallows defining type aliases that contain shapes
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# Foo = T.type_alias { { foo: Integer } }
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# class Foo
|
17
|
+
# extend T::Sig
|
18
|
+
#
|
19
|
+
# sig { params(foo: Integer).void }
|
20
|
+
# def initialize(foo)
|
21
|
+
# @foo = foo
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
class ForbidTypeAliasedShapes < RuboCop::Cop::Base
|
25
|
+
MSG = "Type aliases shouldn't contain shapes because of significant performance overhead"
|
26
|
+
|
27
|
+
# @!method shape_type_alias?(node)
|
28
|
+
def_node_matcher(:shape_type_alias?, <<-PATTERN)
|
29
|
+
(block
|
30
|
+
(send (const {nil? cbase} :T) :type_alias)
|
31
|
+
(args)
|
32
|
+
`hash
|
33
|
+
)
|
34
|
+
PATTERN
|
35
|
+
|
36
|
+
def on_block(node)
|
37
|
+
add_offense(node) if shape_type_alias?(node)
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :on_numblock, :on_block
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rubocop"
|
4
|
-
|
5
3
|
module RuboCop
|
6
4
|
module Cop
|
7
5
|
module Sorbet
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
class SignatureCop < RuboCop::Cop::Cop # rubocop:todo InternalAffairs/InheritDeprecatedCopClass
|
12
|
-
@registry = Cop.registry # So we can properly subclass this cop
|
6
|
+
# Mixin for writing cops for signatures, providing a `signature?` node matcher and an `on_signature` trigger.
|
7
|
+
module SignatureHelp
|
8
|
+
extend RuboCop::NodePattern::Macros
|
13
9
|
|
14
10
|
# @!method signature?(node)
|
15
11
|
def_node_matcher(:signature?, <<~PATTERN)
|
@@ -22,12 +18,12 @@ module RuboCop
|
|
22
18
|
|
23
19
|
# @!method with_runtime?(node)
|
24
20
|
def_node_matcher(:with_runtime?, <<~PATTERN)
|
25
|
-
(const (const nil? :T) :Sig)
|
21
|
+
(const (const {nil? cbase} :T) :Sig)
|
26
22
|
PATTERN
|
27
23
|
|
28
24
|
# @!method without_runtime?(node)
|
29
25
|
def_node_matcher(:without_runtime?, <<~PATTERN)
|
30
|
-
(const (const (const nil? :T) :Sig) :WithoutRuntime)
|
26
|
+
(const (const (const {nil? cbase} :T) :Sig) :WithoutRuntime)
|
31
27
|
PATTERN
|
32
28
|
|
33
29
|
def on_block(node)
|
@@ -36,8 +32,8 @@ module RuboCop
|
|
36
32
|
|
37
33
|
alias_method :on_numblock, :on_block
|
38
34
|
|
39
|
-
def on_signature(
|
40
|
-
# To be defined
|
35
|
+
def on_signature(_node)
|
36
|
+
# To be defined by cop class as needed
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
return suggested_strictness unless minimum_strictness
|
91
91
|
|
92
92
|
# special case: if you're using Sorbet/IgnoreSigil without config, we should recommend `ignore`
|
93
|
-
return "ignore" if minimum_strictness == "ignore" && cop_config["SuggestedStrictness"].nil?
|
93
|
+
return "ignore" if minimum_strictness == "ignore" && cop_config["SuggestedStrictness"].nil?
|
94
94
|
|
95
95
|
# if a minimum strictness is set (eg. you're using Sorbet/FalseSigil)
|
96
96
|
# we want to compare the minimum strictness and suggested strictness. this is because
|
@@ -161,24 +161,24 @@ module RuboCop
|
|
161
161
|
|
162
162
|
# Default is `false`
|
163
163
|
def require_sigil_on_all_files?
|
164
|
-
!!cop_config["RequireSigilOnAllFiles"]
|
164
|
+
!!cop_config["RequireSigilOnAllFiles"]
|
165
165
|
end
|
166
166
|
|
167
167
|
# Default is `'false'`
|
168
168
|
def suggested_strictness
|
169
|
-
config = cop_config["SuggestedStrictness"].to_s
|
169
|
+
config = cop_config["SuggestedStrictness"].to_s
|
170
170
|
STRICTNESS_LEVELS.include?(config) ? config : "false"
|
171
171
|
end
|
172
172
|
|
173
173
|
# Default is `nil`
|
174
174
|
def minimum_strictness
|
175
|
-
config = cop_config["MinimumStrictness"].to_s
|
175
|
+
config = cop_config["MinimumStrictness"].to_s
|
176
176
|
config if STRICTNESS_LEVELS.include?(config)
|
177
177
|
end
|
178
178
|
|
179
179
|
# Default is `nil`
|
180
180
|
def exact_strictness
|
181
|
-
config = cop_config["ExactStrictness"].to_s
|
181
|
+
config = cop_config["ExactStrictness"].to_s
|
182
182
|
config if STRICTNESS_LEVELS.include?(config)
|
183
183
|
end
|
184
184
|
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rubocop"
|
4
|
-
require_relative "signature_cop"
|
5
|
-
|
6
3
|
module RuboCop
|
7
4
|
module Cop
|
8
5
|
module Sorbet
|
@@ -19,8 +16,9 @@ module RuboCop
|
|
19
16
|
#
|
20
17
|
# # good
|
21
18
|
# sig { void }
|
22
|
-
class CheckedTrueInSignature <
|
19
|
+
class CheckedTrueInSignature < ::RuboCop::Cop::Cop # rubocop:todo InternalAffairs/InheritDeprecatedCopClass
|
23
20
|
include(RuboCop::Cop::RangeHelp)
|
21
|
+
include(RuboCop::Cop::Sorbet::SignatureHelp)
|
24
22
|
|
25
23
|
# @!method offending_node(node)
|
26
24
|
def_node_search(:offending_node, <<~PATTERN)
|
@@ -1,16 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "signature_cop"
|
4
|
-
|
5
3
|
module RuboCop
|
6
4
|
module Cop
|
7
5
|
module Sorbet
|
8
6
|
# Checks for blank lines after signatures.
|
9
7
|
#
|
10
|
-
# It also suggests an autocorrect
|
11
|
-
#
|
12
8
|
# @example
|
13
|
-
#
|
14
9
|
# # bad
|
15
10
|
# sig { void }
|
16
11
|
#
|
@@ -19,37 +14,60 @@ module RuboCop
|
|
19
14
|
# # good
|
20
15
|
# sig { void }
|
21
16
|
# def foo; end
|
22
|
-
|
23
|
-
|
17
|
+
class EmptyLineAfterSig < ::RuboCop::Cop::Base
|
18
|
+
extend AutoCorrector
|
24
19
|
include RangeHelp
|
20
|
+
include SignatureHelp
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
MSG = "Extra empty line or comment detected"
|
23
|
+
|
24
|
+
# @!method sig_or_signable_method_definition?(node)
|
25
|
+
def_node_matcher :sig_or_signable_method_definition?, <<~PATTERN
|
26
|
+
${
|
27
|
+
def
|
28
|
+
defs
|
29
|
+
(send nil? {:attr_reader :attr_writer :attr_accessor} ...)
|
30
|
+
#signature?
|
31
|
+
}
|
32
|
+
PATTERN
|
32
33
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
def on_signature(sig)
|
35
|
+
sig_or_signable_method_definition?(next_sibling(sig)) do |definition|
|
36
|
+
range = lines_between(sig, definition)
|
37
|
+
next if range.empty? || range.single_line?
|
38
|
+
|
39
|
+
add_offense(range) do |corrector|
|
40
|
+
corrector.insert_before(
|
41
|
+
range_by_whole_lines(sig.source_range),
|
42
|
+
range.source
|
43
|
+
.sub(/\A\n+/, "") # remove initial newline(s)
|
44
|
+
.gsub(/\n{2,}/, "\n"), # remove empty line(s)
|
45
|
+
)
|
46
|
+
corrector.remove(range)
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
51
|
private
|
47
52
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
+
def next_sibling(node)
|
54
|
+
node.parent&.children&.at(node.sibling_index + 1)
|
55
|
+
end
|
56
|
+
|
57
|
+
def lines_between(node1, node2, buffer: processed_source.buffer)
|
58
|
+
end_of_node1_pos = node1.source_range.end_pos
|
59
|
+
start_of_node2_pos = node2.source_range.begin_pos
|
60
|
+
|
61
|
+
string_in_between = buffer.slice(end_of_node1_pos...start_of_node2_pos)
|
62
|
+
# Fallbacks handle same line edge case
|
63
|
+
begin_offset = string_in_between.index("\n") || 0
|
64
|
+
end_offset = string_in_between.rindex("\n") || string_in_between.length - 1
|
65
|
+
|
66
|
+
Parser::Source::Range.new(
|
67
|
+
buffer,
|
68
|
+
end_of_node1_pos + begin_offset + 1, # +1 to exclude post-node1 newline
|
69
|
+
end_of_node1_pos + end_offset + 1, # +1 to include pre-node2 newline
|
70
|
+
)
|
53
71
|
end
|
54
72
|
end
|
55
73
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rubocop"
|
4
3
|
require "stringio"
|
5
|
-
require_relative "signature_cop"
|
6
4
|
|
7
5
|
module RuboCop
|
8
6
|
module Cop
|
@@ -26,7 +24,9 @@ module RuboCop
|
|
26
24
|
#
|
27
25
|
# * `ParameterTypePlaceholder`: placeholders used for parameter types (default: 'T.untyped')
|
28
26
|
# * `ReturnTypePlaceholder`: placeholders used for return types (default: 'T.untyped')
|
29
|
-
class EnforceSignatures <
|
27
|
+
class EnforceSignatures < ::RuboCop::Cop::Cop # rubocop:todo InternalAffairs/InheritDeprecatedCopClass
|
28
|
+
include SignatureHelp
|
29
|
+
|
30
30
|
def initialize(config = nil, options = nil)
|
31
31
|
super(config, options)
|
32
32
|
@last_sig_for_scope = {}
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rubocop"
|
4
|
-
require_relative "signature_cop"
|
5
|
-
|
6
3
|
module RuboCop
|
7
4
|
module Cop
|
8
5
|
module Sorbet
|
@@ -20,7 +17,9 @@ module RuboCop
|
|
20
17
|
# # good
|
21
18
|
# sig { params(b: String, a: Integer).void }
|
22
19
|
# def foo(b:, a: 1); end
|
23
|
-
class KeywordArgumentOrdering <
|
20
|
+
class KeywordArgumentOrdering < ::RuboCop::Cop::Cop # rubocop:todo InternalAffairs/InheritDeprecatedCopClass
|
21
|
+
include SignatureHelp
|
22
|
+
|
24
23
|
def on_signature(node)
|
25
24
|
method_node = node.parent.children[node.sibling_index + 1]
|
26
25
|
return if method_node.nil?
|
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "rubocop"
|
4
|
-
require_relative "signature_cop"
|
5
|
-
|
6
3
|
begin
|
7
4
|
require "unparser"
|
8
5
|
rescue LoadError
|
@@ -12,7 +9,28 @@ end
|
|
12
9
|
module RuboCop
|
13
10
|
module Cop
|
14
11
|
module Sorbet
|
15
|
-
|
12
|
+
# Checks for the correct order of sig builder methods:
|
13
|
+
# - abstract, override, or overridable
|
14
|
+
# - type_parameters
|
15
|
+
# - params
|
16
|
+
# - returns, or void
|
17
|
+
# - soft, checked, or on_failure
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# # bad
|
21
|
+
# sig { void.abstract }
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# sig { abstract.void }
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# sig { returns(Integer).params(x: Integer) }
|
28
|
+
#
|
29
|
+
# # good
|
30
|
+
# sig { params(x: Integer).returns(Integer) }
|
31
|
+
class SignatureBuildOrder < ::RuboCop::Cop::Cop # rubocop:todo InternalAffairs/InheritDeprecatedCopClass
|
32
|
+
include SignatureHelp
|
33
|
+
|
16
34
|
ORDER =
|
17
35
|
[
|
18
36
|
:abstract,
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "sorbet/mixin/target_sorbet_version.rb"
|
4
|
+
require_relative "sorbet/mixin/signature_help.rb"
|
4
5
|
|
5
6
|
require_relative "sorbet/binding_constant_without_type_alias"
|
6
7
|
require_relative "sorbet/constants_from_strings"
|
7
8
|
require_relative "sorbet/forbid_superclass_const_literal"
|
8
9
|
require_relative "sorbet/forbid_include_const_literal"
|
10
|
+
require_relative "sorbet/forbid_type_aliased_shapes"
|
9
11
|
require_relative "sorbet/forbid_untyped_struct_props"
|
10
12
|
require_relative "sorbet/implicit_conversion_method"
|
11
13
|
require_relative "sorbet/one_ancestor_per_line"
|
data/manual/cops.md
CHANGED
@@ -23,6 +23,7 @@ In the following section you find all available cops:
|
|
23
23
|
* [Sorbet/ForbidTStruct](cops_sorbet.md#sorbetforbidtstruct)
|
24
24
|
* [Sorbet/ForbidTUnsafe](cops_sorbet.md#sorbetforbidtunsafe)
|
25
25
|
* [Sorbet/ForbidTUntyped](cops_sorbet.md#sorbetforbidtuntyped)
|
26
|
+
* [Sorbet/ForbidTypeAliasedShapes](cops_sorbet.md#sorbetforbidtypealiasedshapes)
|
26
27
|
* [Sorbet/ForbidUntypedStructProps](cops_sorbet.md#sorbetforbiduntypedstructprops)
|
27
28
|
* [Sorbet/HasSigil](cops_sorbet.md#sorbethassigil)
|
28
29
|
* [Sorbet/IgnoreSigil](cops_sorbet.md#sorbetignoresigil)
|
@@ -32,7 +33,6 @@ In the following section you find all available cops:
|
|
32
33
|
* [Sorbet/OneAncestorPerLine](cops_sorbet.md#sorbetoneancestorperline)
|
33
34
|
* [Sorbet/RedundantExtendTSig](cops_sorbet.md#sorbetredundantextendtsig)
|
34
35
|
* [Sorbet/SignatureBuildOrder](cops_sorbet.md#sorbetsignaturebuildorder)
|
35
|
-
* [Sorbet/SignatureCop](cops_sorbet.md#sorbetsignaturecop)
|
36
36
|
* [Sorbet/SingleLineRbiClassModuleDefinitions](cops_sorbet.md#sorbetsinglelinerbiclassmoduledefinitions)
|
37
37
|
* [Sorbet/StrictSigil](cops_sorbet.md#sorbetstrictsigil)
|
38
38
|
* [Sorbet/StrongSigil](cops_sorbet.md#sorbetstrongsigil)
|
data/manual/cops_sorbet.md
CHANGED
@@ -184,8 +184,6 @@ Enabled | Yes | Yes | 0.7.0 | -
|
|
184
184
|
|
185
185
|
Checks for blank lines after signatures.
|
186
186
|
|
187
|
-
It also suggests an autocorrect
|
188
|
-
|
189
187
|
### Examples
|
190
188
|
|
191
189
|
```ruby
|
@@ -498,6 +496,31 @@ sig { params(my_argument: String).void }
|
|
498
496
|
def foo(my_argument); end
|
499
497
|
```
|
500
498
|
|
499
|
+
## Sorbet/ForbidTypeAliasedShapes
|
500
|
+
|
501
|
+
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
502
|
+
--- | --- | --- | --- | ---
|
503
|
+
Disabled | Yes | No | 0.7.6 | -
|
504
|
+
|
505
|
+
Disallows defining type aliases that contain shapes
|
506
|
+
|
507
|
+
### Examples
|
508
|
+
|
509
|
+
```ruby
|
510
|
+
# bad
|
511
|
+
Foo = T.type_alias { { foo: Integer } }
|
512
|
+
|
513
|
+
# good
|
514
|
+
class Foo
|
515
|
+
extend T::Sig
|
516
|
+
|
517
|
+
sig { params(foo: Integer).void }
|
518
|
+
def initialize(foo)
|
519
|
+
@foo = foo
|
520
|
+
end
|
521
|
+
end
|
522
|
+
```
|
523
|
+
|
501
524
|
## Sorbet/ForbidUntypedStructProps
|
502
525
|
|
503
526
|
Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged
|
@@ -710,17 +733,28 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
|
|
710
733
|
--- | --- | --- | --- | ---
|
711
734
|
Enabled | Yes | Yes | 0.3.0 | -
|
712
735
|
|
713
|
-
|
736
|
+
Checks for the correct order of sig builder methods:
|
737
|
+
- abstract, override, or overridable
|
738
|
+
- type_parameters
|
739
|
+
- params
|
740
|
+
- returns, or void
|
741
|
+
- soft, checked, or on_failure
|
714
742
|
|
715
|
-
|
743
|
+
# bad
|
744
|
+
sig { returns(Integer).params(x: Integer) }
|
716
745
|
|
717
|
-
|
718
|
-
|
719
|
-
Enabled | Yes | No | - | -
|
746
|
+
# good
|
747
|
+
sig { params(x: Integer).returns(Integer) }
|
720
748
|
|
721
|
-
|
749
|
+
### Examples
|
750
|
+
|
751
|
+
```ruby
|
752
|
+
# bad
|
753
|
+
sig { void.abstract }
|
722
754
|
|
723
|
-
|
755
|
+
# good
|
756
|
+
sig { abstract.void }
|
757
|
+
```
|
724
758
|
|
725
759
|
## Sorbet/SingleLineRbiClassModuleDefinitions
|
726
760
|
|
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.
|
4
|
+
version: 0.7.6
|
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-
|
14
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rspec
|
@@ -95,8 +95,10 @@ files:
|
|
95
95
|
- lib/rubocop/cop/sorbet/forbid_t_struct.rb
|
96
96
|
- lib/rubocop/cop/sorbet/forbid_t_unsafe.rb
|
97
97
|
- lib/rubocop/cop/sorbet/forbid_t_untyped.rb
|
98
|
+
- lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
|
98
99
|
- lib/rubocop/cop/sorbet/forbid_untyped_struct_props.rb
|
99
100
|
- lib/rubocop/cop/sorbet/implicit_conversion_method.rb
|
101
|
+
- lib/rubocop/cop/sorbet/mixin/signature_help.rb
|
100
102
|
- lib/rubocop/cop/sorbet/mixin/target_sorbet_version.rb
|
101
103
|
- lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb
|
102
104
|
- lib/rubocop/cop/sorbet/obsolete_strict_memoization.rb
|
@@ -120,7 +122,6 @@ files:
|
|
120
122
|
- lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb
|
121
123
|
- lib/rubocop/cop/sorbet/signatures/keyword_argument_ordering.rb
|
122
124
|
- lib/rubocop/cop/sorbet/signatures/signature_build_order.rb
|
123
|
-
- lib/rubocop/cop/sorbet/signatures/signature_cop.rb
|
124
125
|
- lib/rubocop/cop/sorbet/type_alias_name.rb
|
125
126
|
- lib/rubocop/cop/sorbet_cops.rb
|
126
127
|
- lib/rubocop/sorbet.rb
|
@@ -154,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
rubygems_version: 3.4.
|
158
|
+
rubygems_version: 3.4.22
|
158
159
|
signing_key:
|
159
160
|
specification_version: 4
|
160
161
|
summary: Automatic Sorbet code style checking tool.
|