Skip to content

Commit

Permalink
Introduces a new target.* syntax for everything in the target
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Dec 6, 2024
1 parent eec99a4 commit 2274975
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
11 changes: 9 additions & 2 deletions lib/steep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ def process_check
end

opts.on("--group=GROUP", "Specify target/group name to type check") do |arg|
# @type var group: String
# @type var arg: String
target, group = arg.split(".")
target or raise
command.active_group_names << [target.to_sym, group&.to_sym]
case group
when "*"
command.active_group_names << [target.to_sym, true]
when nil
command.active_group_names << [target.to_sym, nil]
else
command.active_group_names << [target.to_sym, group.to_sym]
end
end

opts.on("--[no-]type-check", "Type check Ruby code") do |v|
Expand Down
6 changes: 3 additions & 3 deletions lib/steep/drivers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def active_group?(group)
case group
when Project::Target
active_group_names.any? {|target_name, group_name|
target_name == group.name && group_name == nil
target_name == group.name && (group_name == nil || group_name == true)
}
when Project::Group
active_group_names.any? {|target_name, group_name|
target_name == group.target.name &&
(group_name == group.name || group_name.nil?)
(group_name == group.name || group_name == true)
}
end
end
Expand Down Expand Up @@ -206,7 +206,7 @@ def run

def load_files(files, target, group, params:)
if type_check_code
files.each_group_source_path(group) do |path|
files.each_group_source_path(group, true) do |path|
params[:code_paths] << [target.name.to_s, target.project.absolute_path(path).to_s]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/server/type_check_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def make_group_request(groups, progress:)
request.code_paths << [target_group.name, path]
end
else
group_set = groups.map do |group_name|
group_set = groups.filter_map do |group_name|
target_name, group_name = group_name.split(".", 2)
target_name or raise

Expand All @@ -280,7 +280,7 @@ def make_group_request(groups, progress:)
else
project.targets.find {|target| target.name == target_name }
end
end.compact.to_set
end.to_set

files.signature_paths.each do |path, target_group|
if group_set.include?(target_group)
Expand Down
2 changes: 1 addition & 1 deletion sig/steep/drivers/check.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Steep

attr_reader jobs_option: Utils::JobsOption

attr_reader active_group_names: Array[[Symbol, Symbol?]]
attr_reader active_group_names: Array[[Symbol, Symbol | true | nil]]

attr_accessor type_check_code: bool

Expand Down
52 changes: 52 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,58 @@ def test_check_group__group
end
end

def test_check_group__group__target
in_tmpdir do
(current_dir + "Steepfile").write(<<-EOF)
target :app do
group :foo do
check "foo.rb"
end
group :bar do
check "bar.rb"
end
check "baz.rb"
end
EOF

(current_dir + "foo.rb").write(<<-EOF)
1 + "2"
EOF
(current_dir + "bar.rb").write(<<-EOF)
1 + "2"
EOF
(current_dir + "baz.rb").write(<<-EOF)
1 + "2"
EOF

stdout, _ = sh(*steep, "check", "--group=app.foo")

assert_match(/^foo.rb:1:0/, stdout)
refute_match(/^bar.rb/, stdout)
refute_match(/^baz.rb/, stdout)

stdout, _ = sh(*steep, "check", "--group=app.bar")

refute_match(/^foo.rb/, stdout)
assert_match(/^bar.rb:1:0/, stdout)
refute_match(/^baz.rb/, stdout)

stdout, _ = sh(*steep, "check", "--group=app.*")

assert_match(/^foo.rb:1:0/, stdout)
assert_match(/^bar.rb:1:0/, stdout)
assert_match(/^baz.rb:1:0/, stdout)

stdout, _ = sh(*steep, "check", "--group=app")

refute_match(/^foo.rb/, stdout)
refute_match(/^bar.rb/, stdout)
assert_match(/^baz.rb:1:0/, stdout)
end
end

def test_check_failure_severity_level
in_tmpdir do
(current_dir + "Steepfile").write(<<-EOF)
Expand Down

0 comments on commit 2274975

Please sign in to comment.