@@ -15,10 +15,9 @@ For a complete list of supported rules, visit
15
15
16
16
## Ignore directives
17
17
18
- ### Files
18
+ ### File level
19
19
20
- To ignore the whole file, a ` // deno-lint-ignore-file ` directive should placed
21
- at the top of the file:
20
+ To ignore a whole file use ` // deno-lint-ignore-file ` at the top of the file:
22
21
23
22
``` ts
24
23
// deno-lint-ignore-file
@@ -28,7 +27,7 @@ function foo(): any {
28
27
}
29
28
```
30
29
31
- or
30
+ You can also specify the reason for ignoring the file:
32
31
33
32
``` ts
34
33
// deno-lint-ignore-file -- reason for ignoring
@@ -41,7 +40,7 @@ function foo(): any {
41
40
The ignore directive must be placed before the first statement or declaration:
42
41
43
42
``` ts
44
- // Copyright 2020 the Deno authors. All rights reserved. MIT license.
43
+ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
45
44
46
45
/**
47
46
* Some JS doc
@@ -66,11 +65,25 @@ function foo(): any {
66
65
}
67
66
```
68
67
69
- ### Diagnostics
68
+ If there are multiple ` // deno-lint-ignore-file ` directives, all but the first
69
+ one are ignored:
70
70
71
- To ignore certain diagnostics, the ` // deno-lint-ignore <rules...> ` directive
72
- should be placed before the targeted line. Specifying the ignored rule name is
73
- required:
71
+ ``` ts
72
+ // This is effective
73
+ // deno-lint-ignore-file no-explicit-any no-empty
74
+
75
+ // But this is NOT effective
76
+ // deno-lint-ignore-file no-debugger
77
+
78
+ function foo(): any {
79
+ debugger ; // not ignored!
80
+ }
81
+ ```
82
+
83
+ ### Line level
84
+
85
+ To ignore specific diagnostics use ` // deno-lint-ignore <codes...> ` on the
86
+ preceding line of the offending line.
74
87
75
88
``` ts
76
89
// deno-lint-ignore no-explicit-any
@@ -84,6 +97,8 @@ function bar(a: any) {
84
97
}
85
98
```
86
99
100
+ You must specify the names of the rules to be ignored.
101
+
87
102
You can also specify the reason for ignoring the diagnostic:
88
103
89
104
``` ts
@@ -92,3 +107,33 @@ function foo(): any {
92
107
// ...
93
108
}
94
109
```
110
+
111
+ ## Ignore ` ban-unused-ignore ` itself
112
+
113
+ ` deno lint ` provides [ ` ban-unused-ignore ` rule] ( /lint/rules/ban-unused-ignore/ ) ,
114
+ which will detect ignore directives that don't ever suppress certain
115
+ diagnostics. This is useful when you want to discover ignore directives that are
116
+ no longer necessary after refactoring the code.
117
+
118
+ In a few cases, however, you might want to ignore ` ban-unused-ignore ` rule
119
+ itself. One of the typical cases would be when working with auto-generated
120
+ files; it makes sense to add file-level ignore directives for some rules, and
121
+ there's almost no need for detecting unused directives via ` ban-unused-ignore `
122
+ in this case.
123
+
124
+ You can use ` // deno-lint-ignore-file ban-unused-ignore ` as always if you want
125
+ to suppress the rule for a whole file:
126
+
127
+ ``` ts
128
+ // deno-lint-ignore-file ban-unused-ignore no-explicit-any
129
+
130
+ // `no-explicit-any` isn't used but you'll get no diagnostics because of ignoring
131
+ // `ban-unused-ignore`
132
+ console .log (42 );
133
+ ```
134
+
135
+ Do note that ignoring ` ban-unused-ignore ` itself only works via file-level
136
+ ignore directives. This means that per line directives, like
137
+ ` // deno-lint-ignore ban-unused-ignore ` , don't work at all. If you want to
138
+ ignore ` ban-unused-ignore ` for some special reasons, make sure to add it as a
139
+ file-level ignore directive.
0 commit comments