Skip to content

Commit 41b7e5f

Browse files
authored
vdoc: fix handling of .vdocignore files in subdirectories (#21514)
1 parent 9639f55 commit 41b7e5f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

cmd/tools/vdoc/files.v

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import os
44

55
struct IgnoreRules {
66
mut:
7-
patterns map[string]bool = {
8-
'testdata': true
9-
'tests': true
10-
'*_test.v': true
7+
// Ignore patterns use the path with a `.vdocignore` file as a base. E.g.:
8+
// `{'<path>': ['<pattern1>', '<pattern2>'], '<path/subpath>': ['<pattern3>']}`
9+
patterns map[string][]string = {
10+
// Default ignore patterns.
11+
'': ['testdata', 'tests', '*_test.v']
1112
}
1213
paths map[string]bool
1314
}
@@ -25,19 +26,23 @@ fn get_modules(path string) []string {
2526

2627
fn get_paths(path string, mut ignore_rules IgnoreRules) []string {
2728
mut res := []string{}
28-
for p in os.ls(path) or { return [] } {
29+
outer: for p in os.ls(path) or { return [] } {
2930
ignore_rules.get(path)
3031
fp := os.join_path(path, p)
3132
if fp in ignore_rules.paths {
3233
continue
3334
}
3435
is_dir := os.is_dir(fp)
35-
if ignore_rules.patterns.keys().any(p == it
36-
|| (it.contains('*') && p.ends_with(it.all_after('*')))
37-
|| (is_dir && it.ends_with('/') && fp.ends_with(it.trim_right('/')))
38-
|| (!it.ends_with('/') && it.contains('/') && fp.contains(it)))
39-
{
40-
continue
36+
for ignore_path, patterns in ignore_rules.patterns {
37+
if fp.starts_with(ignore_path) {
38+
if patterns.any(p == it
39+
|| (it.contains('*') && p.ends_with(it.all_after('*')))
40+
|| (is_dir && it.ends_with('/') && fp.ends_with(it.trim_right('/')))
41+
|| (!it.ends_with('/') && it.contains('/') && fp.contains(it)))
42+
{
43+
continue outer
44+
}
45+
}
4146
}
4247
if is_dir {
4348
res << get_paths(fp, mut ignore_rules)
@@ -73,7 +78,7 @@ fn (mut ignore_rules IgnoreRules) get(path string) {
7378
// `/a` should ignore `/a` but not `/b/a`. While `a` should ignore `/a` and `/b/a`.
7479
ignore_rules.paths[os.join_path(path, rule.trim_left('/'))] = true
7580
} else {
76-
ignore_rules.patterns[rule] = true
81+
ignore_rules.patterns[path] << rule
7782
}
7883
}
7984
}

0 commit comments

Comments
 (0)