Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/tapioca/helpers/sorbet_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,25 @@ def parse(content)
end.to_h #: Hash[String, String | bool | nil]

new(
# `--cache-dir=` disables the cache, modeled here with a `nil` value
cache_dir: if (value = options["--cache-dir"]).is_a?(String)
value.empty? ? nil : value
end,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more readable outside of new, was there a specific reason to have it here?

Also should this use shellescape?

Copy link
Copy Markdown
Contributor Author

@amomchilov amomchilov Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I extracted local variables

Also should this use shellescape?

I don't think so. The C++ code consumes these values directly, not mediated by a shell.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I extracted local variables

Did you?

Are we missing a push?


parser: options["--parser"] == "prism" ? :prism : :original,
)
end
end

#: (parser: Symbol) -> void
def initialize(parser:)
#: (cache_dir: String?, parser: Symbol) -> void
def initialize(cache_dir:, parser:)
@cache_dir = cache_dir #: String?
@parser = parser #: Symbol
end

#: String?
attr_reader :cache_dir

#: Symbol
attr_reader :parser

Expand All @@ -64,6 +73,10 @@ def parse_with_prism? = @parser == :prism

#: (*String sorbet_args) -> Spoom::ExecResult
def sorbet(*sorbet_args)
if sorbet_config.cache_dir
sorbet_args << "--cache-dir=#{sorbet_config.cache_dir}"
end

if sorbet_config.parse_with_prism?
sorbet_args << "--parser=prism"
end
Expand Down
26 changes: 26 additions & 0 deletions spec/tapioca/helpers/sorbet_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ class Tapioca::SorbetHelperSpec < Minitest::Spec
end
end

describe "--cache-dir" do
it "detects --cache-dir" do
config = parse(<<~CONFIG)
.
--cache-dir=/tmp/sorbet-cache
CONFIG
assert_equal("/tmp/sorbet-cache", config.cache_dir)
end

it "returns nil when not set" do
config = parse(<<~CONFIG)
.
--parser=prism
CONFIG
assert_nil(config.cache_dir)
end

it "returns nil for empty value" do
config = parse(<<~CONFIG)
.
--cache-dir=
CONFIG
assert_nil(config.cache_dir)
end
end

private

#: (String content) -> Tapioca::SorbetHelper::SorbetConfig
Expand Down
Loading