Skip to content
Merged
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
9 changes: 9 additions & 0 deletions lib/spoom/sorbet/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class Config
sig { returns(T::Array[String]) }
attr_reader :paths, :ignore, :allowed_extensions

sig { returns(T::Boolean) }
attr_accessor :no_stdlib

sig { void }
def initialize
@paths = T.let([], T::Array[String])
@ignore = T.let([], T::Array[String])
@allowed_extensions = T.let([], T::Array[String])
@no_stdlib = T.let(false, T::Boolean)
end

sig { returns(Config) }
Expand All @@ -42,6 +46,7 @@ def copy
new_config.paths.concat(@paths)
new_config.ignore.concat(@ignore)
new_config.allowed_extensions.concat(@allowed_extensions)
new_config.no_stdlib = @no_stdlib
new_config
end

Expand All @@ -63,6 +68,7 @@ def options_string
opts.concat(paths)
opts.concat(ignore.map { |p| "--ignore #{p}" })
opts.concat(allowed_extensions.map { |ext| "--allowed-extension #{ext}" })
opts << "--no-stdlib" if @no_stdlib
opts.join(" ")
end

Expand Down Expand Up @@ -106,6 +112,9 @@ def parse_string(sorbet_config)
when /^--dir=/
config.paths << parse_option(line)
next
when /^--no-stdlib$/
config.no_stdlib = true
next
when /^--.*=/
next
when /^--/
Expand Down
16 changes: 15 additions & 1 deletion test/spoom/sorbet/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def test_parses_a_config_string_with_other_options
assert_empty(config.allowed_extensions)
end

def test_parses_a_config_string_with_no_stdlib
config = Spoom::Sorbet::Config.parse_string(<<~CONFIG)
a
b
--no-stdlib
c
CONFIG
assert_equal(['a', 'b', 'c'], config.paths)
assert(config.no_stdlib)
end

def test_parses_a_config_string_with_mixed_options
config = Spoom::Sorbet::Config.parse_string(<<~CONFIG)
a
Expand Down Expand Up @@ -124,10 +135,12 @@ def test_parses_a_real_config_string
--allowed-extension=.rbi
--allowed-extension=.rake
--allowed-extension=.ru
--no-stdlib
CONFIG
assert_equal(['.'], config.paths)
assert_equal(['.git/', '.idea/', 'vendor/'], config.ignore)
assert_equal(['.rb', '.rbi', '.rake', '.ru'], config.allowed_extensions)
assert(config.no_stdlib)
end

def test_parses_a_config_file_with_errors
Expand Down Expand Up @@ -161,8 +174,9 @@ def test_options_string_with_options
--ignore=.git/
--ignore=vendor/
--allowed-extension=.rb
--no-stdlib
CONFIG
assert_equal(". --ignore .git/ --ignore vendor/ --allowed-extension .rb", config.options_string)
assert_equal(". --ignore .git/ --ignore vendor/ --allowed-extension .rb --no-stdlib", config.options_string)
end
end
end
Expand Down