rbi 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a2cb2f6b2287a3faed50161d70e0c863892c88c6eef5a3c798ccf8e16e0c441
4
- data.tar.gz: e851f3b85aa62534a3a1c867085add40aa7669df3b003f17e62eb81ce36c58ed
3
+ metadata.gz: 0ab48b069bf534228e48c5c76caeb71daca4dd905a00cbdbfdd0ce7ce9374987
4
+ data.tar.gz: f301b0ce6eff170542931c88095d78ff60ffd5e20720eb04461bdbb3eeb98a8d
5
5
  SHA512:
6
- metadata.gz: b566ecfc9c01ebf7524efb055302e3da780caf0e0cc3ab36bdca798ff8390cce5247bce1318c5373c8339fede498f3bc87ffd5071ace658880c0b3724a9f1d15
7
- data.tar.gz: d95c6b6ea53cf84c348b2426b9bf10ad8213282f48ec9364cb9b1512aef9dd4c896d18c09c1dac79abe40f136194ab550571ac141e960eab61e4026bdbf3c578
6
+ metadata.gz: d2f844f5e4d6ec819125d1b91bd40e9af9821f32a4ca76036ccabe5beac985dc566d0cc8d9946ed1488c78115d3a64d798833d13256d829c686df1668353e314
7
+ data.tar.gz: a1bb0eabd7e81e3563e20bfb35eb0bf2044d152c0019ed78018327d6b60c4897b89a94f4fd741f077e7cb5186a82fbd7cf3c08b3340d2f1caa913b2d773adddc
data/lib/rbi/loc.rb CHANGED
@@ -15,7 +15,7 @@ module RBI
15
15
  begin_line: yarp_location.start_line,
16
16
  end_line: yarp_location.end_line,
17
17
  begin_column: yarp_location.start_column,
18
- end_column: yarp_location.end_column + 1, # TODO: Why is this off by one?
18
+ end_column: yarp_location.end_column,
19
19
  )
20
20
  end
21
21
  end
@@ -45,7 +45,11 @@ module RBI
45
45
 
46
46
  sig { returns(String) }
47
47
  def to_s
48
- "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
48
+ if end_line && end_column
49
+ "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
50
+ else
51
+ "#{file}:#{begin_line}:#{begin_column}"
52
+ end
49
53
  end
50
54
 
51
55
  sig { returns(T.nilable(String)) }
data/lib/rbi/model.rb CHANGED
@@ -353,7 +353,7 @@ module RBI
353
353
  abstract!
354
354
 
355
355
  sig { returns(T::Array[Symbol]) }
356
- attr_accessor :names
356
+ attr_reader :names
357
357
 
358
358
  sig { returns(Visibility) }
359
359
  attr_accessor :visibility
@@ -774,7 +774,7 @@ module RBI
774
774
  abstract!
775
775
 
776
776
  sig { returns(T::Array[String]) }
777
- attr_accessor :names
777
+ attr_reader :names
778
778
 
779
779
  sig do
780
780
  params(
data/lib/rbi/parser.rb CHANGED
@@ -95,7 +95,10 @@ module RBI
95
95
  def parse(source, file:)
96
96
  result = YARP.parse(source)
97
97
  unless result.success?
98
- raise ParseError.new(result.errors.map(&:message).join(" "), Loc.from_yarp(file, result.errors.first.location))
98
+ message = result.errors.map { |e| "#{e.message}." }.join(" ")
99
+ error = result.errors.first
100
+ location = Loc.new(file: file, begin_line: error.location.start_line, begin_column: error.location.start_column)
101
+ raise ParseError.new(message, location)
99
102
  end
100
103
 
101
104
  visitor = TreeBuilder.new(source, comments: result.comments, file: file)
@@ -215,7 +218,7 @@ module RBI
215
218
  TypeMember.new(
216
219
  case node
217
220
  when YARP::ConstantWriteNode
218
- node.name
221
+ node.name.to_s
219
222
  when YARP::ConstantPathWriteNode
220
223
  node_string!(node.target)
221
224
  end,
@@ -227,7 +230,7 @@ module RBI
227
230
  Const.new(
228
231
  case node
229
232
  when YARP::ConstantWriteNode
230
- node.name
233
+ node.name.to_s
231
234
  when YARP::ConstantPathWriteNode
232
235
  node_string!(node.target)
233
236
  end,
@@ -241,7 +244,7 @@ module RBI
241
244
  sig { override.params(node: YARP::DefNode).void }
242
245
  def visit_def_node(node)
243
246
  current_scope << Method.new(
244
- node.name,
247
+ node.name.to_s,
245
248
  params: parse_params(node.parameters),
246
249
  sigs: current_sigs,
247
250
  loc: node_loc(node),
@@ -336,7 +339,7 @@ module RBI
336
339
  return unless body.is_a?(YARP::StatementsNode)
337
340
 
338
341
  current_scope << TEnumBlock.new(
339
- body.body.map { |stmt| T.cast(stmt, YARP::ConstantWriteNode).name },
342
+ body.body.map { |stmt| T.cast(stmt, YARP::ConstantWriteNode).name.to_s },
340
343
  loc: node_loc(node),
341
344
  comments: node_comments(node),
342
345
  )
@@ -549,7 +552,7 @@ module RBI
549
552
  rest = node.rest
550
553
  if rest.is_a?(YARP::RestParameterNode)
551
554
  params << RestParam.new(
552
- rest.name || "*args",
555
+ rest.name&.to_s || "*args",
553
556
  loc: node_loc(rest),
554
557
  comments: node_comments(rest),
555
558
  )
@@ -561,14 +564,14 @@ module RBI
561
564
  value = param.value
562
565
  params << if value
563
566
  KwOptParam.new(
564
- param.name.delete_suffix(":"),
567
+ param.name.to_s.delete_suffix(":"),
565
568
  node_string!(value),
566
569
  loc: node_loc(param),
567
570
  comments: node_comments(param),
568
571
  )
569
572
  else
570
573
  KwParam.new(
571
- param.name.delete_suffix(":"),
574
+ param.name.to_s.delete_suffix(":"),
572
575
  loc: node_loc(param),
573
576
  comments: node_comments(param),
574
577
  )
@@ -578,7 +581,7 @@ module RBI
578
581
  rest_kw = node.keyword_rest
579
582
  if rest_kw.is_a?(YARP::KeywordRestParameterNode)
580
583
  params << KwRestParam.new(
581
- rest_kw.name || "**kwargs",
584
+ rest_kw.name&.to_s || "**kwargs",
582
585
  loc: node_loc(rest_kw),
583
586
  comments: node_comments(rest_kw),
584
587
  )
@@ -587,7 +590,7 @@ module RBI
587
590
  block = node.block
588
591
  if block.is_a?(YARP::BlockParameterNode)
589
592
  params << BlockParam.new(
590
- block.name || "&block",
593
+ block.name&.to_s || "&block",
591
594
  loc: node_loc(block),
592
595
  comments: node_comments(block),
593
596
  )
@@ -642,7 +645,7 @@ module RBI
642
645
 
643
646
  name = case node
644
647
  when YARP::ConstantWriteNode
645
- node.name
648
+ node.name.to_s
646
649
  when YARP::ConstantPathWriteNode
647
650
  node_string!(node.target)
648
651
  end
@@ -744,7 +747,7 @@ module RBI
744
747
  extend T::Sig
745
748
 
746
749
  sig { returns(Sig) }
747
- attr_accessor :current
750
+ attr_reader :current
748
751
 
749
752
  sig { params(content: String, file: String).void }
750
753
  def initialize(content, file:)
data/lib/rbi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-07 00:00:00.000000000 Z
11
+ date: 2023-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 0.11.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 0.11.0
41
41
  description:
42
42
  email:
43
43
  - ruby@shopify.com