Skip to content

Commit 98f5949

Browse files
authored
Merge pull request #1113 from euglena1215/fix-check-wildcard
Fix issue with wildcard expansion in FileLoader
2 parents 5430b52 + 571deca commit 98f5949

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

lib/steep/services/file_loader.rb

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,25 @@ def each_path_in_patterns(pattern, commandline_patterns = [])
1212
pats = commandline_patterns.empty? ? pattern.patterns : commandline_patterns
1313

1414
pats.each do |path|
15-
absolute_path = base_dir + path
16-
17-
if absolute_path.file?
18-
relative_path = absolute_path.relative_path_from(base_dir)
19-
if pattern =~ relative_path
20-
yield relative_path
21-
end
22-
else
23-
files = if absolute_path.directory?
24-
Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
25-
else
26-
Pathname.glob(absolute_path.to_s)
27-
end
28-
29-
files.sort.each do |source_path|
30-
if source_path.file?
31-
relative_path = source_path.relative_path_from(base_dir)
32-
unless pattern.ignore?(relative_path)
33-
yield relative_path
15+
Pathname.glob((base_dir + path).to_s).each do |absolute_path|
16+
if absolute_path.file?
17+
relative_path = absolute_path.relative_path_from(base_dir)
18+
if pattern =~ relative_path
19+
yield relative_path
20+
end
21+
else
22+
files = Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
23+
24+
files.sort.each do |source_path|
25+
if source_path.file?
26+
relative_path = source_path.relative_path_from(base_dir)
27+
unless pattern.ignore?(relative_path)
28+
yield relative_path
29+
end
3430
end
3531
end
3632
end
3733
end
38-
3934
end
4035
else
4136
enum_for :each_path_in_patterns, pattern, commandline_patterns

test/file_loader_test.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,34 @@ def test_each_path_in_patterns
3333
assert_empty loader.each_path_in_patterns(pat, ["Rakefile"]).to_a
3434
end
3535
end
36+
37+
def test_each_path_in_patterns_with_glob
38+
in_tmpdir do
39+
loader = FileLoader.new(base_dir: current_dir)
40+
41+
(current_dir + "lib/foo/bar").mkpath()
42+
(current_dir + "lib/foo/bar/baz.rb").write("")
43+
(current_dir + "lib/foo/parser.rb").write("")
44+
(current_dir + "lib/foo/bar/index.html.erb").write("")
45+
46+
pat = Pattern.new(patterns: ["lib/*/bar"], ext: ".rb")
47+
48+
assert_equal [Pathname("lib/foo/bar/baz.rb")], loader.each_path_in_patterns(pat, []).to_a
49+
end
50+
end
51+
52+
def test_each_path_in_patterns_with_glob_and_ext
53+
in_tmpdir do
54+
loader = FileLoader.new(base_dir: current_dir)
55+
56+
(current_dir + "lib/foo/bar").mkpath()
57+
(current_dir + "lib/foo/bar/baz.rb").write("")
58+
(current_dir + "lib/foo/parser.rb").write("")
59+
(current_dir + "lib/foo/bar/index.html.erb").write("")
60+
61+
pat = Pattern.new(patterns: ["lib/*/bar/baz.rb"], ext: ".rb")
62+
63+
assert_equal [Pathname("lib/foo/bar/baz.rb")], loader.each_path_in_patterns(pat, []).to_a
64+
end
65+
end
3666
end

0 commit comments

Comments
 (0)