Skip to content

Commit 9428557

Browse files
authored
docs: improve nolint section (#6089)
1 parent b65912b commit 9428557

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

docs/content/docs/linters/false-positives.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Also, you can exclude all issues in a file by:
150150
package pkg
151151
```
152152

153-
You may add a comment explaining or justifying why `//nolint` is being used on the same line as the flag itself:
153+
You may add a comment explaining or justifying why a `nolint` directive is being used on the same line as the flag itself:
154154

155155
```go
156156
//nolint:gocyclo // This legacy function is complex, but the team too busy to simplify it
@@ -159,9 +159,32 @@ func someLegacyFunction() *string {
159159
}
160160
```
161161

162-
You can see more examples of using `//nolint` in [our tests](https://github.com/golangci/golangci-lint/tree/HEAD/pkg/result/processors/testdata) for it.
162+
You can see more examples of using `nolint` directives in [our tests](https://github.com/golangci/golangci-lint/tree/HEAD/pkg/result/processors/testdata) for it.
163163

164-
Use `//nolint` instead of `// nolint` because directives should have no space by Go convention.
164+
### Syntax
165+
166+
`nolint` is not regular comment but a directive.
167+
168+
> A directive comment is a line matching the regular expression `//(line |extern |export |[a-z0-9]+:[a-z0-9])`.
169+
> https://go.dev/doc/comment#syntax
170+
171+
This means that no spaces are allowed between:
172+
- `//` and `nolint`
173+
- `nolint` and `:`
174+
- `:` and the name of the linter.
175+
176+
Invalid syntax:
177+
```go
178+
// nolint
179+
// nolint:xxx
180+
//nolint :xxx
181+
//nolint: xxx
182+
```
183+
184+
Valid syntax:
185+
```go
186+
//nolint:xxx
187+
```
165188

166189
## Exclusion Presets
167190

0 commit comments

Comments
 (0)