Skip to content

Commit 34f0fb2

Browse files
doc: add file level suppression
1 parent 181d07f commit 34f0fb2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

website/guide/project/severity.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,38 @@ These are the rules for suppression comments:
6161
* You can turn off multiple rules by providing a comma-separated list in the comment. e.g. `ast-grep-ignore: rule-1, rule-2`
6262
* Suppression comments will suppress the next line diagnostic if and only if there is no preceding ASTs on the same line.
6363

64+
## File Level Suppression
6465

66+
You can also suppress all diagnostics in a file by adding a suppression comment at the top of the file followed by an empty line. This is useful when you want to ignore all diagnostics in a file.
67+
68+
For example, in JavaScript:
69+
70+
:::code-group
71+
```javascript [Disable all rules]
72+
// ast-grep-ignore
73+
74+
// This file will not be scanned by ast-grep
75+
// note the empty line after the suppression comment.
76+
debugger // this line will not be scanned
77+
console.debug('debugging') // this line will not be scanned
78+
```
79+
80+
```javascript{6} [Disable sepcific rules]
81+
// ast-grep-ignore: no-debugger
82+
83+
// This file will not be scanned by ast-grep
84+
// note the empty line after the suppression comment.
85+
debugger // this line will not trigger error
86+
console.debug('debugging') // this line will trigger error
87+
```
88+
89+
:::
90+
91+
To suppress the whole file, there must be [two conditions](https://github.com/ast-grep/ast-grep/issues/1541#issuecomment-2573212686) met:
92+
* The suppression comment is on the very first line of the file.
93+
* AND the next line (second line in file) is empty
94+
95+
These conditions are designed for backward compatibility.
6596

6697
## Report Unused Suppressions
6798

0 commit comments

Comments
 (0)