From 44f753bb9c022d0d30aeee08b3f3b6e1af682c6d Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 19 Sep 2025 15:03:00 +0200 Subject: [PATCH 1/2] docs: improve nolint section --- docs/content/docs/linters/false-positives.md | 29 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/content/docs/linters/false-positives.md b/docs/content/docs/linters/false-positives.md index ff6643ee4f3e..5abfc9366935 100644 --- a/docs/content/docs/linters/false-positives.md +++ b/docs/content/docs/linters/false-positives.md @@ -150,7 +150,7 @@ Also, you can exclude all issues in a file by: package pkg ``` -You may add a comment explaining or justifying why `//nolint` is being used on the same line as the flag itself: +You may add a comment explaining or justifying why a `nolint` directive is being used on the same line as the flag itself: ```go //nolint:gocyclo // This legacy function is complex, but the team too busy to simplify it @@ -159,9 +159,32 @@ func someLegacyFunction() *string { } ``` -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. +You can see more examples of using `nolint` directives direct in [our tests](https://github.com/golangci/golangci-lint/tree/HEAD/pkg/result/processors/testdata) for it. -Use `//nolint` instead of `// nolint` because directives should have no space by Go convention. +### Syntax + +`nolint` is not regular comment but a directive. + +> A directive comment is a line matching the regular expression `//(line |extern |export |[a-z0-9]+:[a-z0-9])`. +> https://go.dev/doc/comment#syntax + +This means that no spaces are allowed between: +- `//` and `nolint` +- `nolint` and `:` +- `:` and the name of the linter. + +Invalid syntax: +```go +// nolint +// nolint:xxx +//nolint :xxx +//nolint: xxx +``` + +Valid syntax: +```go +//nolint:xxx +``` ## Exclusion Presets From f3ad4ba236a08a78624130b5e5c37867af3ff941 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 19 Sep 2025 22:38:42 +0200 Subject: [PATCH 2/2] review: typos --- docs/content/docs/linters/false-positives.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/docs/linters/false-positives.md b/docs/content/docs/linters/false-positives.md index 5abfc9366935..144868e0d61b 100644 --- a/docs/content/docs/linters/false-positives.md +++ b/docs/content/docs/linters/false-positives.md @@ -159,7 +159,7 @@ func someLegacyFunction() *string { } ``` -You can see more examples of using `nolint` directives direct in [our tests](https://github.com/golangci/golangci-lint/tree/HEAD/pkg/result/processors/testdata) for it. +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. ### Syntax