yard-sig 0.2.1 → 0.2.3

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: a8a30d8e37b42f9db474cacba8fe768ae90129eb452cedaa105de1a28995a415
4
- data.tar.gz: b5ef51eedc71a75d8875f392e93f09f11257b7f91ad88222ee28df64dd9bf7df
3
+ metadata.gz: 7ab2bf52e54c80a38edafd9ddbd34e0c1238e26001b582e828cecbd44b7fde2a
4
+ data.tar.gz: 88be629986e49ae4d1d4fcb2a1555f2dcce9828664a9fbdc860ae4433d8240e2
5
5
  SHA512:
6
- metadata.gz: cebe6a8c8697513117acd7080217942cd4320549466a710f780b5f38f0d3d57652121eff85b435d463168f9fed75ddba67b575b25845de311a812abfe3d0891c
7
- data.tar.gz: eb84fde03e6b369e4445cb31ae5348149da6eaf43952084036b5601045b88cb404f80308315091149247627631e6a3ce23da7dbb4a08aeee1c08a4a9b70fca6f
6
+ metadata.gz: 6f363d438620ae79fd852525a0ff3e8f3bd30adff94799d3a4e3a6aaae6e7e335d1a4357d212b1a5eae11021ab7953edf8b7c795356826300cedf2a81b0e7160
7
+ data.tar.gz: ccd484cc3b40d4335747946b799eb9d2796a75304a4435fa8128d1ee0b9d29505d2411cc1e91dce954a33b44895a20119e892d508c630dfa0279543f5845e2f6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.3] - 2024-02-07
4
+
5
+ - fix: fix invalid tags when specifying multiple types
6
+
7
+ ## [0.2.2] - 2024-01-15
8
+
9
+ - fix: support keyword arguments
10
+
3
11
  ## [0.2.1] - 2024-01-08
4
12
 
5
13
  - fix: use the hash specific syntax
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Gem Version](https://badge.fury.io/rb/yard-sig.svg)](https://badge.fury.io/rb/yard-sig)
2
+ [![test](https://github.com/sinsoku/yard-sig/actions/workflows/test.yml/badge.svg)](https://github.com/sinsoku/yard-sig/actions/workflows/test.yml)
3
+
1
4
  # yard-sig
2
5
 
3
6
  A YARD plugin for writing documentations with [RBS syntax](https://github.com/ruby/rbs).
data/lib/yard-sig/sig.rb CHANGED
@@ -25,12 +25,16 @@ module YardSig
25
25
  @rbs_method_type ||= RBS::Parser.parse_method_type(@source)
26
26
  end
27
27
 
28
- def rbs_type_to_tags(rbs_type, within_block: false)
28
+ def rbs_type_to_tags(rbs_type, within_block: false) # rubocop:disable Metrics/AbcSize
29
29
  positionals = rbs_type.required_positionals + rbs_type.optional_positionals
30
30
 
31
31
  tags = positionals.map.with_index do |param, i|
32
32
  build_param_tag(param, :positionals, pos: i, within_block: within_block)
33
33
  end
34
+
35
+ tags += rbs_type.required_keywords.map { |name, type| build_param_tag_for_keyword(name, type) }
36
+ tags += rbs_type.optional_keywords.map { |name, type| build_param_tag_for_keyword(name, type) }
37
+
34
38
  tags << build_param_tag(rbs_type.rest_positionals, :rest, within_block: within_block)
35
39
  tags << build_param_tag(rbs_type.rest_keywords, :keyrest, within_block: within_block)
36
40
  tags << build_return_tag(rbs_type.return_type, within_block: within_block)
@@ -48,14 +52,21 @@ module YardSig
48
52
  name = type.name ? type.name.to_s : find_name_from_yard(kind, pos)
49
53
 
50
54
  if kind == :rest
51
- yard_types = "Array<#{yard_types}>"
55
+ yard_types = "Array<#{yard_types.join(", ")}>"
52
56
  elsif kind == :keyrest
53
- yard_types = "Hash{Symbol => #{yard_types}}"
57
+ yard_types = "Hash{Symbol => #{yard_types.join(", ")}}"
54
58
  end
55
59
 
56
60
  YARD::Tags::Tag.new(tag_name, "", yard_types, name)
57
61
  end
58
62
 
63
+ def build_param_tag_for_keyword(name, type)
64
+ yard_types = to_yard_type(type.type)
65
+ return unless yard_types
66
+
67
+ YARD::Tags::Tag.new(:param, "", yard_types, name.to_s)
68
+ end
69
+
59
70
  def build_return_tag(type, within_block: false)
60
71
  return unless type
61
72
 
@@ -71,29 +82,31 @@ module YardSig
71
82
  when RBS::Types::Bases::Void, RBS::Types::Bases::Any, RBS::Types::Bases::Bottom
72
83
  nil
73
84
  when RBS::Types::Bases::Top
74
- "Object"
85
+ ["Object"]
75
86
  when RBS::Types::Union
76
- type.types.map { |t| to_yard_type(t) }.join(", ")
87
+ type.types.map { |t| to_yard_type(t) }
77
88
  when RBS::Types::Tuple
78
89
  args = type.types.map { |t| to_yard_type(t) }.join(", ")
79
- "Array[#{args}]"
90
+ ["Array[#{args}]"]
80
91
  when RBS::Types::Bases::Bool
81
- "Boolean"
92
+ ["Boolean"]
82
93
  when RBS::Types::Bases::Instance
83
- @namespace.to_s
94
+ [@namespace.to_s]
84
95
  when RBS::Types::Optional
85
- "#{to_yard_type(type.type)}, nil"
96
+ [to_yard_type(type.type).join(", ").to_s, "nil"]
86
97
  when RBS::Types::ClassInstance
87
98
  args = type.args.map { |t| to_yard_type(t) }
88
99
  if args.empty?
89
- type.to_s
100
+ [type.to_s]
90
101
  elsif type.name.name == :Hash
91
- "#{type.name}{#{args[0]} => #{args[1]}}"
102
+ key = args[0].join(", ")
103
+ value = args[1].join(", ")
104
+ ["#{type.name}{#{key} => #{value}}"]
92
105
  else
93
- "#{type.name}<#{args.join(", ")}>"
106
+ ["#{type.name}<#{args.join(", ")}>"]
94
107
  end
95
108
  else
96
- type.to_s
109
+ [type.to_s]
97
110
  end
98
111
  end
99
112
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YardSig
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-sig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takumi Shotoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbs
@@ -63,8 +63,8 @@ licenses:
63
63
  - MIT
64
64
  metadata:
65
65
  homepage_uri: https://github.com/sinsoku/yard-sig
66
- source_code_uri: https://github.com/sinsoku/yard-sig/blob/v0.2.1/CHANGELOG.md
67
- changelog_uri: https://github.com/sinsoku/yard-sig/tree/v0.2.1
66
+ source_code_uri: https://github.com/sinsoku/yard-sig/blob/v0.2.3/CHANGELOG.md
67
+ changelog_uri: https://github.com/sinsoku/yard-sig/tree/v0.2.3
68
68
  post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.4.19
83
+ rubygems_version: 3.6.0.dev
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: A YARD plugin for writing documentations with RBS syntax