Skip to content

Commit 07efa4c

Browse files
doc: explain correct globbing behavior
fix #749
1 parent 98c89c8 commit 07efa4c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

website/guide/project/lint-rule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ ignores:
146146
- "tests/config/**"
147147
```
148148

149-
`ignores` and `files` can be used together. But `files` will take precedence over `ignores`.
149+
`ignores` and `files` can be used together. `ignores` will be tested before `files`. See [reference](/reference/yaml.html#ignores) for more details.
150150

151151
:::warning Don't add `./`
152152

website/reference/yaml.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,21 @@ Please also see [label guide](/guide/project/lint-rule.html#customize-code-highl
232232
* type: `Array<String>`
233233
* required: false
234234

235-
Glob patterns to specify that the rule only applies to matching files. It takes priority over `ignores`.
235+
Glob patterns to specify that the rule only applies to matching files. It is tested if `ignores` does not exist or a file does not match any `ignores` glob.
236+
237+
**Example:**
236238

237-
Example:
238239
```yaml
239240
files:
240241
- src/**/*.js
241242
- src/**/*.ts
242243
```
243244

245+
:::warning Don't add `./`
246+
Be sure to remove `./` to the beginning of your rules. ast-grep will not recognize the paths if you add `./`.
247+
:::
248+
249+
244250
### `ignores`
245251
* type: `Array<String>`
246252
* required: false
@@ -251,18 +257,20 @@ ignores:
251257
- test/**/*.ts
252258
```
253259

254-
Glob patterns that exclude rules from applying to files. It is superseded by `files` if both are specified.
260+
Glob patterns that exclude rules from applying to files. A file is tested against `ignores` list before matching `files`.
261+
262+
A typical globing process works as follows:
263+
264+
1. If `ignores` is configured, a file will be skipped if it matches any of the glob in the list(`files` will not be tested).
265+
2. If `files` is configured, a file will be included if and only if it matches one of the glob in the list.
266+
3. If neither `ignores`/`files` is configured, a file is included by default.
255267

256268
:::warning `ignores` in YAML is different from `--no-ignore` in CLI
257269
ast-grep respects common ignore files like `.gitignore` and hidden files by default.
258270
To disable this behavior, use [`--no-ignore`](/reference/cli.html#scan) in CLI.
259271
`ignores` is a rule-wise configuration that only filters files that are not ignored by the CLI.
260272
:::
261273

262-
:::warning Don't add `./`
263-
Be sure to remove `./` to the beginning of your rules. ast-grep will not recognize the paths if you add `./`.
264-
:::
265-
266274

267275
## Other
268276

0 commit comments

Comments
 (0)