Skip to content

Commit a5c94cb

Browse files
chore: refine Yard and Sorbet types and ensure linting is turned on for examples
1 parent 98c446f commit a5c94cb

7 files changed

Lines changed: 34 additions & 9 deletions

File tree

Rakefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require "rake/clean"
99
require "rubocop/rake_task"
1010

1111
tapioca = "sorbet/tapioca"
12+
examples = "examples"
1213
ignore_file = ".ignore"
1314

1415
CLEAN.push(*%w[.idea/ .ruby-lsp/ .yardoc/ doc/], *FileList["*.gem"], ignore_file)
@@ -39,7 +40,7 @@ locale = {"LC_ALL" => "C.UTF-8"}
3940

4041
desc("Lint `*.rb(i)`")
4142
multitask(:"lint:rubocop") do
42-
find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
43+
find = %w[find ./lib ./test ./rbi ./examples -type f -and ( -name *.rb -or -name *.rbi ) -print0]
4344

4445
rubocop = %w[rubocop]
4546
rubocop += %w[--format github] if ENV.key?("CI")
@@ -54,7 +55,7 @@ end
5455
desc("Format `*.rb`")
5556
multitask(:"format:rb") do
5657
# while `syntax_tree` is much faster than `rubocop`, `rubocop` is the only formatter with full syntax support
57-
find = %w[find ./lib ./test -type f -and -name *.rb -print0]
58+
find = %w[find ./lib ./test ./examples -type f -and -name *.rb -print0]
5859
fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
5960
sh("#{find.shelljoin} | #{fmt.shelljoin}")
6061
end
@@ -117,12 +118,14 @@ multitask(:"typecheck:steep") do
117118
sh(*%w[steep check])
118119
end
119120

121+
directory(examples)
122+
120123
desc("Typecheck `*.rbi`")
121-
multitask(:"typecheck:sorbet") do
122-
sh(*%w[srb typecheck])
124+
multitask("typecheck:sorbet": examples) do
125+
sh(*%w[srb typecheck --dir], examples)
123126
end
124127

125-
file(tapioca) do
128+
directory(tapioca) do
126129
sh(*%w[tapioca init])
127130
end
128131

lib/lithic/internal.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ module Internal
1313
define_sorbet_constant!(:AnyHash) do
1414
T.type_alias { T::Hash[Symbol, T.anything] }
1515
end
16+
define_sorbet_constant!(:FileInput) do
17+
T.type_alias { T.any(Pathname, StringIO, IO, String, Lithic::FilePart) }
18+
end
1619
end
1720
end

rbi/lithic/internal.rbi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Lithic
88
# this alias might be refined in the future.
99
AnyHash = T.type_alias { T::Hash[Symbol, T.anything] }
1010

11+
FileInput =
12+
T.type_alias { T.any(Pathname, StringIO, IO, String, Lithic::FilePart) }
13+
1114
OMIT = T.let(Object.new.freeze, T.anything)
1215
end
1316
end

rbi/lithic/models/auth_rules/velocity_limit_params.rbi

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ module Lithic
2525
# The size of the trailing window to calculate Spend Velocity over in seconds. The
2626
# minimum value is 10 seconds, and the maximum value is 2678400 seconds (31 days).
2727
sig do
28-
returns(Lithic::AuthRules::VelocityLimitParams::Period::Variants)
28+
returns(
29+
T.any(
30+
Integer,
31+
Lithic::AuthRules::VelocityLimitParamsPeriodWindow::OrSymbol
32+
)
33+
)
2934
end
3035
attr_accessor :period
3136

@@ -49,7 +54,11 @@ module Lithic
4954
sig do
5055
params(
5156
filters: Lithic::AuthRules::VelocityLimitParams::Filters::OrHash,
52-
period: Lithic::AuthRules::VelocityLimitParams::Period::Variants,
57+
period:
58+
T.any(
59+
Integer,
60+
Lithic::AuthRules::VelocityLimitParamsPeriodWindow::OrSymbol
61+
),
5362
scope: Lithic::AuthRules::VelocityLimitParams::Scope::OrSymbol,
5463
limit_amount: T.nilable(Integer),
5564
limit_count: T.nilable(Integer)
@@ -78,7 +87,11 @@ module Lithic
7887
override.returns(
7988
{
8089
filters: Lithic::AuthRules::VelocityLimitParams::Filters,
81-
period: Lithic::AuthRules::VelocityLimitParams::Period::Variants,
90+
period:
91+
T.any(
92+
Integer,
93+
Lithic::AuthRules::VelocityLimitParamsPeriodWindow::OrSymbol
94+
),
8295
scope: Lithic::AuthRules::VelocityLimitParams::Scope::OrSymbol,
8396
limit_amount: T.nilable(Integer),
8497
limit_count: T.nilable(Integer)

sig/lithic/internal.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Lithic
22
module Internal
33
extend Lithic::Internal::Util::SorbetRuntimeSupport
44

5+
type file_input = Pathname | StringIO | IO | String | Lithic::FilePart
6+
57
OMIT: Object
68
end
79
end

sorbet/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
--dir=rbi
1+
--dir=rbi/
22
--ignore=test/

test/lithic/internal/sorbet_runtime_support_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_nil_aliases
2525
err = Lithic::Internal::Util::SorbetRuntimeSupport::MissingSorbetRuntimeError
2626

2727
assert_raises(err) { Lithic::Internal::AnyHash }
28+
assert_raises(err) { Lithic::Internal::FileInput }
2829
assert_raises(err) { Lithic::Internal::Type::Converter::Input }
2930
assert_raises(err) { Lithic::Internal::Type::Converter::CoerceState }
3031
assert_raises(err) { Lithic::Internal::Type::Converter::DumpState }

0 commit comments

Comments
 (0)