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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c51ae13ac2c32733024c71003fa884392ea9ba66a7a02638a7f000f1ca59ffc3
4
- data.tar.gz: 3d665a684394894867652ee120361c9e03d2f41a6ef713d91b89f6a927bde8ea
3
+ metadata.gz: e4fb414d8d5df23d654fc8f861efb308e2a1d4c3a51fcea2d87ce65654179a1b
4
+ data.tar.gz: 320d66ec089e119e43a19630a5a144c9fd69ef415af600ff8abd9d1690e6cf98
5
5
  SHA512:
6
- metadata.gz: 47098214ac3bf1ca4d3c26ebce8a7668bf02179180d4c7407965c4d3a6e436df67af6e7850b19787e5bbbe5265ebc35a5958bc424c4fb043d69cf7b157cdba76
7
- data.tar.gz: bb120a2eab93d930a407a3d34e1f1d407eda219cfb0410d4a0a31cb8ccfc91d2d410634c8eb0c7d81e38af406631c458b29145c5f5e0e61455c0764d9477ab75
6
+ metadata.gz: 134904f291e25f0a766cef59a1e634b28f67083702eb9012e2e23d693d7eef09de7a484d43756a66ac15466c9f1f3f87c787c656e5391c948b3ac90f680f51ec
7
+ data.tar.gz: aaa261000213551b7591761df1be4b78932af5846578d9969e75cdb79d4c104fd75c3f66610d5248d80b5e36f74496f1938fc2c1e35b56582d8200b7829e04bc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-sorbet (0.13.1)
4
+ rubocop-sorbet (0.13.2)
5
5
  lint_roller
6
6
  rubocop (>= 1.75.2)
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.1
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
- suggest = create_signature_suggestion(node, type)
121
+ target = leftmost_send_ancestor(node)
122
+ suggest = create_signature_suggestion(target, type)
122
123
  populate_signature_suggestion(suggest, node)
123
- corrector.insert_before(node, suggest.to_autocorrect)
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
 
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.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu