yard-sorbet 0.8.1 → 0.9.0

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: 9b9dcb968aabdaa21a4f1eb74d7a0800e156fda50609b9e4df209795fe4f353f
4
- data.tar.gz: bd98ccbde56a8fbb8a3d1058c64047b3ff0111912684dd454cf71f016abc5c88
3
+ metadata.gz: 1421bf5c36984eb95f6d05e83900bdc9599a052fa51edb2939cf9dc656f5722b
4
+ data.tar.gz: 3922ad972509e1bfb185903ff40dfce5952fca881ea4196f7c8c2f37a572ae24
5
5
  SHA512:
6
- metadata.gz: c42c6277c2ebe6eac00e8bad6c68528d23aa1066ce23d79276a8dce062a064f8dcda87c77eff00ace7d125685a503b17c62357c50b59212b1507cb5880db5d26
7
- data.tar.gz: 8209d82a15513c42d1d3371be854a7d2d63989e0c1552eb53e34b87aba6578cca8caf4f46a439474df193dd28951872fbed2af72ff63065a8b17adf8d4969614
6
+ metadata.gz: 2a7531bf6292ee4d37d5257ce851d62a9738c8f9319595f5c638b30e9a0cb324980b5fa3608b6b45da1e7fa9940323e7e31cbab9621957e8b0addab86020f11c
7
+ data.tar.gz: 365dac401f8792a0841496ccb07a3b08ee5d88d5f1de29a38312094eddc659f6fc6b9b087032e11fa862a482c6d30dc2069244aa060719eb81666d5358b7d5d3
@@ -18,8 +18,6 @@ module YARDSorbet
18
18
  end
19
19
 
20
20
  sig { params(docstring: String, directives: T::Array[String]).void }
21
- def self.add_directives(docstring, directives)
22
- directives.each { docstring.concat("\n#{_1}") }
23
- end
21
+ def self.add_directives(docstring, directives) = directives.each { docstring.concat("\n#{_1}") }
24
22
  end
25
23
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module YARDSorbet
5
5
  module Handlers
6
- # Apllies an `@abstract` tag to `abstract!`/`interface!` modules (if not alerady present).
6
+ # Applies an `@abstract` tag to `abstract!`/`interface!` modules (if not alerady present).
7
7
  class AbstractDSLHandler < YARD::Handlers::Ruby::Base
8
8
  extend T::Sig
9
9
 
@@ -15,7 +15,7 @@ module YARDSorbet
15
15
  # The `@abstract` tag template
16
16
  TAG_TEXT = 'Subclasses must implement the `abstract` methods below.'
17
17
  # Extra text for class namespaces
18
- CLASS_TAG_TEXT = T.let("It cannot be directly instantiated. #{TAG_TEXT}", String)
18
+ CLASS_TAG_TEXT = T.let("It cannot be directly instantiated. #{TAG_TEXT}".freeze, String)
19
19
 
20
20
  sig { void }
21
21
  def process
@@ -26,9 +26,7 @@ module YARDSorbet
26
26
  private
27
27
 
28
28
  sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Boolean) }
29
- def const_assign_node?(node)
30
- node.type == :assign && node[0][0].type == :const
31
- end
29
+ def const_assign_node?(node) = node.type == :assign && node[0][0].type == :const
32
30
  end
33
31
  end
34
32
  end
@@ -15,9 +15,7 @@ module YARDSorbet
15
15
  @@mix_in_class_methods = T.let({}, T::Hash[String, T::Array[String]]) # rubocop:disable Style/ClassVars
16
16
 
17
17
  sig { params(code_obj: String).returns(T.nilable(T::Array[String])) }
18
- def self.mixed_in_class_methods(code_obj)
19
- @@mix_in_class_methods[code_obj]
20
- end
18
+ def self.mixed_in_class_methods(code_obj) = @@mix_in_class_methods[code_obj]
21
19
 
22
20
  sig { void }
23
21
  def process
@@ -64,21 +64,19 @@ module YARDSorbet
64
64
  attrs = namespace.attributes[scope][names[0]]
65
65
  return false if attrs.nil? || attrs.empty?
66
66
 
67
- document_attr_methods(attrs.values.compact)
67
+ document_attrs(attrs.values.compact)
68
68
  attr_node.docstring = nil
69
69
  true
70
70
  end
71
71
 
72
72
  sig { params(method_objects: T::Array[YARD::CodeObjects::MethodObject]).void }
73
- def document_attr_methods(method_objects)
74
- method_objects.each { parse_node(_1, _1.docstring, include_params: false) }
75
- end
73
+ def document_attrs(method_objects) = method_objects.each { parse_node(_1, _1.docstring, include_params: false) }
76
74
 
77
75
  sig { params(attach_to: Documentable, docstring: T.nilable(String), include_params: T::Boolean).void }
78
76
  def parse_node(attach_to, docstring, include_params: true)
79
77
  existing_docstring = docstring.is_a?(YARD::Docstring)
80
78
  docstring, directives = Directives.extract_directives(docstring) unless existing_docstring
81
- parse_sig(docstring, include_params: include_params)
79
+ parse_sig(docstring, include_params:)
82
80
  attach_to.docstring = docstring.to_raw
83
81
  Directives.add_directives(attach_to.docstring, directives) unless existing_docstring
84
82
  end
@@ -35,15 +35,11 @@ module YARDSorbet
35
35
  end
36
36
 
37
37
  sig { returns(T::Boolean) }
38
- def immutable?
39
- statement.method_name(true) == :const || kw_arg('immutable:') == 'true'
40
- end
38
+ def immutable? = statement.method_name(true) == :const || kw_arg('immutable:') == 'true'
41
39
 
42
40
  # @return the value passed to the keyword argument, or nil
43
41
  sig { params(kwd: String).returns(T.nilable(String)) }
44
- def kw_arg(kwd)
45
- params[2]&.find { _1[0].source == kwd }&.[](1)&.source
46
- end
42
+ def kw_arg(kwd) = params[2]&.find { _1[0].source == kwd }&.[](1)&.source
47
43
 
48
44
  sig { params(name: String).returns(TStructProp) }
49
45
  def make_prop(name)
@@ -57,16 +53,14 @@ module YARDSorbet
57
53
  end
58
54
 
59
55
  sig { returns(T::Array[YARD::Parser::Ruby::AstNode]) }
60
- def params
61
- @params ||= T.let(statement.parameters(false), T.nilable(T::Array[YARD::Parser::Ruby::AstNode]))
62
- end
56
+ def params = @params ||= T.let(statement.parameters(false), T.nilable(T::Array[YARD::Parser::Ruby::AstNode]))
63
57
 
64
58
  # Register the field explicitly as an attribute.
65
59
  sig { params(object: YARD::CodeObjects::MethodObject, name: String).void }
66
60
  def register_attrs(object, name)
67
61
  write = immutable? ? nil : object
68
62
  # Create the virtual attribute in our current scope
69
- namespace.attributes[scope][name] ||= SymbolHash[read: object, write: write]
63
+ namespace.attributes[scope][name] ||= SymbolHash[read: object, write:]
70
64
  end
71
65
 
72
66
  # Store the prop for use in the constructor definition
@@ -19,25 +19,33 @@ module YARDSorbet
19
19
  # @yield [YARD::Parser::Ruby::AstNode]
20
20
  sig { params(node: YARD::Parser::Ruby::AstNode, _blk: T.proc.params(n: YARD::Parser::Ruby::AstNode).void).void }
21
21
  def self.bfs_traverse(node, &_blk)
22
- queue = [node]
22
+ queue = Queue.new << node
23
23
  until queue.empty?
24
- n = T.must(queue.shift)
24
+ n = queue.deq(true)
25
25
  yield n
26
- n.children.each { queue.push(_1) }
27
- queue.pop if n.is_a?(YARD::Parser::Ruby::MethodCallNode) && SKIP_METHOD_CONTENTS.include?(n.method_name(true))
26
+ enqueue_children(queue, n)
28
27
  end
29
28
  end
30
29
 
31
30
  sig { params(node: YARD::Parser::Ruby::AstNode).void }
32
- def self.delete_node(node)
33
- node.parent.children.delete(node)
31
+ def self.delete_node(node) = node.parent.children.delete(node)
32
+
33
+ # Enqueue the eligible children of a node in the BFS queue
34
+ sig { params(queue: Queue, node: YARD::Parser::Ruby::AstNode).void }
35
+ def self.enqueue_children(queue, node)
36
+ last_child = node.children.last
37
+ node.children.each do |child|
38
+ next if child == last_child &&
39
+ node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
40
+ SKIP_METHOD_CONTENTS.include?(node.method_name(true))
41
+
42
+ queue.enq(child)
43
+ end
34
44
  end
35
45
 
36
46
  # Gets the node that a sorbet `sig` can be attached do, bypassing visisbility modifiers and the like
37
47
  sig { params(node: YARD::Parser::Ruby::AstNode).returns(SigableNode) }
38
- def self.get_method_node(node)
39
- sigable_node?(node) ? node : node.jump(:def, :defs)
40
- end
48
+ def self.get_method_node(node) = sigable_node?(node) ? node : node.jump(:def, :defs)
41
49
 
42
50
  # Find and return the adjacent node (ascending)
43
51
  # @raise [IndexError] if the node does not have an adjacent sibling (ascending)
@@ -10,8 +10,8 @@ module YARDSorbet
10
10
  # Map of common types to YARD conventions (in order to reduce allocations)
11
11
  REF_TYPES = T.let({
12
12
  'T::Boolean' => ['Boolean'].freeze, # YARD convention for booleans
13
- # YARD convention is use singleton objects when applicable:
14
- # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#Literals
13
+ # YARD convention is to use singleton objects when applicable:
14
+ # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#literals
15
15
  'FalseClass' => ['false'].freeze,
16
16
  'NilClass' => ['nil'].freeze,
17
17
  'TrueClass' => ['true'].freeze
@@ -20,10 +20,7 @@ module YARDSorbet
20
20
 
21
21
  # @see https://yardoc.org/types.html
22
22
  sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Array[String]) }
23
- def convert(node)
24
- # scrub newlines, as they break the YARD parser
25
- convert_node(node).map { _1.gsub(/\n\s*/, ' ') }
26
- end
23
+ def convert(node) = convert_node(node).map { _1.gsub(/\n\s*/, ' ') }
27
24
 
28
25
  private
29
26
 
@@ -68,7 +65,7 @@ module YARDSorbet
68
65
 
69
66
  sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Array[String]) }
70
67
  def convert_aref(node)
71
- # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#Parametrized_Types
68
+ # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#parametrized-types
72
69
  case node.first.source
73
70
  when 'T::Array', 'T::Enumerable', 'T::Range', 'T::Set' then convert_collection(node)
74
71
  when 'T::Hash' then convert_hash(node)
@@ -80,10 +77,10 @@ module YARDSorbet
80
77
 
81
78
  sig { params(node: YARD::Parser::Ruby::AstNode).returns([String]) }
82
79
  def convert_array(node)
83
- # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#Order-Dependent_Lists
80
+ # https://www.rubydoc.info/gems/yard/file/docs/Tags.md#order-dependent-lists
84
81
  member_types = node.first.children.map { convert_node(_1) }
85
82
  sequence = member_types.map { _1.size == 1 ? _1[0] : _1.to_s.tr('"', '') }.join(', ')
86
- ["Array(#{sequence})"]
83
+ ["Array<(#{sequence})>"]
87
84
  end
88
85
 
89
86
  sig { params(node: YARD::Parser::Ruby::AstNode).returns([String]) }
@@ -13,9 +13,7 @@ module YARDSorbet
13
13
  sig do
14
14
  params(docstring: YARD::Docstring, tag_name: String, name: T.nilable(String)).returns(T.nilable(YARD::Tags::Tag))
15
15
  end
16
- def self.find_tag(docstring, tag_name, name)
17
- docstring.tags.find { _1.tag_name == tag_name && _1.name == name }
18
- end
16
+ def self.find_tag(docstring, tag_name, name) = docstring.tags.find { _1.tag_name == tag_name && _1.name == name }
19
17
 
20
18
  # Create or update a `YARD` tag with type information
21
19
  sig do
@@ -4,5 +4,5 @@
4
4
  # Types are documentation
5
5
  module YARDSorbet
6
6
  # {https://rubygems.org/gems/yard-sorbet Version history}
7
- VERSION = '0.8.1'
7
+ VERSION = '0.9.0'
8
8
  end
metadata CHANGED
@@ -1,211 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas Eichelberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-03 00:00:00.000000000 Z
11
+ date: 2024-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler-audit
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.9.1
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.9.1
27
- - !ruby/object:Gem::Dependency
28
- name: codecov
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.6.0
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.6.0
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: redcarpet
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.5'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.10'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.10'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 1.49.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 1.49.0
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-performance
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.16.0
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.16.0
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop-rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 0.6.0
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 0.6.0
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 2.19.0
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 2.19.0
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop-sorbet
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: 0.7.0
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: 0.7.0
153
- - !ruby/object:Gem::Dependency
154
- name: sorbet
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 0.5.9204
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 0.5.9204
167
- - !ruby/object:Gem::Dependency
168
- name: tapioca
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.11.1
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.11.1
181
13
  - !ruby/object:Gem::Dependency
182
14
  name: sorbet-runtime
183
15
  requirement: !ruby/object:Gem::Requirement
184
16
  requirements:
185
17
  - - ">="
186
18
  - !ruby/object:Gem::Version
187
- version: '0.5'
19
+ version: '0'
188
20
  type: :runtime
189
21
  prerelease: false
190
22
  version_requirements: !ruby/object:Gem::Requirement
191
23
  requirements:
192
24
  - - ">="
193
25
  - !ruby/object:Gem::Version
194
- version: '0.5'
26
+ version: '0'
195
27
  - !ruby/object:Gem::Dependency
196
28
  name: yard
197
29
  requirement: !ruby/object:Gem::Requirement
198
30
  requirements:
199
31
  - - ">="
200
32
  - !ruby/object:Gem::Version
201
- version: '0.9'
33
+ version: '0'
202
34
  type: :runtime
203
35
  prerelease: false
204
36
  version_requirements: !ruby/object:Gem::Requirement
205
37
  requirements:
206
38
  - - ">="
207
39
  - !ruby/object:Gem::Version
208
- version: '0.9'
40
+ version: '0'
209
41
  description: A YARD plugin that incorporates Sorbet type information
210
42
  email: dduugg@gmail.com
211
43
  executables: []
@@ -248,14 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
80
  requirements:
249
81
  - - ">="
250
82
  - !ruby/object:Gem::Version
251
- version: 2.7.0
83
+ version: '3.1'
252
84
  required_rubygems_version: !ruby/object:Gem::Requirement
253
85
  requirements:
254
86
  - - ">="
255
87
  - !ruby/object:Gem::Version
256
88
  version: '0'
257
89
  requirements: []
258
- rubygems_version: 3.2.33
90
+ rubygems_version: 3.3.7
259
91
  signing_key:
260
92
  specification_version: 4
261
93
  summary: Create YARD docs from Sorbet type signatures