@@ -4,10 +4,11 @@ import os
4
4
5
5
struct IgnoreRules {
6
6
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' ]
11
12
}
12
13
paths map [string ]bool
13
14
}
@@ -25,19 +26,23 @@ fn get_modules(path string) []string {
25
26
26
27
fn get_paths (path string , mut ignore_rules IgnoreRules) []string {
27
28
mut res := []string {}
28
- for p in os.ls (path) or { return [] } {
29
+ outer: for p in os.ls (path) or { return [] } {
29
30
ignore_rules.get (path)
30
31
fp := os.join_path (path, p)
31
32
if fp in ignore_rules.paths {
32
33
continue
33
34
}
34
35
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
+ }
41
46
}
42
47
if is_dir {
43
48
res << get_paths (fp, mut ignore_rules)
@@ -73,7 +78,7 @@ fn (mut ignore_rules IgnoreRules) get(path string) {
73
78
// `/a` should ignore `/a` but not `/b/a`. While `a` should ignore `/a` and `/b/a`.
74
79
ignore_rules.paths[os.join_path (path, rule.trim_left ('/' ))] = true
75
80
} else {
76
- ignore_rules.patterns[rule] = true
81
+ ignore_rules.patterns[path] << rule
77
82
}
78
83
}
79
84
}
0 commit comments