Skip to content

Commit 4482f1f

Browse files
authored
lint: update ignore directives manual (#1285)
1 parent 83ef793 commit 4482f1f

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

go.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"ide": "/runtime/getting_started/setup_your_environment/#setting-up-your-editor%2Fide",
2525
"import_maps": "/runtime/manual/basics/import_maps",
2626
"info": "/runtime/manual/tools/info",
27+
"lint-ignore": "/runtime/reference/cli/lint/#ignore-directives",
2728
"lint": "/runtime/manual/tools/lint",
2829
"lsp": "/runtime/reference/cli/lsp",
2930
"permissions": "/runtime/fundamentals/security/",

runtime/reference/cli/lint.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ For a complete list of supported rules, visit
1515

1616
## Ignore directives
1717

18-
### Files
18+
### File level
1919

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:
2221

2322
```ts
2423
// deno-lint-ignore-file
@@ -28,7 +27,7 @@ function foo(): any {
2827
}
2928
```
3029

31-
or
30+
You can also specify the reason for ignoring the file:
3231

3332
```ts
3433
// deno-lint-ignore-file -- reason for ignoring
@@ -41,7 +40,7 @@ function foo(): any {
4140
The ignore directive must be placed before the first statement or declaration:
4241

4342
```ts
44-
// Copyright 2020 the Deno authors. All rights reserved. MIT license.
43+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
4544

4645
/**
4746
* Some JS doc
@@ -66,11 +65,25 @@ function foo(): any {
6665
}
6766
```
6867

69-
### Diagnostics
68+
If there are multiple `// deno-lint-ignore-file` directives, all but the first
69+
one are ignored:
7070

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.
7487

7588
```ts
7689
// deno-lint-ignore no-explicit-any
@@ -84,6 +97,8 @@ function bar(a: any) {
8497
}
8598
```
8699

100+
You must specify the names of the rules to be ignored.
101+
87102
You can also specify the reason for ignoring the diagnostic:
88103

89104
```ts
@@ -92,3 +107,33 @@ function foo(): any {
92107
// ...
93108
}
94109
```
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

Comments
 (0)