orthoses-yard 0.4.0 → 0.6.0
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/lib/orthoses/yard/version.rb +1 -1
- data/lib/orthoses/yard/yard2rbs.rb +33 -16
- data/lib/orthoses/yard.rb +7 -4
- data/sig/orthoses.rbs +2 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d80e8c5e354b7be1e8d3e160e30093ab485a42f2a0d70460473721f93528bfa2
|
4
|
+
data.tar.gz: 19af1c287147f7da97338dbea77d17bc857a3154bab3770a09d4939c2abbaf4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11f717bb93e085083f79ac23e169d8dd02f4996faed4073d53cdb1895af039fdcc707a68326ef6459fd6e2943e622097faf5624884cfe55aaef7f5ced1ac9224
|
7
|
+
data.tar.gz: 5b6c127a6789659eff70f25fe21131dc5c7d0b3490cff6337675d60ae824f973a30252f98933f9aae2cfde76ec12b5b8daa7136616575141d81bc6ecff2537ac
|
@@ -35,7 +35,7 @@ module Orthoses
|
|
35
35
|
# @return [void]
|
36
36
|
def run
|
37
37
|
Orthoses.logger.info("YARD will generate about #{yardoc.inspect}")
|
38
|
-
|
38
|
+
emit(yardoc.path, yardoc.docstring.all, nil, false)
|
39
39
|
yardoc.children.each do |child|
|
40
40
|
case child.type
|
41
41
|
when :module, :class
|
@@ -70,6 +70,10 @@ module Orthoses
|
|
70
70
|
|
71
71
|
private
|
72
72
|
|
73
|
+
def emit(namespace, docstring, rbs, skippable)
|
74
|
+
block.call(namespace, docstring, rbs, skippable)
|
75
|
+
end
|
76
|
+
|
73
77
|
def class_of(mod)
|
74
78
|
Kernel.instance_method(:class).bind_call(mod)
|
75
79
|
end
|
@@ -82,15 +86,18 @@ module Orthoses
|
|
82
86
|
if class_attributes[:read] && class_attributes[:write]
|
83
87
|
visibility = class_attributes[:read].visibility == :private ? 'private ' : ''
|
84
88
|
type = tag_types_to_rbs_type(class_attributes[:read].tags('return').flat_map(&:types))
|
85
|
-
|
89
|
+
skippable = class_attributes[:read].tags('return').empty?
|
90
|
+
emit(yardoc.path, class_attributes[:read].docstring.all, "#{visibility}attr_accessor #{prefix}#{name}: #{type}", skippable)
|
86
91
|
elsif class_attributes[:read]
|
87
92
|
visibility = class_attributes[:read].visibility == :private ? 'private ' : ''
|
88
93
|
type = tag_types_to_rbs_type(class_attributes[:read].tags('return').flat_map(&:types))
|
89
|
-
|
94
|
+
skippable = class_attributes[:read].tags('return').empty?
|
95
|
+
emit(yardoc.path, class_attributes[:read].docstring.all, "#{visibility}attr_reader #{prefix}#{name}: #{type}", skippable)
|
90
96
|
elsif class_attributes[:write]
|
91
97
|
visibility = class_attributes[:write].visibility == :private ? 'private ' : ''
|
92
98
|
type = tag_types_to_rbs_type(class_attributes[:write].tags('return').flat_map(&:types))
|
93
|
-
|
99
|
+
skippable = class_attributes[:write].tags('return').empty?
|
100
|
+
emit(yardoc.path, class_attributes[:write].docstring.all, "#{visibility}attr_writer #{prefix}#{name}: #{type}", skippable)
|
94
101
|
else
|
95
102
|
raise "bug"
|
96
103
|
end
|
@@ -106,8 +113,8 @@ module Orthoses
|
|
106
113
|
# skip attribute methods because of generate_for_attributes
|
107
114
|
next if meth.attr_info
|
108
115
|
|
109
|
-
# skip no tags methods
|
110
|
-
|
116
|
+
# skip no type tags methods
|
117
|
+
skippable = meth.docstring.all.empty?
|
111
118
|
|
112
119
|
namespace = meth.namespace
|
113
120
|
method_name = meth.name
|
@@ -131,8 +138,7 @@ module Orthoses
|
|
131
138
|
|
132
139
|
if meth.is_alias?
|
133
140
|
orig_key = yardoc.aliases[meth]
|
134
|
-
|
135
|
-
next
|
141
|
+
emit(yardoc.to_s, "", "alias #{prefix}#{meth.name} #{prefix}#{orig_key}", false)
|
136
142
|
end
|
137
143
|
|
138
144
|
required_positionals = []
|
@@ -226,7 +232,7 @@ module Orthoses
|
|
226
232
|
)
|
227
233
|
|
228
234
|
visibility = meth.visibility == :private ? 'private ' : ''
|
229
|
-
|
235
|
+
emit(yardoc.to_s, meth.docstring.all, "#{visibility}def #{prefix}#{method_name}: #{method_type}", skippable)
|
230
236
|
end
|
231
237
|
end
|
232
238
|
|
@@ -234,8 +240,9 @@ module Orthoses
|
|
234
240
|
def generate_for_constants
|
235
241
|
yardoc.constants(inherited: false).each do |const|
|
236
242
|
return_tags = const.tags('return')
|
237
|
-
return_type =
|
238
|
-
|
243
|
+
return_type = tag_types_to_rbs_type(return_tags.flat_map(&:types))
|
244
|
+
skippable = return_tags.empty?
|
245
|
+
emit(const.namespace.to_s, const.docstring.all, "#{const.name}: #{return_type}", skippable)
|
239
246
|
end
|
240
247
|
end
|
241
248
|
|
@@ -243,8 +250,9 @@ module Orthoses
|
|
243
250
|
def generate_for_classvariable
|
244
251
|
yardoc.cvars.each do |cvar|
|
245
252
|
return_tags = cvar.tags('return')
|
246
|
-
return_type =
|
247
|
-
|
253
|
+
return_type = tag_types_to_rbs_type(return_tags.flat_map(&:types))
|
254
|
+
skippable = return_tags.empty?
|
255
|
+
emit(cvar.namespace.to_s, cvar.docstring.all, "#{cvar.name}: #{return_type}", skippable)
|
248
256
|
end
|
249
257
|
end
|
250
258
|
|
@@ -269,12 +277,21 @@ module Orthoses
|
|
269
277
|
)
|
270
278
|
end
|
271
279
|
else
|
280
|
+
name = TypeName(types_explainer_type.name)
|
281
|
+
type_params = temporary_type_params(name.to_s)
|
282
|
+
args = if 2 <= type_params.length
|
283
|
+
Orthoses.logger.warn("Cannot convert to rbs since generics mismatch. `#{name}` has #{type_params.length} generics in RBS. But YARD tag type is `#{types_explainer_type.to_s}`. Use `#{name}[#{type_params.join(', ')}]` instead.")
|
284
|
+
type_params
|
285
|
+
else
|
286
|
+
[type]
|
287
|
+
end
|
288
|
+
|
272
289
|
::RBS::Types::ClassInstance.new(
|
273
|
-
name:
|
274
|
-
args:
|
290
|
+
name: name,
|
291
|
+
args: args,
|
275
292
|
location: nil
|
276
293
|
)
|
277
|
-
|
294
|
+
end
|
278
295
|
when ::YARD::Tags::TypesExplainer::HashCollectionType
|
279
296
|
::RBS::Types::ClassInstance.new(
|
280
297
|
name: TypeName(types_explainer_type.name),
|
data/lib/orthoses/yard.rb
CHANGED
@@ -10,11 +10,13 @@ module Orthoses
|
|
10
10
|
# @param [<String>, String] parse Target files
|
11
11
|
# @param [Boolean] use_cache Use cache .yardoc
|
12
12
|
# @param [Symbol, nil] log_level Set YARD log level
|
13
|
-
|
13
|
+
# @param [Boolean] allow_empty_doc Generate RBS also from empty doc
|
14
|
+
def initialize(loader, parse:, use_cache: true, log_level: nil, allow_empty_doc: false)
|
14
15
|
@loader = loader
|
15
16
|
@parse = Array(parse)
|
16
17
|
@use_cache = use_cache
|
17
18
|
@log_level = log_level
|
19
|
+
@allow_empty_doc = allow_empty_doc
|
18
20
|
end
|
19
21
|
|
20
22
|
# @return [void]
|
@@ -36,13 +38,14 @@ module Orthoses
|
|
36
38
|
|
37
39
|
case yardoc.type
|
38
40
|
when :class, :module
|
39
|
-
YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs|
|
40
|
-
|
41
|
+
YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs, skippable|
|
42
|
+
next if skippable && !@allow_empty_doc
|
43
|
+
comment = docstring.empty? ? '' : "# #{docstring.gsub("\n", "\n# ")}"
|
41
44
|
if rbs.nil? && comment && !store.has_key?(namespace)
|
42
45
|
store[namespace].comment = comment
|
43
46
|
else
|
44
47
|
Orthoses.logger.debug("#{namespace} << #{rbs}")
|
45
|
-
store[namespace] << "#{comment}\n#{rbs}"
|
48
|
+
store[namespace] << "#{comment.chomp}\n#{rbs}"
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
data/sig/orthoses.rbs
CHANGED
@@ -6,10 +6,10 @@ class Orthoses::YARD
|
|
6
6
|
# @param [<String>, String] parse Target files
|
7
7
|
# @param [Boolean] use_cache Use cache .yardoc
|
8
8
|
# @param [Symbol, nil] log_level Set YARD log level
|
9
|
-
|
9
|
+
# @param [Boolean] allow_empty_doc Generate RBS also from empty doc
|
10
|
+
def initialize: (untyped loader, parse: Array[String] | String, ?use_cache: bool, ?log_level: Symbol?, ?allow_empty_doc: bool) -> void
|
10
11
|
# @return [void]
|
11
12
|
def call: () -> void
|
12
|
-
VERSION: untyped
|
13
13
|
end
|
14
14
|
|
15
15
|
class Orthoses::YARD::YARD2RBS
|
@@ -23,7 +23,6 @@ class Orthoses::YARD::YARD2RBS
|
|
23
23
|
attr_reader void: RBS::Types::Bases::Void
|
24
24
|
# @return [RBS::Types::Bases::Bool]
|
25
25
|
attr_reader bool: RBS::Types::Bases::Bool
|
26
|
-
def initialize: (yardoc: untyped, block: untyped) -> void
|
27
26
|
# @return [void]
|
28
27
|
def run: () -> void
|
29
28
|
# @return [RBS::Types::t]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthoses-yard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: orthoses
|