Skip to content

Commit

Permalink
Set up static type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
akadusei committed Jun 17, 2024
1 parent 125ef12 commit 51ef02a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
bundler-cache: true
- name: Lint code
run: bundle exec rubocop
- name: Check types
run: bundle exec steep check
specs:
strategy:
fail-fast: false
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ group :development, :test do
gem "rubocop-rake", "~> 0.6.0", require: false
end

group :development do
gem "rbs", "~> 3.5", require: false
gem "steep", "~> 1.7", require: false
end

group :test do
gem "rspec", "~> 3.0"
gem "rubocop-rspec", "~> 2.29", require: false
Expand Down
12 changes: 12 additions & 0 deletions Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

target :lib do
signature "sig"

check "lib"

library "yaml"
library "set"

configure_code_diagnostics(Steep::Diagnostic::Ruby.strict)
end
2 changes: 1 addition & 1 deletion lib/envy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def from_file!(*files, perm: nil)
private

def load_yaml(path, force:)
File.open(path) { |file| set_envs YAML.safe_load(file), force: force }
File.open(path) { |file| set_envs YAML.safe_load(file.read), force: force }
nil
end

Expand Down
17 changes: 15 additions & 2 deletions sig/envy.rbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
module Envy
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
extend ::Envy

def from_file: (*String files, ?perm: Integer?) -> nil

def from_file!: (*String files, ?perm: Integer?) -> nil

private

def load_yaml: (String path, force: bool) -> nil

def set_perms: (Array[String] files, ?perm: Integer?) -> void

def set_envs: (untyped yaml, ?String prev_key, force: bool) -> void

def load_wrap: () { () -> untyped } -> nil
end
4 changes: 4 additions & 0 deletions sig/envy/error.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Envy
class Error < ::StandardError
end
end
3 changes: 3 additions & 0 deletions sig/envy/version.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Envy
VERSION: String
end

0 comments on commit 51ef02a

Please sign in to comment.