yard-sig 0.2.0 → 0.2.2

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: 0222c39af762e8f0c74f9ab32b00810f1fef82130f7fce31055a3d213dc7004c
4
- data.tar.gz: aeaaa149c7de85e02fcc489ad8797c5d72d598d144916b5311f6e3e63fc2c437
3
+ metadata.gz: a5f0199099b90174466cf9c16956ad076ebef5c79a371eb28bd96e9f7ead2195
4
+ data.tar.gz: 1760b6025f143dc79fdb34cf48f8f4cc2779047fbfe5203e74bf5a633e4b1eaa
5
5
  SHA512:
6
- metadata.gz: d0680c7d050b65311197c39cc0bb5fe6aaf68fd696f5631c45fe08f65206805bab33d3e5786270a58bddbcc0589405d4e38be82b97b37625cd7ebdd1eabf93ce
7
- data.tar.gz: c148870b2939b3258014f22bb8309f0bacfc948ab61c57a74db8d3cd44d82e76fcb4458b020a80a59c297e264ca1cdde5e91eafc7200ab0302592b4c315b4a0a
6
+ metadata.gz: 18333b749e23f6da2ab2f6b946e8c1fce265fd1fa9c4ebbd6b108d93dd8e4226b0ef513b18e1ceafa151511a09f9e6161bc92a1067fd826fc68e4440da81de1a
7
+ data.tar.gz: 5eb6cfcc8a229cd0550bd447db8c9397578ef51f67c178d739f22af3e008d7894ed3dc85bdeedb0f888da46d0fa0cc4dbdfe32a615cca3a4709a1d08201cd7b7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.2] - 2024-01-15
4
+
5
+ - fix: support keyword arguments
6
+
7
+ ## [0.2.1] - 2024-01-08
8
+
9
+ - fix: use the hash specific syntax
10
+ - fix: support optional types
11
+ - ci: CI against ruby 3.3
12
+ - ci: upgrade actions/checkout
13
+
3
14
  ## [0.2.0] - 2023-07-07
4
15
 
5
16
  - feat: support [AaronC81/sord](https://github.com/AaronC81/sord)
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)
@@ -50,12 +54,19 @@ module YardSig
50
54
  if kind == :rest
51
55
  yard_types = "Array<#{yard_types}>"
52
56
  elsif kind == :keyrest
53
- yard_types = "Hash<Symbol, #{yard_types}>"
57
+ yard_types = "Hash{Symbol => #{yard_types}}"
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
 
@@ -81,9 +92,17 @@ module YardSig
81
92
  "Boolean"
82
93
  when RBS::Types::Bases::Instance
83
94
  @namespace.to_s
95
+ when RBS::Types::Optional
96
+ "#{to_yard_type(type.type)}, nil"
84
97
  when RBS::Types::ClassInstance
85
- args = type.args.map { |t| to_yard_type(t) }.join(", ")
86
- args.empty? ? type.to_s : "#{type.name}<#{args}>"
98
+ args = type.args.map { |t| to_yard_type(t) }
99
+ if args.empty?
100
+ type.to_s
101
+ elsif type.name.name == :Hash
102
+ "#{type.name}{#{args[0]} => #{args[1]}}"
103
+ else
104
+ "#{type.name}<#{args.join(", ")}>"
105
+ end
87
106
  else
88
107
  type.to_s
89
108
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YardSig
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.2"
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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takumi Shotoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-07 00:00:00.000000000 Z
11
+ date: 2024-01-15 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.0/CHANGELOG.md
67
- changelog_uri: https://github.com/sinsoku/yard-sig/tree/v0.2.0
66
+ source_code_uri: https://github.com/sinsoku/yard-sig/blob/v0.2.2/CHANGELOG.md
67
+ changelog_uri: https://github.com/sinsoku/yard-sig/tree/v0.2.2
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.14
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