Skip to content

Commit 47e43de

Browse files
committed
Make Config attributes read-only
1 parent 31ec3a5 commit 47e43de

4 files changed

Lines changed: 40 additions & 29 deletions

File tree

lib/spoom/coverage.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def report(context, snapshots, palette:)
100100
#: (Context context) -> FileTree
101101
def file_tree(context)
102102
config = context.sorbet_config
103-
config.ignore += ["test"]
103+
config.ignore << "test"
104104

105105
files = context.srb_files(with_config: config, include_rbis: false)
106106
FileTree.new(files)

lib/spoom/sorbet/config.rb

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class Config
2727
DEFAULT_ALLOWED_EXTENSIONS = [".rb", ".rbi"].freeze #: Array[String]
2828

2929
#: Array[String]
30-
attr_accessor :paths, :ignore, :allowed_extensions
30+
attr_reader :paths, :ignore, :allowed_extensions
3131

3232
#: bool
33-
attr_accessor :no_stdlib
33+
attr_reader :no_stdlib
3434

35-
#: -> void
36-
def initialize
37-
@paths = [] #: Array[String]
38-
@ignore = [] #: Array[String]
39-
@allowed_extensions = [] #: Array[String]
40-
@no_stdlib = false #: bool
35+
#: (?paths: Array[String], ?ignore: Array[String], ?allowed_extensions: Array[String], ?no_stdlib: bool) -> void
36+
def initialize(paths: [], ignore: [], allowed_extensions: [], no_stdlib: false)
37+
@paths = paths
38+
@ignore = ignore
39+
@allowed_extensions = allowed_extensions
40+
@no_stdlib = no_stdlib
4141
end
4242

4343
#: (Config source) -> void
@@ -78,35 +78,40 @@ def parse_file(sorbet_config_path)
7878

7979
#: (String sorbet_config) -> Spoom::Sorbet::Config
8080
def parse_string(sorbet_config)
81-
config = Config.new
81+
paths = [] #: Array[String]
82+
ignore = [] #: Array[String]
83+
allowed_extensions = [] #: Array[String]
84+
no_stdlib = false #: bool
85+
8286
state = nil #: Symbol?
87+
8388
sorbet_config.each_line do |line|
8489
line = line.strip
8590
case line
8691
when /^--allowed-extension$/
8792
state = :extension
8893
next
8994
when /^--allowed-extension=/
90-
config.allowed_extensions << parse_option(line)
95+
allowed_extensions << parse_option(line)
9196
next
9297
when /^--ignore$/
9398
state = :ignore
9499
next
95100
when /^--ignore=/
96-
config.ignore << parse_option(line)
101+
ignore << parse_option(line)
97102
next
98103
when /^--file$/
99104
next
100105
when /^--file=/
101-
config.paths << parse_option(line)
106+
paths << parse_option(line)
102107
next
103108
when /^--dir$/
104109
next
105110
when /^--dir=/
106-
config.paths << parse_option(line)
111+
paths << parse_option(line)
107112
next
108113
when /^--no-stdlib(=|$)/
109-
config.no_stdlib = parse_bool_option(line)
114+
no_stdlib = parse_bool_option(line)
110115
next
111116
when /^--.*=/
112117
next
@@ -121,18 +126,24 @@ def parse_string(sorbet_config)
121126
else
122127
case state
123128
when :ignore
124-
config.ignore << line
129+
ignore << line
125130
when :extension
126-
config.allowed_extensions << line
131+
allowed_extensions << line
127132
when :skip
128133
# nothing
129134
else
130-
config.paths << line
135+
paths << line
131136
end
132137
state = nil
133138
end
134139
end
135-
config
140+
141+
Config.new(
142+
paths:,
143+
ignore:,
144+
allowed_extensions:,
145+
no_stdlib:,
146+
)
136147
end
137148

138149
private

rbi/spoom.rbi

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,27 +2598,28 @@ Spoom::Sorbet::BIN_PATH = T.let(T.unsafe(nil), String)
25982598
Spoom::Sorbet::CONFIG_PATH = T.let(T.unsafe(nil), String)
25992599

26002600
class Spoom::Sorbet::Config
2601-
sig { void }
2602-
def initialize; end
2601+
sig do
2602+
params(
2603+
paths: T::Array[::String],
2604+
ignore: T::Array[::String],
2605+
allowed_extensions: T::Array[::String],
2606+
no_stdlib: T::Boolean
2607+
).void
2608+
end
2609+
def initialize(paths: T.unsafe(nil), ignore: T.unsafe(nil), allowed_extensions: T.unsafe(nil), no_stdlib: T.unsafe(nil)); end
26032610

26042611
def allowed_extensions; end
2605-
def allowed_extensions=(_arg0); end
26062612
def ignore; end
2607-
def ignore=(_arg0); end
26082613

26092614
sig { returns(T::Boolean) }
26102615
def no_stdlib; end
26112616

2612-
def no_stdlib=(_arg0); end
2613-
26142617
sig { returns(::String) }
26152618
def options_string; end
26162619

26172620
sig { returns(T::Array[::String]) }
26182621
def paths; end
26192622

2620-
def paths=(_arg0); end
2621-
26222623
private
26232624

26242625
sig { params(source: ::Spoom::Sorbet::Config).void }

test/spoom/context/sorbet_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ def test_context_srb_files_with_custom_config
367367
context.write!("h.js", "")
368368
context.write!("i", "")
369369

370-
config = Spoom::Sorbet::Config.new
371-
config.paths = ["b", "d"]
370+
config = Spoom::Sorbet::Config.new(paths: ["b", "d"])
372371

373372
assert_equal(["b/c.rb", "d/e/f.rbi"], context.srb_files(with_config: config))
374373

0 commit comments

Comments
 (0)