rubocop-sorbet 0.13.1 → 0.13.2
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb +35 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4fb414d8d5df23d654fc8f861efb308e2a1d4c3a51fcea2d87ce65654179a1b
|
|
4
|
+
data.tar.gz: 320d66ec089e119e43a19630a5a144c9fd69ef415af600ff8abd9d1690e6cf98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 134904f291e25f0a766cef59a1e634b28f67083702eb9012e2e23d693d7eef09de7a484d43756a66ac15466c9f1f3f87c787c656e5391c948b3ac90f680f51ec
|
|
7
|
+
data.tar.gz: aaa261000213551b7591761df1be4b78932af5846578d9969e75cdb79d4c104fd75c3f66610d5248d80b5e36f74496f1938fc2c1e35b56582d8200b7829e04bc
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.13.
|
|
1
|
+
0.13.2
|
|
@@ -118,9 +118,16 @@ module RuboCop
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
def autocorrect_with_signature_type(corrector, node, type)
|
|
121
|
-
|
|
121
|
+
target = leftmost_send_ancestor(node)
|
|
122
|
+
suggest = create_signature_suggestion(target, type)
|
|
122
123
|
populate_signature_suggestion(suggest, node)
|
|
123
|
-
corrector.insert_before(
|
|
124
|
+
corrector.insert_before(target, suggest.to_autocorrect)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def leftmost_send_ancestor(node)
|
|
128
|
+
ancestor = node
|
|
129
|
+
ancestor = ancestor.parent while ancestor.parent&.send_type?
|
|
130
|
+
ancestor
|
|
124
131
|
end
|
|
125
132
|
|
|
126
133
|
def create_signature_suggestion(node, type)
|
|
@@ -141,6 +148,8 @@ module RuboCop
|
|
|
141
148
|
end
|
|
142
149
|
|
|
143
150
|
def populate_method_definition_suggestion(suggest, node)
|
|
151
|
+
suggest.returns = "void" if instance_initialize?(node)
|
|
152
|
+
|
|
144
153
|
node.arguments.each do |arg|
|
|
145
154
|
if arg.blockarg_type? && suggest.respond_to?(:has_block=)
|
|
146
155
|
suggest.has_block = true
|
|
@@ -150,10 +159,30 @@ module RuboCop
|
|
|
150
159
|
end
|
|
151
160
|
end
|
|
152
161
|
|
|
162
|
+
def instance_initialize?(node)
|
|
163
|
+
node.def_type? && node.method?(:initialize) && !in_sclass_context?(node)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def in_sclass_context?(node)
|
|
167
|
+
parent = node.parent
|
|
168
|
+
while parent
|
|
169
|
+
return true if parent.sclass_type?
|
|
170
|
+
return false if parent.type?(:class, :module)
|
|
171
|
+
|
|
172
|
+
parent = parent.parent
|
|
173
|
+
end
|
|
174
|
+
false
|
|
175
|
+
end
|
|
176
|
+
|
|
153
177
|
def populate_accessor_suggestion(suggest, node)
|
|
154
178
|
method = node.children[1]
|
|
155
179
|
symbol = node.children[2]
|
|
156
180
|
|
|
181
|
+
if suggest.is_a?(RBSSuggestion)
|
|
182
|
+
suggest.attribute = true
|
|
183
|
+
return
|
|
184
|
+
end
|
|
185
|
+
|
|
157
186
|
add_accessor_parameter_if_needed(suggest, symbol, method)
|
|
158
187
|
set_void_return_for_writer(suggest, method)
|
|
159
188
|
end
|
|
@@ -299,12 +328,13 @@ module RuboCop
|
|
|
299
328
|
end
|
|
300
329
|
|
|
301
330
|
class RBSSuggestion
|
|
302
|
-
attr_accessor :params, :returns, :has_block
|
|
331
|
+
attr_accessor :params, :returns, :has_block, :attribute
|
|
303
332
|
|
|
304
333
|
def initialize(indent)
|
|
305
334
|
@params = []
|
|
306
335
|
@returns = nil
|
|
307
336
|
@has_block = false
|
|
337
|
+
@attribute = false
|
|
308
338
|
@indent = indent
|
|
309
339
|
end
|
|
310
340
|
|
|
@@ -315,6 +345,8 @@ module RuboCop
|
|
|
315
345
|
private
|
|
316
346
|
|
|
317
347
|
def generate_signature
|
|
348
|
+
return @returns || "untyped" if @attribute
|
|
349
|
+
|
|
318
350
|
param_types = @params.map { |param| rbs_param(param) }.join(", ")
|
|
319
351
|
return_type = @returns || "untyped"
|
|
320
352
|
|