Skip to content

Commit 03f9334

Browse files
authored
Merge pull request #7 from sue445/feature/add_sig
Add sig
2 parents b89bcae + 0371bd7 commit 03f9334

24 files changed

+496
-15
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: rbs-collection-updater
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 1 * *" # Run monthly
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: ruby
18+
bundler-cache: true
19+
20+
- run: bundle exec rbs collection update
21+
22+
- uses: actions/create-github-app-token@v1
23+
id: app-token
24+
with:
25+
app-id: ${{ secrets.GH_APP_ID }}
26+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
27+
28+
- uses: peter-evans/create-pull-request@v7
29+
with:
30+
token: ${{ steps.app-token.outputs.token }}
31+
committer: GitHub <noreply@github.com>
32+
title: "Update rbs_collection.lock.yaml"
33+
commit-message: "Run `bundle exe rbs collection update`"
34+
35+
- name: Slack Notification
36+
uses: act10ns/slack@v2
37+
if: always()
38+
continue-on-error: true
39+
with:
40+
status: ${{ job.status }}
41+
webhook-url: ${{ secrets.SLACK_WEBHOOK }}

.github/workflows/test.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
- run: sudo apt-get install -y universal-ctags
4040

4141
- run: bundle exec rake spec
42-
- run: bundle exec rake rubocop
4342

4443
- name: Slack Notification (not success)
4544
uses: act10ns/slack@v2
@@ -50,9 +49,66 @@ jobs:
5049
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
5150
matrix: ${{ toJson(matrix) }}
5251

52+
rubocop:
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- uses: ruby/setup-ruby@v1
59+
with:
60+
ruby-version: ruby
61+
bundler-cache: true
62+
63+
- name: bundle update
64+
run: |
65+
set -xe
66+
bundle config path vendor/bundle
67+
bundle update --jobs $(nproc) --retry 3
68+
69+
- run: bundle exec rake rubocop
70+
71+
- name: Slack Notification (not success)
72+
uses: act10ns/slack@v2
73+
if: "! success()"
74+
continue-on-error: true
75+
with:
76+
status: ${{ job.status }}
77+
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
78+
79+
rbs:
80+
runs-on: ubuntu-latest
81+
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- uses: ruby/setup-ruby@v1
86+
with:
87+
ruby-version: ruby
88+
bundler-cache: true
89+
90+
- name: bundle update
91+
run: |
92+
set -xe
93+
bundle config path vendor/bundle
94+
bundle update --jobs $(nproc) --retry 3
95+
96+
- run: bundle exec rake rbs:install
97+
- run: bundle exec rake rbs
98+
99+
- name: Slack Notification (not success)
100+
uses: act10ns/slack@v2
101+
if: "! success()"
102+
continue-on-error: true
103+
with:
104+
status: ${{ job.status }}
105+
webhook-url: ${{ secrets.SLACK_WEBHOOK }}
106+
53107
notify:
54108
needs:
55109
- test
110+
- rubocop
111+
- rbs
56112

57113
runs-on: ubuntu-latest
58114

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
.rspec_status
1212

1313
Gemfile.lock
14+
.gem_rbs_collection/

Rakefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ require "rubocop/rake_task"
99

1010
RuboCop::RakeTask.new
1111

12+
namespace :rbs do
13+
desc "`rbs collection install` and `git commit`"
14+
task :install do
15+
sh "rbs collection install"
16+
sh "git add rbs_collection.lock.yaml"
17+
sh "git commit -m 'rbs collection install' || true"
18+
end
19+
end
20+
21+
desc "Check rbs"
22+
task :rbs do
23+
sh "rbs validate"
24+
sh "steep check"
25+
end
26+
1227
desc "Run all development tasks"
13-
task dev_all: %i[spec rubocop]
28+
task dev_all: %i[spec rubocop rbs]
1429

1530
task default: :dev_all

Steepfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
# D = Steep::Diagnostic
4+
5+
target :lib do
6+
signature "sig"
7+
8+
check "lib" # Directory name
9+
# check "Gemfile" # File name
10+
# check "app/models/**/*.rb" # Glob
11+
# ignore "lib/templates/*.rb"
12+
13+
# library "pathname" # Standard libraries
14+
# library "strong_json" # Gems
15+
16+
collection_config "rbs_collection.yaml"
17+
18+
# configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
19+
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
20+
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
21+
# configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
22+
# configure_code_diagnostics do |hash| # You can setup everything yourself
23+
# hash[D::Ruby::NoMethod] = :information
24+
# end
25+
end
26+
27+
# target :test do
28+
# signature "sig", "sig-private"
29+
#
30+
# check "test"
31+
#
32+
# # library "pathname" # Standard libraries
33+
# end

lib/ruby_header_parser/data.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Data
88
attr_reader :data
99

1010
def initialize
11-
yaml = File.read(File.join(__dir__, "data.yml"))
11+
yaml = File.read(File.join(__dir__.to_s, "data.yml"))
1212
@data = YAML.safe_load(yaml, aliases: true, permitted_classes: [Regexp])
1313
end
1414

lib/ruby_header_parser/parser.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ def parse_typeref_type(definition:, function_name:, typeref_field:, filepath:, l
235235
typeref_field.gsub(/[A-Z_]+\s*\(\(.*\)\)/, "").gsub("RUBY_SYMBOL_EXPORT_BEGIN", "")
236236
else
237237
# parse typeref in definition
238-
definition[0...definition.index(function_name)].gsub("char *", "char*").strip
238+
type = definition[0...definition.index(function_name)] || ""
239+
type.gsub("char *", "char*").strip
239240
end
240241

241242
typeref_type = Util.sanitize_type(typeref_type)
@@ -301,7 +302,8 @@ def generate_argument_definition(function_name:, arg:, arg_pos:)
301302
# - length [Integer]
302303
def analyze_argument_type(function_name:, arg_pos:, parts:)
303304
pointer, length = prepare_argument_parts(arg_pos:, parts:)
304-
original_type = Util.sanitize_type(parts[0...-1].join(" "))
305+
type = parts[0...-1] || []
306+
original_type = Util.sanitize_type(type.join(" "))
305307

306308
case original_type
307309
when /\*+$/
@@ -329,27 +331,30 @@ def analyze_argument_type(function_name:, arg_pos:, parts:)
329331
# - pointer [Symbol,nil]
330332
# - length [Integer]
331333
def prepare_argument_parts(parts:, arg_pos:)
332-
pointer = nil
333-
length = 0
334-
335334
if parts[-1] =~ /\[([0-9]+)?\]$/
336335
parts[-1].gsub!(/\[([0-9]+)?\]$/, "")
337336
length = ::Regexp.last_match(1).to_i
338-
pointer = :array
337+
338+
unless parts[-1] =~ /^[0-9a-zA-Z_]+$/
339+
# last elements isn't dummy argument
340+
parts << "arg#{arg_pos}"
341+
end
342+
343+
return [:array, length]
339344
end
340345

341346
unless parts[-1] =~ /^[0-9a-zA-Z_]+$/
342347
# last elements isn't dummy argument
343348
parts << "arg#{arg_pos}"
344349
end
345350

346-
[pointer, length]
351+
[nil, 0]
347352
end
348353

349354
# @param type [String]
350355
def pointer_length(type)
351356
type =~ /(\*+)$/
352-
::Regexp.last_match(1).length
357+
::Regexp.last_match(1)&.length || 0
353358
end
354359
end
355360
end

lib/ruby_header_parser/typeref_definition.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class TyperefDefinition
88
attr_accessor :type
99

1010
# @!attribute pointer
11-
# @return [Symbol,nil]
11+
# @return [Symbol,nil] :ref, :raw
1212
attr_accessor :pointer
1313

1414
# @param type [String]
15-
# @param pointer [Symbol,nil] :ref
15+
# @param pointer [Symbol,nil] :ref, :raw
1616
def initialize(type:, pointer: nil)
1717
@type = type
1818
@pointer = pointer

lib/ruby_header_parser/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def self.find_field(array, field_name)
1717
# @param signature [String]
1818
# @return [Array<String>]
1919
def self.split_signature(signature)
20-
signature.scan(/[^,]+\([^()]*\)|[^,]+/).map(&:strip)
20+
signature.scan(/[^,]+\([^()]*\)|[^,]+/).flatten.map(&:strip)
2121
end
2222

2323
# @param type [String]

rbs_collection.lock.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
path: ".gem_rbs_collection"
3+
gems:
4+
- name: ast
5+
version: '2.4'
6+
source:
7+
type: git
8+
name: ruby/gem_rbs_collection
9+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
10+
remote: https://github.com/ruby/gem_rbs_collection.git
11+
repo_dir: gems
12+
- name: binding_of_caller
13+
version: '1.0'
14+
source:
15+
type: git
16+
name: ruby/gem_rbs_collection
17+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
18+
remote: https://github.com/ruby/gem_rbs_collection.git
19+
repo_dir: gems
20+
- name: dbm
21+
version: '0'
22+
source:
23+
type: stdlib
24+
- name: diff-lcs
25+
version: '1.5'
26+
source:
27+
type: git
28+
name: ruby/gem_rbs_collection
29+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
30+
remote: https://github.com/ruby/gem_rbs_collection.git
31+
repo_dir: gems
32+
- name: fileutils
33+
version: '0'
34+
source:
35+
type: stdlib
36+
- name: json
37+
version: '0'
38+
source:
39+
type: stdlib
40+
- name: parallel
41+
version: '1.20'
42+
source:
43+
type: git
44+
name: ruby/gem_rbs_collection
45+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
46+
remote: https://github.com/ruby/gem_rbs_collection.git
47+
repo_dir: gems
48+
- name: parser
49+
version: '3.2'
50+
source:
51+
type: git
52+
name: ruby/gem_rbs_collection
53+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
54+
remote: https://github.com/ruby/gem_rbs_collection.git
55+
repo_dir: gems
56+
- name: pstore
57+
version: '0'
58+
source:
59+
type: stdlib
60+
- name: psych
61+
version: '0'
62+
source:
63+
type: stdlib
64+
- name: rainbow
65+
version: '3.0'
66+
source:
67+
type: git
68+
name: ruby/gem_rbs_collection
69+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
70+
remote: https://github.com/ruby/gem_rbs_collection.git
71+
repo_dir: gems
72+
- name: rake
73+
version: '13.0'
74+
source:
75+
type: git
76+
name: ruby/gem_rbs_collection
77+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
78+
remote: https://github.com/ruby/gem_rbs_collection.git
79+
repo_dir: gems
80+
- name: regexp_parser
81+
version: '2.8'
82+
source:
83+
type: git
84+
name: ruby/gem_rbs_collection
85+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
86+
remote: https://github.com/ruby/gem_rbs_collection.git
87+
repo_dir: gems
88+
- name: rspec-parameterized-core
89+
version: 1.0.1
90+
source:
91+
type: rubygems
92+
- name: rspec-parameterized-table_syntax
93+
version: 1.0.1
94+
source:
95+
type: rubygems
96+
- name: rubocop
97+
version: '1.57'
98+
source:
99+
type: git
100+
name: ruby/gem_rbs_collection
101+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
102+
remote: https://github.com/ruby/gem_rbs_collection.git
103+
repo_dir: gems
104+
- name: rubocop-ast
105+
version: '1.30'
106+
source:
107+
type: git
108+
name: ruby/gem_rbs_collection
109+
revision: 704f7e6b395fca717cc25c562598ca86015ed545
110+
remote: https://github.com/ruby/gem_rbs_collection.git
111+
repo_dir: gems
112+
- name: yaml
113+
version: '0'
114+
source:
115+
type: stdlib
116+
gemfile_lock_path: Gemfile.lock

0 commit comments

Comments
 (0)