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 +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +5 -0
- data/README.md +19 -0
- data/lib/rbs/trace/cli/inline.rb +5 -2
- data/lib/rbs/trace/file.rb +6 -6
- data/lib/rbs/trace/inline_comment_visitor.rb +4 -3
- data/lib/rbs/trace/version.rb +1 -1
- data/lib/rbs/trace.rb +3 -3
- data/rbs_collection.lock.yaml +11 -3
- data/sig/generated/rbs/trace/file.rbs +4 -4
- data/sig/generated/rbs/trace/inline_comment_visitor.rbs +2 -2
- data/sig/generated/rbs/trace.rbs +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a25eb287a611f0c087e0419da03b0d45b53735e3e1bfa9bbcf9018940f640a1
|
4
|
+
data.tar.gz: 70591151052c0e0695b3584b31551e0251987f8cc9b5c5c635db741d4b44c0d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3fd0ae96dc471248170fd72d639fc338026e7ecba577db2d3be8096652c9e28e9df4a1cf9c012a976da6951dcb0bbbcb12444d029206f9ac3384b9374538165
|
7
|
+
data.tar.gz: 204295de73d9fee188d8c5568546b09bd295173937b9037f1e957f7a4b2952af502b2a58ce2fc01927e29bdeeb866e8950d3b9549cf3f4960759e94d745f5a2f
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
data/lib/rbs/trace/cli/inline.rb
CHANGED
@@ -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
|
data/lib/rbs/trace/file.rb
CHANGED
@@ -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}#
|
42
|
+
@comments[lineno] = "#{indent}#{@comment_prefix} #{comment}\n"
|
42
43
|
end
|
43
44
|
|
44
45
|
super
|
data/lib/rbs/trace/version.rb
CHANGED
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
|
|
data/rbs_collection.lock.yaml
CHANGED
@@ -6,7 +6,7 @@ gems:
|
|
6
6
|
source:
|
7
7
|
type: git
|
8
8
|
name: ruby/gem_rbs_collection
|
9
|
-
revision:
|
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:
|
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.
|
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
|
data/sig/generated/rbs/trace.rbs
CHANGED
@@ -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.
|
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.
|
92
|
-
changelog_uri: https://github.com/sinsoku/rbs-trace/blob/v0.
|
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:
|