orthoses-yard 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d57da650c9fa9921fe11457ff26920168316e9eb43ff101cc9aedd6472c998e5
4
- data.tar.gz: 96fab97f4f9ea79e773a5f0bd4eaf8fa5be3aac236be6819b74c89c9acf8a80f
3
+ metadata.gz: b2f6b90fd20646f14534289bd4b876eb0faf8cb4a2d422d442bcbcefd07b2069
4
+ data.tar.gz: e7283f8f85defc5ac290310d35a8a248c47fd87ef09f54c2dd65e352373bc881
5
5
  SHA512:
6
- metadata.gz: ed202e833e51fe62faf2b2c2d2554d5f14af1399dfca052f4fa38a06cda920232bcd66a46b1e2cd3b7683322527fddd6b3dbcc0504b4a99a0d996675253a33f9
7
- data.tar.gz: 4af5a24ec753a2d92371deed81de517bc558b7c30a215986f9b1b138def44d65ffaa105c6853dc757f2d2a3fd9442434d19a95c50fa227688fd186840b84442a
6
+ metadata.gz: 1796d238fbfa72d260fce28cf167ca6b0d595bc6b65faa0295e5416bd17aeec384303f8395b5aa5e3c9f8c9587ffb48cbb0a7654301ceb004be457a349a5d34b
7
+ data.tar.gz: 27a5c5c9dcfdd9d51834aa57c875c1e3600ed1a3841a930b199286624e843054a98653ff9f6e8af397fb46792136735283df49f5ed4aed4411feb14cad3b5f38
data/Gemfile.lock CHANGED
@@ -1,62 +1,74 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orthoses-yard (0.1.0)
5
- orthoses
4
+ orthoses-yard (0.3.0)
5
+ orthoses (>= 1.3.0, < 2.0)
6
6
  yard
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.4)
11
+ activesupport (7.0.4.3)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
16
  ast (2.4.2)
17
- concurrent-ruby (1.1.10)
18
- debug (1.6.2)
19
- irb (>= 1.3.6)
17
+ concurrent-ruby (1.2.2)
18
+ csv (3.2.6)
19
+ debug (1.7.1)
20
+ irb (>= 1.5.0)
20
21
  reline (>= 0.3.1)
21
22
  ffi (1.15.5)
23
+ fileutils (1.7.0)
22
24
  i18n (1.12.0)
23
25
  concurrent-ruby (~> 1.0)
24
- io-console (0.5.11)
25
- irb (1.4.1)
26
+ io-console (0.6.0)
27
+ irb (1.6.3)
26
28
  reline (>= 0.3.0)
27
- language_server-protocol (3.17.0.1)
28
- listen (3.7.1)
29
+ json (2.6.3)
30
+ language_server-protocol (3.17.0.3)
31
+ listen (3.8.0)
29
32
  rb-fsevent (~> 0.10, >= 0.10.3)
30
33
  rb-inotify (~> 0.9, >= 0.9.10)
31
- minitest (5.16.3)
32
- orthoses (1.1.0)
33
- rbs (~> 2.0)
34
+ logger (1.5.3)
35
+ minitest (5.18.0)
36
+ orthoses (1.6.0)
37
+ rbs (~> 3.0)
34
38
  parallel (1.22.1)
35
- parser (3.1.2.1)
39
+ parser (3.2.1.1)
36
40
  ast (~> 2.4.1)
37
41
  rainbow (3.1.1)
38
42
  rake (13.0.6)
39
43
  rb-fsevent (0.11.2)
40
44
  rb-inotify (0.10.1)
41
45
  ffi (~> 1.0)
42
- rbs (2.6.0)
43
- reline (0.3.1)
46
+ rbs (3.0.4)
47
+ reline (0.3.2)
44
48
  io-console (~> 0.5)
45
- rgot (1.1.0)
46
- steep (1.1.1)
49
+ rgot (1.3.0)
50
+ securerandom (0.2.2)
51
+ steep (1.3.0)
47
52
  activesupport (>= 5.1)
53
+ csv (>= 3.0.9)
54
+ fileutils (>= 1.1.0)
55
+ json (>= 2.1.0)
48
56
  language_server-protocol (>= 3.15, < 4.0)
49
57
  listen (~> 3.0)
58
+ logger (>= 1.3.0)
50
59
  parallel (>= 1.0.0)
51
60
  parser (>= 3.1)
52
61
  rainbow (>= 2.2.2, < 4.0)
53
- rbs (>= 2.3.2)
62
+ rbs (>= 2.8.0)
63
+ securerandom (>= 0.1)
64
+ strscan (>= 1.0.0)
54
65
  terminal-table (>= 2, < 4)
66
+ strscan (3.0.6)
55
67
  terminal-table (3.0.2)
56
68
  unicode-display_width (>= 1.1.1, < 3)
57
- tzinfo (2.0.5)
69
+ tzinfo (2.0.6)
58
70
  concurrent-ruby (~> 1.0)
59
- unicode-display_width (2.3.0)
71
+ unicode-display_width (2.4.2)
60
72
  webrick (1.7.0)
61
73
  yard (0.9.28)
62
74
  webrick (~> 1.7.0)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Orthoses
4
4
  class YARD
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -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
- block.call(yardoc.path, yardoc.docstring, nil)
38
+ block.call(yardoc.path, yardoc.docstring.all, nil)
39
39
  yardoc.children.each do |child|
40
40
  case child.type
41
41
  when :module, :class
@@ -45,6 +45,7 @@ module Orthoses
45
45
  generate_for_attributes
46
46
  generate_for_methods
47
47
  generate_for_constants
48
+ generate_for_classvariable
48
49
  end
49
50
 
50
51
  # @return [void]
@@ -55,15 +56,15 @@ module Orthoses
55
56
  if class_attributes[:read] && class_attributes[:write]
56
57
  visibility = class_attributes[:read].visibility == :private ? 'private ' : ''
57
58
  type = tag_types_to_rbs_type(class_attributes[:read].tags('return').flat_map(&:types))
58
- block.call(yardoc.path, class_attributes[:read].docstring, "#{visibility}attr_accessor #{prefix}#{name}: #{type}")
59
+ block.call(yardoc.path, class_attributes[:read].docstring.all, "#{visibility}attr_accessor #{prefix}#{name}: #{type}")
59
60
  elsif class_attributes[:read]
60
61
  visibility = class_attributes[:read].visibility == :private ? 'private ' : ''
61
62
  type = tag_types_to_rbs_type(class_attributes[:read].tags('return').flat_map(&:types))
62
- block.call(yardoc.path, class_attributes[:read].docstring, "#{visibility}attr_reader #{prefix}#{name}: #{type}")
63
+ block.call(yardoc.path, class_attributes[:read].docstring.all, "#{visibility}attr_reader #{prefix}#{name}: #{type}")
63
64
  elsif class_attributes[:write]
64
65
  visibility = class_attributes[:write].visibility == :private ? 'private ' : ''
65
66
  type = tag_types_to_rbs_type(class_attributes[:write].tags('return').flat_map(&:types))
66
- block.call(yardoc.path, class_attributes[:write].docstring, "#{visibility}attr_writer #{prefix}#{name}: #{type}")
67
+ block.call(yardoc.path, class_attributes[:write].docstring.all, "#{visibility}attr_writer #{prefix}#{name}: #{type}")
67
68
  else
68
69
  raise "bug"
69
70
  end
@@ -73,6 +74,8 @@ module Orthoses
73
74
 
74
75
  # @return [void]
75
76
  def generate_for_methods
77
+ return if yardoc.to_s.empty?
78
+
76
79
  yardoc.meths(inherited: false).each do |meth|
77
80
  # skip attribute methods because of generate_for_attributes
78
81
  next if meth.attr_info
@@ -82,7 +85,6 @@ module Orthoses
82
85
 
83
86
  namespace = meth.namespace
84
87
  method_name = meth.name
85
- next if namespace.to_s.empty?
86
88
 
87
89
  begin
88
90
  mod = Object.const_get(namespace.to_s)
@@ -101,6 +103,12 @@ module Orthoses
101
103
  next
102
104
  end
103
105
 
106
+ if meth.is_alias?
107
+ orig_key = yardoc.aliases[meth]
108
+ block.call(yardoc.to_s, "", "alias #{prefix}#{meth.name} #{prefix}#{orig_key}")
109
+ next
110
+ end
111
+
104
112
  required_positionals = []
105
113
  optional_positionals = []
106
114
  rest_positionals = nil
@@ -108,8 +116,6 @@ module Orthoses
108
116
  required_keywords = {}
109
117
  optional_keywords = {}
110
118
  rest_keywords = nil
111
- yield_params = []
112
- yield_return = nil
113
119
 
114
120
  requireds = required_positionals
115
121
 
@@ -194,7 +200,7 @@ module Orthoses
194
200
  )
195
201
 
196
202
  visibility = meth.visibility == :private ? 'private ' : ''
197
- block.call(yardoc.to_s, meth.docstring, "#{visibility}def #{prefix}#{method_name}: #{method_type}")
203
+ block.call(yardoc.to_s, meth.docstring.all, "#{visibility}def #{prefix}#{method_name}: #{method_type}")
198
204
  end
199
205
  end
200
206
 
@@ -203,7 +209,16 @@ module Orthoses
203
209
  yardoc.constants(inherited: false).each do |const|
204
210
  return_tags = const.tags('return')
205
211
  return_type = return_tags.empty? ? untyped : tag_types_to_rbs_type(return_tags.flat_map(&:types))
206
- block.call(const.namespace.to_s, const.docstring, "#{const.name}: #{return_type}")
212
+ block.call(const.namespace.to_s, const.docstring.all, "#{const.name}: #{return_type}")
213
+ end
214
+ end
215
+
216
+ # @return [void]
217
+ def generate_for_classvariable
218
+ yardoc.cvars.each do |cvar|
219
+ return_tags = cvar.tags('return')
220
+ return_type = return_tags.empty? ? untyped : tag_types_to_rbs_type(return_tags.flat_map(&:types))
221
+ block.call(cvar.namespace.to_s, cvar.docstring.all, "#{cvar.name}: #{return_type}")
207
222
  end
208
223
  end
209
224
 
@@ -215,6 +230,7 @@ module Orthoses
215
230
  begin
216
231
  types_explainers = ::YARD::Tags::TypesExplainer::Parser.parse(tag_types.uniq.join(", "))
217
232
  rescue SyntaxError
233
+ Orthoses.logger.warn("#{tag_types} in #{yardoc.inspect} cannot parse as tags. use untyped instead")
218
234
  return untyped
219
235
  end
220
236
 
data/lib/orthoses/yard.rb CHANGED
@@ -4,28 +4,28 @@ require_relative "yard/version"
4
4
  require_relative "yard/yard2rbs"
5
5
 
6
6
  module Orthoses
7
- # use Orthoses::YARD, globs: "lib/**/*.rb"
7
+ # use Orthoses::YARD, parse: "lib/**/*.rb"
8
8
  class YARD
9
- def initialize(loader, globs:)
9
+ def initialize(loader, parse:)
10
10
  @loader = loader
11
- @globs = Array(globs)
11
+ @parse = Array(parse)
12
12
  end
13
13
 
14
14
  def call
15
15
  @loader.call.tap do |store|
16
16
  require 'yard'
17
17
 
18
- ::YARD.parse(@globs)
18
+ ::YARD.parse(@parse)
19
19
  ::YARD::Registry.root.children.each do |yardoc|
20
20
  case yardoc.type
21
21
  when :class, :module
22
22
  YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs|
23
+ comment = docstring.each_line.map { |line| "# #{line}" }.join
23
24
  if rbs.nil?
24
- store[namespace]
25
+ store[namespace].comment = comment
25
26
  else
26
27
  Orthoses.logger.debug("#{namespace} << #{rbs}")
27
- all = docstring.all.then { |it| it.empty? ? "" : "#{it.gsub(/^/, '# ')}\n" }
28
- store[namespace] << "#{all}#{rbs}"
28
+ store[namespace] << "#{comment}\n#{rbs}"
29
29
  end
30
30
  end
31
31
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
22
  `git ls-files -z`.split("\x0").reject do |f|
23
23
  next true if (f == __FILE__)
24
- next true if f.match?(%r{\A(?:bin|known_sig)/}) # dir
24
+ next true if f.match?(%r{\A(?:bin|known_sig|examples)/}) # dir
25
25
  next true if f.match?(%r{\A\.(?:git)}) # git
26
26
  next true if f.match?(%r{\A(?:rbs_collection|Steepfile|Rakefile)}) # top file
27
27
  next true if f.match?(%r{_test\.rb\z}) # test
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency "orthoses"
35
+ spec.add_dependency "orthoses", ">= 1.3.0", "< 2.0"
36
36
  spec.add_dependency "yard"
37
37
  end
@@ -1,6 +1,6 @@
1
1
  # GENERATED FILE
2
2
 
3
3
  class Orthoses::YARD
4
- def initialize: (untyped loader, globs: untyped) -> void
4
+ def initialize: (untyped loader, parse: untyped) -> void
5
5
  VERSION: untyped
6
6
  end
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orthoses
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.3.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: 1.3.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: yard
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,12 +56,6 @@ files:
50
56
  - Gemfile.lock
51
57
  - LICENSE.txt
52
58
  - README.md
53
- - examples/yard/Gemfile
54
- - examples/yard/Gemfile.lock
55
- - examples/yard/Rakefile
56
- - examples/yard/generate.rb
57
- - examples/yard/rbs_collection.lock.yaml
58
- - examples/yard/rbs_collection.yaml
59
59
  - lib/orthoses-yard.rb
60
60
  - lib/orthoses/yard.rb
61
61
  - lib/orthoses/yard/version.rb
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.3.16
89
+ rubygems_version: 3.4.8
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Orthoses extention for YARD.
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "yard", path: "src"
6
- gem "orthoses-yard", path: "../../"
7
- gem "rake"
8
- gem "rack"
9
- gem "sord"
10
- gem "debug"
@@ -1,62 +0,0 @@
1
- PATH
2
- remote: ../..
3
- specs:
4
- orthoses-yard (0.1.0)
5
- orthoses
6
- yard
7
-
8
- PATH
9
- remote: src
10
- specs:
11
- yard (0.9.28)
12
- webrick (~> 1.7.0)
13
-
14
- GEM
15
- remote: https://rubygems.org/
16
- specs:
17
- ast (2.4.2)
18
- commander (4.6.0)
19
- highline (~> 2.0.0)
20
- debug (1.6.2)
21
- irb (>= 1.3.6)
22
- reline (>= 0.3.1)
23
- highline (2.0.3)
24
- io-console (0.5.11)
25
- irb (1.4.1)
26
- reline (>= 0.3.0)
27
- orthoses (1.1.0)
28
- rbs (~> 2.0)
29
- parlour (5.0.0)
30
- commander (~> 4.5)
31
- parser
32
- rainbow (~> 3.0)
33
- sorbet-runtime (>= 0.5)
34
- parser (3.1.2.1)
35
- ast (~> 2.4.1)
36
- rack (3.0.0)
37
- rainbow (3.1.1)
38
- rake (13.0.6)
39
- rbs (2.6.0)
40
- reline (0.3.1)
41
- io-console (~> 0.5)
42
- sorbet-runtime (0.5.10445)
43
- sord (4.0.0)
44
- commander (~> 4.5)
45
- parlour (~> 5.0)
46
- sorbet-runtime
47
- yard
48
- webrick (1.7.0)
49
-
50
- PLATFORMS
51
- arm64-darwin-21
52
-
53
- DEPENDENCIES
54
- debug
55
- orthoses-yard!
56
- rack
57
- rake
58
- sord
59
- yard!
60
-
61
- BUNDLED WITH
62
- 2.4.0.dev
@@ -1,7 +0,0 @@
1
- file :src do
2
- sh "git clone --depth 1 https://github.com/lsegal/yard.git src"
3
- end
4
-
5
- task :generate => [:src] do
6
- load 'generate.rb'
7
- end
@@ -1,71 +0,0 @@
1
- require 'orthoses-yard'
2
- require 'fileutils'
3
- require 'pathname'
4
-
5
- FileUtils.rm_rf('out')
6
- Orthoses.logger.level = :warn
7
- Orthoses::Builder.new do
8
- use Orthoses::CreateFileByName,
9
- base_dir: 'out'
10
- use Orthoses::Filter do |name, content|
11
- name.start_with?('YARD') ||
12
- name.start_with?('Ripper') ||
13
- name.start_with?('OpenStruct') ||
14
- name.start_with?('SymbolHash') ||
15
- name.start_with?('Rake') ||
16
- name.start_with?('WEBrick') ||
17
- name.start_with?('RDoc')
18
- end
19
- use Orthoses::Tap do |store|
20
- store['YARD'].header = 'module YARD'
21
- store['YARD::CodeObjects'].header = 'module YARD::CodeObjects'
22
- store['YARD::Handlers'].header = 'module YARD::Handlers'
23
- store['YARD::Handlers::C'].header = 'module YARD::Handlers::C'
24
- store['YARD::Handlers::Common'].header = 'module YARD::Handlers::Common'
25
- store['YARD::Handlers::Ruby'].header = 'module YARD::Handlers::Ruby'
26
- # TODO: support generics
27
- store['YARD::Tags::Library'] << 'def self.labels: () -> SymbolHash'
28
- end
29
- use Orthoses::YARD,
30
- globs: [
31
- 'src/lib/yard.rb',
32
- 'src/lib/yard/**/*.rb'
33
- ]
34
- use Orthoses::Autoload
35
- run -> {
36
- require 'yard'
37
- YARD::Tags::Library.define_tag("YARD Tag Signature", 'yard.signature'.to_sym, nil)
38
- YARD::Tags::Library.define_tag("YARD Tag", 'yard.tag'.to_sym, :with_types_and_name)
39
- YARD::Tags::Library.define_tag("YARD Directive", 'yard.directive'.to_sym, :with_types_and_name)
40
- # YARD::Tags::Library.visible_tags -= ['yard.tag'].map(&:to_sym)
41
- }
42
- end.call
43
-
44
- Pathname("out").join("EXTERNAL_TODO.rbs").write(<<~RBS)
45
- # !!! GENERATED CODE !!!
46
- class OpenStruct
47
- end
48
-
49
- class Ripper
50
- end
51
-
52
- module Rake
53
- class TaskLib
54
- end
55
- end
56
-
57
-
58
- module WEBrick
59
- module HTTPServlet
60
- class AbstractServlet
61
- end
62
- end
63
- end
64
-
65
- module RDoc
66
- module Markup
67
- class ToHtml
68
- end
69
- end
70
- end
71
- RBS
@@ -1,64 +0,0 @@
1
- ---
2
- sources:
3
- - name: ruby/gem_rbs_collection
4
- remote: https://github.com/ruby/gem_rbs_collection.git
5
- revision: main
6
- repo_dir: gems
7
- path: ".gem_rbs_collection"
8
- gems:
9
- - name: rbs
10
- version: 2.6.0
11
- source:
12
- type: rubygems
13
- - name: io-console
14
- version: '0'
15
- source:
16
- type: stdlib
17
- - name: orthoses
18
- version: 1.1.0
19
- source:
20
- type: rubygems
21
- - name: orthoses-yard
22
- version: 0.1.0
23
- source:
24
- type: rubygems
25
- - name: rack
26
- version: 2.2.2
27
- source:
28
- type: git
29
- name: ruby/gem_rbs_collection
30
- revision: d5d79cf5cc4df61ccb4a28f3e744ea7970cfabf9
31
- remote: https://github.com/ruby/gem_rbs_collection.git
32
- repo_dir: gems
33
- - name: logger
34
- version: '0'
35
- source:
36
- type: stdlib
37
- - name: set
38
- version: '0'
39
- source:
40
- type: stdlib
41
- - name: pathname
42
- version: '0'
43
- source:
44
- type: stdlib
45
- - name: json
46
- version: '0'
47
- source:
48
- type: stdlib
49
- - name: optparse
50
- version: '0'
51
- source:
52
- type: stdlib
53
- - name: rubygems
54
- version: '0'
55
- source:
56
- type: stdlib
57
- - name: tsort
58
- version: '0'
59
- source:
60
- type: stdlib
61
- - name: monitor
62
- version: '0'
63
- source:
64
- type: stdlib
@@ -1,12 +0,0 @@
1
- # Download sources
2
- sources:
3
- - name: ruby/gem_rbs_collection
4
- remote: https://github.com/ruby/gem_rbs_collection.git
5
- revision: main
6
- repo_dir: gems
7
-
8
- # A directory to install the downloaded RBSs
9
- path: .gem_rbs_collection
10
-
11
- gems:
12
- - name: rbs