Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nolint directive ignored #3201

Closed
4 tasks done
rekby opened this issue Sep 9, 2022 · 3 comments
Closed
4 tasks done

nolint directive ignored #3201

rekby opened this issue Sep 9, 2022 · 3 comments
Labels
area: nolint Related to nolint directive and nolintlint question Further information is requested

Comments

@rekby
Copy link

rekby commented Sep 9, 2022

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

I have nolint directive at top of file.
golangcilint report me about some linter rules bad, then report about nolint unused.

Expected result: quite ignore all linters.

Version of golangci-lint

$ /usr/local/bin/golangci-lint --version
golangci-lint has version 1.49.0 built from cc2d97f on 2022-08-23T12:03:20Z

Configuration file

$ cat .golangci.yml

no config

Go environment

$ go version && go env
➤ go version && go env
go version go1.19.1 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rekby/Library/Caches/go-build"
GOENV="/Users/rekby/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rekby/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rekby/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.19.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.19.1/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8_/68c7r6rj6xg4fpjls__qtsjn18s1hz/T/go-build602686221=/tmp/go-build -gno-record-gcc-switches -fno-common"

Verbose output of running

$ /usr/local/bin/golangci-lint cache clean
$ /usr/local/bin/golangci-lint run -v --enable-all
INFO [config_reader] Config search paths: [./ /Users/rekby/projects/rekby/tmp-go /Users/rekby/projects/rekby /Users/rekby/projects /Users/rekby /Users /]
INFO [lintersdb] Active 98 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck cyclop deadcode decorder depguard dogsled dupl durationcheck errcheck errchkjson errname errorlint execinquery exhaustive exhaustivestruct exhaustruct exportloopref forbidigo forcetypeassert funlen gci gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo godot godox goerr113 gofmt gofumpt goheader goimports golint gomnd gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper ifshort importas ineffassign interfacebloat interfacer ireturn lll logrlint maintidx makezero maligned misspell nakedret nestif nilerr nilnil nlreturn noctx nolintlint nonamedreturns nosnakecase nosprintfhostport paralleltest prealloc predeclared promlinter reassign revive rowserrcheck scopelint sqlclosecheck staticcheck structcheck stylecheck tagliatelle tenv testpackage thelper tparallel typecheck unconvert unparam unused usestdlibvars varcheck varnamelen wastedassign whitespace wrapcheck wsl]
INFO [loader] Go packages loading at mode 575 (imports|compiled_files|deps|files|types_sizes|exports_file|name) took 236.33534ms
WARN [runner] The linter 'nosnakecase' is deprecated (since v1.48.1) due to: The repository of the linter has been deprecated by the owner.  Replaced by revive(var-naming).
WARN [runner] The linter 'exhaustivestruct' is deprecated (since v1.46.0) due to: The owner seems to have abandoned the linter.  Replaced by exhaustruct.
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner.  Replaced by revive.
WARN [runner] The linter 'ifshort' is deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner.
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused.
WARN [runner] The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner.  Replaced by exportloopref.
WARN [runner] The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.
WARN [runner] The linter 'maligned' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.  Replaced by govet 'fieldalignment'.
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 837.841µs
INFO [linters context] importas settings found, but no aliases listed. List aliases under alias: key.
INFO [linters context/goanalysis] analyzers took 325.162521ms with top 10 stages: the_only_name: 44.030986ms, buildir: 9.715759ms, contextcheck: 9.066948ms, goimports: 8.969938ms, dupl: 8.635234ms, gocritic: 8.230619ms, gofumpt: 7.6068ms, gofmt: 7.425916ms, misspell: 6.963965ms, unparam: 4.141695ms
WARN [linters context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters context] sqlclosecheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters context] structcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
WARN [linters context] wastedassign is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649.
INFO [runner] Issues before processing: 8, after processing: 4
INFO [runner] Processors filtering stat (out/in): max_from_linter: 4/4, severity-rules: 4/4, cgo: 8/8, exclude-rules: 7/8, nolint: 7/7, max_per_file_from_linter: 4/4, uniq_by_line: 4/7, diff: 4/4, max_same_issues: 4/4, path_prettifier: 8/8, autogenerated_exclude: 8/8, identifier_marker: 8/8, exclude: 8/8, sort_results: 4/4, skip_dirs: 8/8, source_code: 4/4, path_shortener: 4/4, path_prefixer: 4/4, filename_unadjuster: 8/8, skip_files: 8/8
INFO [runner] processing took 1.048906ms with stages: nolint: 291.13µs, exclude-rules: 264.144µs, identifier_marker: 163.321µs, autogenerated_exclude: 148.128µs, source_code: 85.905µs, path_prettifier: 55.396µs, cgo: 12.983µs, skip_dirs: 9.031µs, max_same_issues: 4.271µs, uniq_by_line: 3.536µs, max_from_linter: 2.974µs, filename_unadjuster: 2.645µs, path_shortener: 2.495µs, max_per_file_from_linter: 1.131µs, exclude: 422ns, skip_files: 378ns, diff: 302ns, severity-rules: 302ns, sort_results: 240ns, path_prefixer: 172ns
INFO [runner] linters took 1.462212546s with stages: goanalysis_metalinter: 1.460920938s, wastedassign: 66.436µs, rowserrcheck: 27.784µs, structcheck: 7.492µs, sqlclosecheck: 5.229µs
types.go:35:2: return statements should not be cuddled if block has more than two lines (wsl)
	return 0
	^
types.go:23:1: named return "old" with type "bool" found (nonamedreturns)
func (x *Bool) Swap(new bool) (old bool) { return atomic.SwapUint32(&x.v, b32(new)) != 0 }
^
types.go:26:1: named return "swapped" with type "bool" found (nonamedreturns)
func (x *Bool) CompareAndSwap(old, new bool) (swapped bool) {
^
types.go:1:1: directive `//nolint` is unused (nolintlint)
//nolint
^
INFO File cache stats: 4 entries of total size 2.6KiB
INFO Memory: 19 samples, avg is 53.2MB, max is 66.5MB
INFO Execution took 1.71445329s

Code example or link to a public repository

https://gist.github.com/rekby/a95d6b63626d24a9c2a2314d9aea989a

@rekby rekby added the bug Something isn't working label Sep 9, 2022
@ldez
Copy link
Member

ldez commented Sep 9, 2022

Hello,

you have to use //nolint:all

Due to a change of go fmt inside go1.19.
We have to enforce the directive style.

So the option allow-leading-space has been dropped.

The syntax of directives is: [a-zA-Z]+:[a-zA-Z].*.
The spaces around : and after the // must be removed.

// nolint:foo // <-- malformed
//nolint :foo // <-- malformed
//nolint: foo // <-- malformed

//nolint:foo // <-- OK

If you do that your IDE or go fmt will format the directive as a directive and it will not add extra space.

Related to:
#3002
#1658 (comment)

duplicate of #3098, #3063, #3068, #3101, 3110.

@ldez ldez closed this as completed Sep 9, 2022
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Sep 9, 2022
@rekby
Copy link
Author

rekby commented Sep 13, 2022

@ldez
It has same problem with //nolint:all
https://gist.github.com/rekby/3e0f632817ee2d6993eece0738052744

Also for clean experiment I tried it with docker
https://gist.github.com/rekby/537139df82b5e63d4481e2a4e5e2a8c5

@ldez
Copy link
Member

ldez commented Sep 13, 2022

because the directive must placed on the package name (no blank line):

//nolint:all
package main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: nolint Related to nolint directive and nolintlint question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants