rbs-trace 0.5.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffa35a17dce6177b82270290080a095b19ee61015245ce8d64621990b7634635
4
- data.tar.gz: c6ec9bb2c2387b4c421e03bab6d3aec654eff71e1d814c680027952ccd4d6805
3
+ metadata.gz: 8a25eb287a611f0c087e0419da03b0d45b53735e3e1bfa9bbcf9018940f640a1
4
+ data.tar.gz: 70591151052c0e0695b3584b31551e0251987f8cc9b5c5c635db741d4b44c0d9
5
5
  SHA512:
6
- metadata.gz: cfabe32a33ba27850b286c2a6ab5bbf33d382dea09cfb6e6bc828d9c3aac949b644ad9cd8afbbc2bbc3f3c873c6200ccb9743f7ee04143ec3eb38ff2eb35f382
7
- data.tar.gz: 4dbdea59fdf5711777c5a3b9ed5e07e8420c901fe6a156d9e710e31227c437220001974e848c678adef096aef279a277b2679c11329ae7f32c43841b65649edb
6
+ metadata.gz: f3fd0ae96dc471248170fd72d639fc338026e7ecba577db2d3be8096652c9e28e9df4a1cf9c012a976da6951dcb0bbbcb12444d029206f9ac3384b9374538165
7
+ data.tar.gz: 204295de73d9fee188d8c5568546b09bd295173937b9037f1e957f7a4b2952af502b2a58ce2fc01927e29bdeeb866e8950d3b9549cf3f4960759e94d745f5a2f
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-rake
3
3
  - rubocop-rspec
4
4
  - rubocop-performance
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.0] - 2025-05-12
4
+
5
+ - feat: Support inline comments using colon-prefixed RBS syntax
6
+ - chore: Update gem dependencies
7
+
3
8
  ## [0.5.1] - 2025-04-20
4
9
 
5
10
  - fix: Support nested modules defined with `::`
data/README.md CHANGED
@@ -114,6 +114,25 @@ end
114
114
  RBS::Trace.new(paths: Dir.glob("#{Dir.pwd}/app/models/**/*.rb"))
115
115
  ```
116
116
 
117
+ ### Change the format of embedded comments
118
+
119
+ You can change the comment format.
120
+
121
+ | `comment_format` | embedded comment |
122
+ |---|---|
123
+ | `:rbs_keyword` (default) | `# @rbs () -> void` |
124
+ | `:rbs_colon` | `#: () -> void` |
125
+
126
+ ```ruby
127
+ trace.save_comments(:rbs_colon)
128
+ ```
129
+
130
+ or
131
+
132
+ ```bash
133
+ $ rbs-trace inline --rb-dir=app --rb-dir=lib --comment-format=rbs_colon
134
+ ```
135
+
117
136
  ### Save RBS declarations as files
118
137
 
119
138
  ```ruby
@@ -5,7 +5,7 @@ module RBS
5
5
  class CLI
6
6
  class Inline
7
7
  BANNER = <<~USAGE
8
- Usage: rbs-trace inline --sig-dir=DIR --rb-dir=DIR
8
+ Usage: rbs-trace inline --sig-dir=DIR --rb-dir=DIR --comment-format=FORMAT
9
9
 
10
10
  Insert RBS inline comments from RBS files.
11
11
 
@@ -14,16 +14,19 @@ module RBS
14
14
  $ rbs-trace inline --sig-dir=sig --rb-dir=app
15
15
 
16
16
  Options:
17
+ --comment-format FORMAT: Format for comments (`rbs_keyword` or `rbs_colon`, default: `rbs_keyword`)
17
18
  USAGE
18
19
 
19
20
  # @rbs (Array[String]) -> void
20
21
  def run(args) # rubocop:disable Metrics
21
22
  sig_dir = Pathname.pwd.join("sig").to_s
22
23
  rb_dirs = [] #: Array[String]
24
+ comment_format = :rbs_keyword
23
25
 
24
26
  opts = OptionParser.new(BANNER)
25
27
  opts.on("--sig-dir DIR") { |dir| sig_dir = dir }
26
28
  opts.on("--rb-dir DIR") { |dir| rb_dirs << dir }
29
+ opts.on("--comment-format FORMAT") { |format| comment_format = format.to_sym }
27
30
  opts.parse!(args)
28
31
 
29
32
  if rb_dirs.empty?
@@ -35,7 +38,7 @@ module RBS
35
38
  rb_files = rb_dirs.flat_map { |rb_dir| Dir.glob("#{rb_dir}/**/*.rb") }
36
39
  rb_files.each do |path|
37
40
  file = File.new(path, decls)
38
- file.rewrite
41
+ file.rewrite(comment_format)
39
42
  end
40
43
  end
41
44
  end
@@ -27,11 +27,11 @@ module RBS
27
27
  end
28
28
  end
29
29
 
30
- # @rbs () -> String
31
- def with_rbs
30
+ # @rbs (?Symbol?) -> String
31
+ def with_rbs(comment_format = nil)
32
32
  result = Prism.parse_file(@path)
33
33
  comments = {} #: Hash[Integer, String]
34
- result.value.accept(InlineCommentVisitor.new(@decls, comments))
34
+ result.value.accept(InlineCommentVisitor.new(@decls, comments, comment_format))
35
35
 
36
36
  lines = result.source.source.lines
37
37
  comments.keys.sort.reverse_each do |i|
@@ -42,9 +42,9 @@ module RBS
42
42
  lines.join
43
43
  end
44
44
 
45
- # @rbs () -> void
46
- def rewrite
47
- ::File.write(@path, with_rbs)
45
+ # @rbs (?Symbol?) -> void
46
+ def rewrite(comment_format = nil)
47
+ ::File.write(@path, with_rbs(comment_format))
48
48
  end
49
49
 
50
50
  # @rbs () -> String
@@ -3,10 +3,11 @@
3
3
  module RBS
4
4
  class Trace
5
5
  class InlineCommentVisitor < Prism::Visitor
6
- # @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
7
- def initialize(decls, comments)
6
+ # @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
7
+ def initialize(decls, comments, comment_format)
8
8
  @decls = decls
9
9
  @comments = comments
10
+ @comment_prefix = comment_format == :rbs_colon ? "#:" : "# @rbs"
10
11
  @context = [] #: Array[Symbol]
11
12
 
12
13
  super()
@@ -38,7 +39,7 @@ module RBS
38
39
  overloads = OverloadCompact.new(member.overloads).call
39
40
  comment = overloads.map(&:method_type).join(" | ")
40
41
 
41
- @comments[lineno] = "#{indent}# @rbs #{comment}\n"
42
+ @comments[lineno] = "#{indent}#{@comment_prefix} #{comment}\n"
42
43
  end
43
44
 
44
45
  super
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  class Trace
5
- VERSION = "0.5.1"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
data/lib/rbs/trace.rb CHANGED
@@ -50,10 +50,10 @@ module RBS
50
50
  @files ||= {}
51
51
  end
52
52
 
53
- # @rbs () -> void
54
- def save_comments
53
+ # @rbs (?Symbol) -> void
54
+ def save_comments(comment_format = nil)
55
55
  files.each do |path, file|
56
- file.rewrite if @paths.include?(path)
56
+ file.rewrite(comment_format) if @paths.include?(path)
57
57
  end
58
58
  end
59
59
 
@@ -6,7 +6,7 @@ gems:
6
6
  source:
7
7
  type: git
8
8
  name: ruby/gem_rbs_collection
9
- revision: ccbd2bbc6be5c195df1d90aa68d64916a9e7d0ab
9
+ revision: 1e026936df951c269b64b7cba278132b0af42828
10
10
  remote: https://github.com/ruby/gem_rbs_collection.git
11
11
  repo_dir: gems
12
12
  - name: fileutils
@@ -42,17 +42,25 @@ gems:
42
42
  source:
43
43
  type: git
44
44
  name: ruby/gem_rbs_collection
45
- revision: ccbd2bbc6be5c195df1d90aa68d64916a9e7d0ab
45
+ revision: 1e026936df951c269b64b7cba278132b0af42828
46
46
  remote: https://github.com/ruby/gem_rbs_collection.git
47
47
  repo_dir: gems
48
48
  - name: rbs
49
- version: 3.8.1
49
+ version: 3.9.3
50
50
  source:
51
51
  type: rubygems
52
52
  - name: rdoc
53
53
  version: '0'
54
54
  source:
55
55
  type: stdlib
56
+ - name: simplecov
57
+ version: '0.22'
58
+ source:
59
+ type: git
60
+ name: ruby/gem_rbs_collection
61
+ revision: 1e026936df951c269b64b7cba278132b0af42828
62
+ remote: https://github.com/ruby/gem_rbs_collection.git
63
+ repo_dir: gems
56
64
  - name: tsort
57
65
  version: '0'
58
66
  source:
@@ -11,11 +11,11 @@ module RBS
11
11
  # @rbs (untyped, Class, Symbol) -> AST::Members::MethodDefinition?
12
12
  def find_or_new_method_definition: (untyped, Class, Symbol) -> AST::Members::MethodDefinition?
13
13
 
14
- # @rbs () -> String
15
- def with_rbs: () -> String
14
+ # @rbs (?Symbol?) -> String
15
+ def with_rbs: (?Symbol?) -> String
16
16
 
17
- # @rbs () -> void
18
- def rewrite: () -> void
17
+ # @rbs (?Symbol?) -> void
18
+ def rewrite: (?Symbol?) -> void
19
19
 
20
20
  # @rbs () -> String
21
21
  def to_rbs: () -> String
@@ -3,8 +3,8 @@
3
3
  module RBS
4
4
  class Trace
5
5
  class InlineCommentVisitor < Prism::Visitor
6
- # @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
7
- def initialize: (Hash[TypeName, AST::Declarations::t], Hash[Integer, String]) -> void
6
+ # @rbs (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
7
+ def initialize: (Hash[TypeName, AST::Declarations::t], Hash[Integer, String], Symbol?) -> void
8
8
 
9
9
  # @rbs override
10
10
  # @rbs (Prism::Node) -> void
@@ -23,8 +23,8 @@ module RBS
23
23
  # @rbs () -> Hash[String, File]
24
24
  def files: () -> Hash[String, File]
25
25
 
26
- # @rbs () -> void
27
- def save_comments: () -> void
26
+ # @rbs (?Symbol) -> void
27
+ def save_comments: (?Symbol) -> void
28
28
 
29
29
  # @rbs (out_dir: String) -> void
30
30
  def save_files: (out_dir: String) -> void
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takumi Shotoku
@@ -88,8 +88,8 @@ licenses:
88
88
  - MIT
89
89
  metadata:
90
90
  homepage_uri: https://github.com/sinsoku/rbs-trace
91
- source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.5.1
92
- changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.5.1/CHANGELOG.md
91
+ source_code_uri: https://github.com/sinsoku/rbs-trace/tree/v0.6.0
92
+ changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.6.0/CHANGELOG.md
93
93
  rubygems_mfa_required: 'true'
94
94
  rdoc_options: []
95
95
  require_paths: