Skip to content

Commit 1c2cf68

Browse files
committed
Add Steep for type checking
1 parent e58c77b commit 1c2cf68

5 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/steep.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: steep
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
steep:
7+
name: Type check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v6
11+
- name: Set up Ruby
12+
uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: ruby
15+
bundler-cache: true
16+
- name: Run Steep
17+
run: bundle exec rake steep

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ source "https://rubygems.org"
33
gemspec
44

55
gem "rake"
6+
gem "steep"
67
gem "test-unit"
78
gem "test-unit-ruby-core"

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ Rake::TestTask.new(:test) do |t|
77
t.test_files = FileList["test/**/test_*.rb"]
88
end
99

10+
desc "Type check with Steep"
11+
task :steep do
12+
sh "steep check"
13+
end
14+
1015
task :default => :test

Steepfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
target :lib do
2+
check "lib"
3+
signature "sig"
4+
5+
library "cgi"
6+
library "open-uri"
7+
library "openssl"
8+
library "resolv"
9+
library "securerandom"
10+
library "socket"
11+
library "strscan"
12+
library "tempfile"
13+
library "timeout"
14+
library "uri"
15+
library "zlib"
16+
17+
d = Steep::Diagnostic::Ruby.default.dup
18+
d[Steep::Diagnostic::Ruby::ArgumentTypeMismatch] = :information
19+
d[Steep::Diagnostic::Ruby::NoMethod] = :information
20+
configure_code_diagnostics(d)
21+
end

sig/net-http.rbs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
# TCPSocket.open is an alias for TCPSocket.new in Ruby,
2+
# but RBS inherits IO.open which has a different signature.
3+
class TCPSocket
4+
def self.open: (String remote_host, Integer remote_port, ?String? local_host, ?Integer? local_port, ?open_timeout: Numeric?) -> TCPSocket
5+
| (String remote_host, Integer remote_port, ?String? local_host, ?Integer? local_port) -> TCPSocket
6+
end
7+
18
module Net
29
# Stubs for net-protocol classes
310
class Protocol
11+
def self.new: (*untyped) -> instance
412
end
513

614
class ProtocolError < StandardError
@@ -323,8 +331,7 @@ module Net
323331
def initialize: (String address, ?Integer? port) -> void
324332
def started?: () -> bool
325333
alias active? started?
326-
def start: () -> Net::HTTP
327-
| () { (Net::HTTP http) -> untyped } -> untyped
334+
def start: () ?{ (Net::HTTP http) -> untyped } -> (Net::HTTP | untyped)
328335
def finish: () -> void
329336

330337
def use_ssl?: () -> bool

0 commit comments

Comments
 (0)