From a1646b1786dbc5d250efe35053084928d2090cec Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Wed, 1 Apr 2026 15:00:17 -0400 Subject: [PATCH 1/3] Parse `--parser` Sorbet config --- lib/spoom/sorbet/config.rb | 12 ++++++++++++ rbi/spoom.rbi | 8 ++++++++ test/spoom/sorbet/config_test.rb | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/lib/spoom/sorbet/config.rb b/lib/spoom/sorbet/config.rb index 5bc76195..5bb6462e 100644 --- a/lib/spoom/sorbet/config.rb +++ b/lib/spoom/sorbet/config.rb @@ -32,12 +32,19 @@ class Config #: bool attr_accessor :no_stdlib + #: Symbol? + attr_accessor :parser + + #: -> bool + def parse_with_prism? = @parser == :prism + #: -> void def initialize @paths = [] #: Array[String] @ignore = [] #: Array[String] @allowed_extensions = [] #: Array[String] @no_stdlib = false #: bool + @parser = nil #: Symbol? end #: -> Config @@ -47,6 +54,7 @@ def copy new_config.ignore.concat(@ignore) new_config.allowed_extensions.concat(@allowed_extensions) new_config.no_stdlib = @no_stdlib + new_config.parser = @parser new_config end @@ -69,6 +77,7 @@ def options_string opts.concat(ignore.map { |p| "--ignore '#{p}'" }) opts.concat(allowed_extensions.map { |ext| "--allowed-extension '#{ext}'" }) opts << "--no-stdlib" if @no_stdlib + opts << "--parser=#{@parser}" if @parser opts.join(" ") end @@ -110,6 +119,9 @@ def parse_string(sorbet_config) when /^--no-stdlib(=|$)/ config.no_stdlib = parse_bool_option(line) next + when /^--parser=/ + config.parser = parse_option(line).to_sym + next when /^--.*=/ next when /^--/ diff --git a/rbi/spoom.rbi b/rbi/spoom.rbi index f9abe5a6..917e25f3 100644 --- a/rbi/spoom.rbi +++ b/rbi/spoom.rbi @@ -2618,6 +2618,14 @@ class Spoom::Sorbet::Config sig { returns(::String) } def options_string; end + sig { returns(T::Boolean) } + def parse_with_prism?; end + + sig { returns(T.nilable(::Symbol)) } + def parser; end + + def parser=(_arg0); end + sig { returns(T::Array[::String]) } def paths; end diff --git a/test/spoom/sorbet/config_test.rb b/test/spoom/sorbet/config_test.rb index 8aac162c..20ee159d 100644 --- a/test/spoom/sorbet/config_test.rb +++ b/test/spoom/sorbet/config_test.rb @@ -133,6 +133,30 @@ def test_parses_no_stdlib_equals_false refute_predicate(config, :no_stdlib) end + def test_parses_parser_option_prism + config = Spoom::Sorbet::Config.parse_string(<<~CONFIG) + . + --parser=prism + CONFIG + assert_equal(:prism, config.parser) + assert_predicate(config, :parse_with_prism?) + end + + def test_parses_parser_option_original + config = Spoom::Sorbet::Config.parse_string(<<~CONFIG) + . + --parser=original + CONFIG + assert_equal(:original, config.parser) + refute_predicate(config, :parse_with_prism?) + end + + def test_parser_defaults_to_nil + config = Spoom::Sorbet::Config.parse_string(".") + assert_nil(config.parser) + refute_predicate(config, :parse_with_prism?) + end + def test_parses_a_config_string_with_mixed_options config = Spoom::Sorbet::Config.parse_string(<<~CONFIG) a From e2691de98804d4e840b830acd923ef6da25ce1b6 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Wed, 1 Apr 2026 15:23:25 -0400 Subject: [PATCH 2/3] Parse `--cache-dir` Sorbet config --- lib/spoom/sorbet/config.rb | 12 +++++++++++- rbi/spoom.rbi | 5 +++++ test/spoom/sorbet/config_test.rb | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/spoom/sorbet/config.rb b/lib/spoom/sorbet/config.rb index 5bb6462e..fba64b9f 100644 --- a/lib/spoom/sorbet/config.rb +++ b/lib/spoom/sorbet/config.rb @@ -32,6 +32,9 @@ class Config #: bool attr_accessor :no_stdlib + #: String? + attr_accessor :cache_dir + #: Symbol? attr_accessor :parser @@ -44,6 +47,7 @@ def initialize @ignore = [] #: Array[String] @allowed_extensions = [] #: Array[String] @no_stdlib = false #: bool + @cache_dir = nil #: String? @parser = nil #: Symbol? end @@ -54,6 +58,7 @@ def copy new_config.ignore.concat(@ignore) new_config.allowed_extensions.concat(@allowed_extensions) new_config.no_stdlib = @no_stdlib + new_config.cache_dir = @cache_dir new_config.parser = @parser new_config end @@ -77,6 +82,7 @@ def options_string opts.concat(ignore.map { |p| "--ignore '#{p}'" }) opts.concat(allowed_extensions.map { |ext| "--allowed-extension '#{ext}'" }) opts << "--no-stdlib" if @no_stdlib + opts << "--cache-dir='#{@cache_dir}'" if @cache_dir opts << "--parser=#{@parser}" if @parser opts.join(" ") end @@ -119,6 +125,10 @@ def parse_string(sorbet_config) when /^--no-stdlib(=|$)/ config.no_stdlib = parse_bool_option(line) next + when /^--cache-dir=/ + value = parse_option(line) + config.cache_dir = value.empty? ? nil : value + next when /^--parser=/ config.parser = parse_option(line).to_sym next @@ -153,7 +163,7 @@ def parse_string(sorbet_config) #: (String line) -> String def parse_option(line) - T.must(line.split("=").last).strip + T.must(line.split("=", 2).last).strip end #: (String line) -> bool diff --git a/rbi/spoom.rbi b/rbi/spoom.rbi index 917e25f3..f9d44c42 100644 --- a/rbi/spoom.rbi +++ b/rbi/spoom.rbi @@ -2604,6 +2604,11 @@ class Spoom::Sorbet::Config def allowed_extensions; end def allowed_extensions=(_arg0); end + sig { returns(T.nilable(::String)) } + def cache_dir; end + + def cache_dir=(_arg0); end + sig { returns(::Spoom::Sorbet::Config) } def copy; end diff --git a/test/spoom/sorbet/config_test.rb b/test/spoom/sorbet/config_test.rb index 20ee159d..df0ed407 100644 --- a/test/spoom/sorbet/config_test.rb +++ b/test/spoom/sorbet/config_test.rb @@ -133,6 +133,21 @@ def test_parses_no_stdlib_equals_false refute_predicate(config, :no_stdlib) end + def test_cache_dir_defaults_to_nil + config = Spoom::Sorbet::Config.parse_string(".") + assert_nil(config.cache_dir) + end + + def test_parses_cache_dir + config = Spoom::Sorbet::Config.parse_string("--cache-dir=/tmp/sorbet-cache") + assert_equal("/tmp/sorbet-cache", config.cache_dir) + end + + def test_parses_empty_cache_dir_as_nil + config = Spoom::Sorbet::Config.parse_string("--cache-dir=") + assert_nil(config.cache_dir) + end + def test_parses_parser_option_prism config = Spoom::Sorbet::Config.parse_string(<<~CONFIG) . From d860b42c5820554acd375392f506e2031c2dd315 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Wed, 1 Apr 2026 15:32:27 -0400 Subject: [PATCH 3/3] Parse RBS Sorbet configs --- lib/spoom/sorbet/config.rb | 11 +++++++++++ rbi/spoom.rbi | 8 ++++++++ test/spoom/sorbet/config_test.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/spoom/sorbet/config.rb b/lib/spoom/sorbet/config.rb index fba64b9f..4bbb84a0 100644 --- a/lib/spoom/sorbet/config.rb +++ b/lib/spoom/sorbet/config.rb @@ -38,9 +38,15 @@ class Config #: Symbol? attr_accessor :parser + #: bool + attr_accessor :use_rbs + #: -> bool def parse_with_prism? = @parser == :prism + #: -> bool + def use_rbs? = @use_rbs + #: -> void def initialize @paths = [] #: Array[String] @@ -49,6 +55,7 @@ def initialize @no_stdlib = false #: bool @cache_dir = nil #: String? @parser = nil #: Symbol? + @use_rbs = false #: bool end #: -> Config @@ -60,6 +67,7 @@ def copy new_config.no_stdlib = @no_stdlib new_config.cache_dir = @cache_dir new_config.parser = @parser + new_config.use_rbs = @use_rbs new_config end @@ -132,6 +140,9 @@ def parse_string(sorbet_config) when /^--parser=/ config.parser = parse_option(line).to_sym next + when /^--enable-experimental-rbs-(comments|signatures|assertions)(=|$)/ + config.use_rbs = parse_bool_option(line) + next when /^--.*=/ next when /^--/ diff --git a/rbi/spoom.rbi b/rbi/spoom.rbi index f9d44c42..549ddac8 100644 --- a/rbi/spoom.rbi +++ b/rbi/spoom.rbi @@ -2636,6 +2636,14 @@ class Spoom::Sorbet::Config def paths=(_arg0); end + sig { returns(T::Boolean) } + def use_rbs; end + + def use_rbs=(_arg0); end + + sig { returns(T::Boolean) } + def use_rbs?; end + class << self sig { params(sorbet_config_path: ::String).returns(::Spoom::Sorbet::Config) } def parse_file(sorbet_config_path); end diff --git a/test/spoom/sorbet/config_test.rb b/test/spoom/sorbet/config_test.rb index df0ed407..178935ec 100644 --- a/test/spoom/sorbet/config_test.rb +++ b/test/spoom/sorbet/config_test.rb @@ -172,6 +172,36 @@ def test_parser_defaults_to_nil refute_predicate(config, :parse_with_prism?) end + def test_use_rbs_defaults_to_false + config = Spoom::Sorbet::Config.parse_string(".") + refute_predicate(config, :use_rbs?) + end + + def test_use_rbs_with_rbs_comments + config = Spoom::Sorbet::Config.parse_string("--enable-experimental-rbs-comments") + assert_predicate(config, :use_rbs?) + end + + def test_use_rbs_with_rbs_signatures + config = Spoom::Sorbet::Config.parse_string("--enable-experimental-rbs-signatures") + assert_predicate(config, :use_rbs?) + end + + def test_use_rbs_with_rbs_assertions + config = Spoom::Sorbet::Config.parse_string("--enable-experimental-rbs-assertions") + assert_predicate(config, :use_rbs?) + end + + def test_use_rbs_equals_false + config = Spoom::Sorbet::Config.parse_string("--enable-experimental-rbs-comments=false") + refute_predicate(config, :use_rbs?) + end + + def test_use_rbs_equals_true + config = Spoom::Sorbet::Config.parse_string("--enable-experimental-rbs-comments=true") + assert_predicate(config, :use_rbs?) + end + def test_parses_a_config_string_with_mixed_options config = Spoom::Sorbet::Config.parse_string(<<~CONFIG) a