yard-sorbet 0.2.0 → 0.3.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: e83416e1d85da291aa4d0311df2e239f14fd072f38f3f2be4ee12a008f1a89dc
4
- data.tar.gz: 3fcffa38addbaa3b47b200711462847b81bd9c52095aa1dfa46d2c077f497ef4
3
+ metadata.gz: f5a40a71c985d760b358e1a066b2b30b73a244ec47c43546dcbb476135217b6c
4
+ data.tar.gz: 74d637f5b92f95234f3feaf2ef39050bcb4379c26a735961f4f04d7a29bd7697
5
5
  SHA512:
6
- metadata.gz: 13f13c26aff10422e1fda98016fdfd1038d14a36d084653407b7797908206cde655f1504087b7ec164d6b72de2b9ded4d5f807c9c9af36d4a77e6c296828cd3d
7
- data.tar.gz: 9bb8d82770501e206ac7f1bf6f6d836c0559383b9babd0e6416180e5508bed5bd7f55e317a5c86f30231ca7cdc08b30211b722645a558d4130c4f046a39471ec
6
+ metadata.gz: f92b7ec79d46db5b9abcb3ecb294576fe02874972deeb93f23023fbfebe0bc50c9160d7f11193f93598cb07191ab4a5b3045c27ea5d0bce509fdbef5d9e99a65
7
+ data.tar.gz: 66ea5ef884b6867b1f4b80a28f5b4ee8ee8c557995be314513c43eb0886fb7a0697c01b9723d3f6a76607dc2108ddbabe7c398b5ceaec16e3693707f0b10b911
data/lib/yard-sorbet.rb CHANGED
@@ -4,8 +4,6 @@
4
4
  require 'sorbet-runtime'
5
5
  require 'yard'
6
6
 
7
- T::Configuration.default_checked_level = :tests
8
-
9
7
  # top-level namespace
10
8
  module YARDSorbet; end
11
9
 
@@ -13,3 +11,4 @@ require_relative 'yard-sorbet/directives'
13
11
  require_relative 'yard-sorbet/sig_handler'
14
12
  require_relative 'yard-sorbet/sig_to_yard'
15
13
  require_relative 'yard-sorbet/struct_handler'
14
+ require_relative 'yard-sorbet/version'
@@ -6,11 +6,19 @@ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
6
6
  extend T::Sig
7
7
  handles :class, :module, :singleton_class?
8
8
 
9
+ # A struct that holds the parsed contents of a Sorbet type signature
10
+ class ParsedSig < T::Struct
11
+ prop :abstract, T::Boolean, default: false
12
+ prop :params, T::Hash[String, T::Array[String]], default: {}
13
+ prop :return, T.nilable(T::Array[String])
14
+ end
15
+
9
16
  PARAM_EXCLUDES = T.let(%i[array call hash].freeze, T::Array[Symbol])
10
17
  PROCESSABLE_NODES = T.let(%i[def defs command].freeze, T::Array[Symbol])
11
18
  SIG_EXCLUDES = T.let(%i[array hash].freeze, T::Array[Symbol])
12
19
  SIG_NODE_TYPES = T.let(%i[call fcall vcall].freeze, T::Array[Symbol])
13
- private_constant :PARAM_EXCLUDES, :PROCESSABLE_NODES, :SIG_EXCLUDES, :SIG_NODE_TYPES
20
+
21
+ private_constant :ParsedSig, :PARAM_EXCLUDES, :PROCESSABLE_NODES, :SIG_EXCLUDES, :SIG_NODE_TYPES
14
22
 
15
23
  sig { void }
16
24
  def process
@@ -56,7 +64,7 @@ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
56
64
  enhance_tag(docstring, :abstract, parsed_sig)
57
65
  enhance_tag(docstring, :return, parsed_sig)
58
66
  if method_node.type != :command
59
- parsed_sig[:params]&.each do |name, types|
67
+ parsed_sig.params.each do |name, types|
60
68
  enhance_param(docstring, name, types)
61
69
  end
62
70
  end
@@ -77,9 +85,10 @@ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
77
85
  docstring.add_tag(tag)
78
86
  end
79
87
 
80
- sig { params(docstring: YARD::Docstring, type: Symbol, parsed_sig: T::Hash[Symbol, Object]).void }
88
+ sig { params(docstring: YARD::Docstring, type: Symbol, parsed_sig: ParsedSig).void }
81
89
  private def enhance_tag(docstring, type, parsed_sig)
82
- return if !parsed_sig[type]
90
+ type_value = parsed_sig.public_send(type)
91
+ return if !type_value
83
92
 
84
93
  tag = docstring.tags.find { |t| t.tag_name == type.to_s }
85
94
  if tag
@@ -87,33 +96,20 @@ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
87
96
  else
88
97
  tag = YARD::Tags::Tag.new(type, '')
89
98
  end
90
- if parsed_sig[type].is_a?(Array)
91
- tag.types = parsed_sig[type]
99
+ if type_value.is_a?(Array)
100
+ tag.types = type_value
92
101
  end
93
102
  docstring.add_tag(tag)
94
103
  end
95
104
 
96
- sig do
97
- params(sig_node: YARD::Parser::Ruby::MethodCallNode)
98
- .returns(
99
- {
100
- abstract: T::Boolean,
101
- params: T::Hash[String, T::Array[String]],
102
- return: T.nilable(T::Array[String])
103
- }
104
- )
105
- end
105
+ sig { params(sig_node: YARD::Parser::Ruby::MethodCallNode).returns(ParsedSig) }
106
106
  private def parse_sig(sig_node)
107
- parsed = {
108
- abstract: false,
109
- params: {},
110
- return: nil
111
- }
107
+ parsed = ParsedSig.new
112
108
  found_params = T.let(false, T::Boolean)
113
109
  found_return = T.let(false, T::Boolean)
114
110
  bfs_traverse(sig_node, exclude: SIG_EXCLUDES) do |n|
115
111
  if n.source == 'abstract'
116
- parsed[:abstract] = true
112
+ parsed.abstract = true
117
113
  elsif n.source == 'params' && !found_params
118
114
  found_params = true
119
115
  sibling = T.must(sibling_node(n))
@@ -121,14 +117,14 @@ class YARDSorbet::SigHandler < YARD::Handlers::Ruby::Base
121
117
  if p.type == :assoc
122
118
  param_name = p.children.first.source[0...-1]
123
119
  types = YARDSorbet::SigToYARD.convert(p.children.last)
124
- parsed[:params][param_name] = types
120
+ parsed.params[param_name] = types
125
121
  end
126
122
  end
127
123
  elsif n.source == 'returns' && !found_return
128
124
  found_return = true
129
- parsed[:return] = YARDSorbet::SigToYARD.convert(T.must(sibling_node(n)))
125
+ parsed.return = YARDSorbet::SigToYARD.convert(T.must(sibling_node(n)))
130
126
  elsif n.source == 'void'
131
- parsed[:return] ||= ['void']
127
+ parsed.return ||= ['void']
132
128
  end
133
129
  end
134
130
  parsed
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module YARDSorbet
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.12
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.12
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.8.0
61
+ version: 1.11.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.8.0
68
+ version: 1.11.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-performance
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.9.2
75
+ version: 1.10.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.9.2
82
+ version: 1.10.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 2.1.0
103
+ version: 2.2.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 2.1.0
110
+ version: 2.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop-sorbet
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0.21'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0.21'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sorbet
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.0.3
218
+ rubygems_version: 3.1.4
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Create YARD docs from Sorbet type signatures