golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.65k stars 1.39k forks source link

Using enable-all. Custom linter does not work. #3080

Closed yuqengo closed 1 year ago

yuqengo commented 2 years ago

Welcome

Description of the problem

example linter does not work with this .golangci.yml .

linters-settings:
  custom:
    example:
      path: ./example.so

linters:
  enable-all: true
$ golangci-lint run -v testdata/src/testlintdata/todo/todo.go                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
INFO [config_reader] Config search paths: [./ ${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata/todo /${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata ${home}/go/src/github.com/example-plugin-linter/testdata/src ${home}/go/src/github.com/example-plugin-linter/testdata ${home}/go/src/github.com/example-plugin-linter${home}/go/src/github.com ${home}/go/src ${home}/go ${home} /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO Loaded ./example.so: example                 
INFO [lintersdb] Active 95 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 interfacer ireturn lll maintidx makezero maligned misspell nakedret nestif nilerr nilnil nlreturn noctx nolintlint nonamedreturns nosnakecase nosprintfhostport paralleltest prealloc predeclared promlinter revive rowserrcheck scopelint sqlclosecheck staticcheck structcheck stylecheck tagliatelle tenv testpackage thelper tparallel typecheck unconvert unparam unused usestdlibvars varcheck varnamelen wastedassign whitespace wrapcheck wsl] 

Related issue: https://github.com/golangci/golangci-lint/issues/1335 But this issue was closed.

Version of golangci-lint

```console $ golangci-lint --version # Paste output here ```
$ golangci-lint --version
golangci-lint has version v1.48.0 built from (unknown, mod sum: "h1:hRiBNk9iRqdAKMa06ntfEiLyza1/3IE9rHLNJaek4a8=") on (unknown)

Configuration file

```console $ cat .golangci.yml linters-settings: custom: example: path: ./example.so linters: enable-all: true ```

Go environment

```console $ go version && go env go version go1.19 darwin/amd64 GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/mydir/Library/Caches/go-build" GOENV="/mydir/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/mydir/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/mydir/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/mydir/go/go1.19" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/mydir/go/go1.19/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/mydir/go/src/github.com/example-plugin-linter/go.mod" 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/cq/w8dcz0q94m7dpp5crzp623b5kzj1nl/T/go-build3223704989=/tmp/go-build -gno-record-gcc-switches -fno-common" ```

Verbose output of running

Code example: https://github.com/yuqengo/example-plugin-linter ## using enable-all ```console $ cat .golangci.yml linters-settings: custom: example: path: ./example.so linters: enable-all: true ``` ```console $ golangci-lint cache clean $ golangci-lint run -v testdata/src/testlintdata/todo/todo.go INFO [config_reader] Config search paths: [./ ${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata/todo /${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata ${home}/go/src/github.com/example-plugin-linter/testdata/src ${home}/go/src/github.com/example-plugin-linter/testdata ${home}/go/src/github.com/example-plugin-linter${home}/go/src/github.com ${home}/go/src ${home}/go ${home} /Users /] INFO [config_reader] Used config file .golangci.yml INFO Loaded ./example.so: example INFO [lintersdb] Active 95 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 interfacer ireturn lll maintidx makezero maligned misspell nakedret nestif nilerr nilnil nlreturn noctx nolintlint nonamedreturns nosnakecase nosprintfhostport paralleltest prealloc predeclared promlinter 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 (types_sizes|compiled_files|name|files|imports|deps|exports_file) took 80.433823ms 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 'ifshort' is deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner. 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 '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 '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 '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 587.677µs WARN [linters context] contextcheck 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 [linters context] importas settings found, but no aliases listed. List aliases under alias: key. INFO [linters context/goanalysis] analyzers took 160.660979ms with top 10 stages: the_only_name: 32.434752ms, gocritic: 11.810725ms, buildir: 9.02466ms, gofumpt: 7.555906ms, goimports: 7.166155ms, gci: 6.881859ms, dupl: 6.879723ms, gofmt: 6.618409ms, fact_deprecated: 6.542322ms, ctrlflow: 6.326471ms 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/max_same_issues] 1/4 issues with text "Comment should end in a period" were hidden, use --max-same-issues INFO [runner] Issues before processing: 23, after processing: 6 INFO [runner] Processors filtering stat (out/in): autogenerated_exclude: 23/23, source_code: 6/6, path_shortener: 6/6, cgo: 23/23, filename_unadjuster: 23/23, uniq_by_line: 7/10, diff: 7/7, max_per_file_from_linter: 7/7, severity-rules: 6/6, path_prefixer: 6/6, path_prettifier: 23/23, skip_files: 23/23, skip_dirs: 23/23, exclude: 23/23, exclude-rules: 10/23, max_from_linter: 6/6, identifier_marker: 23/23, nolint: 10/10, max_same_issues: 6/7, sort_results: 6/6 INFO [runner] processing took 21.044022ms with stages: autogenerated_exclude: 17.648823ms, exclude-rules: 918.479µs, identifier_marker: 794.314µs, nolint: 791.905µs, source_code: 678.1µs, path_prettifier: 125.632µs, max_same_issues: 40.958µs, skip_dirs: 19.844µs, uniq_by_line: 6.887µs, filename_unadjuster: 4.785µs, cgo: 4.378µs, max_per_file_from_linter: 3.294µs, max_from_linter: 2.605µs, path_shortener: 2.091µs, sort_results: 375ns, severity-rules: 371ns, skip_files: 365ns, diff: 318ns, exclude: 307ns, path_prefixer: 191ns INFO [runner] linters took 847.632462ms with stages: goanalysis_metalinter: 826.337053ms, wastedassign: 45.787µs, rowserrcheck: 13.532µs, contextcheck: 12.085µs, sqlclosecheck: 6.364µs, structcheck: 5.234µs testdata/src/testlintdata/todo/todo.go:3:27: Comment should end in a period (godot) // comment without a to do ^ testdata/src/testlintdata/todo/todo.go:8:59: Comment should end in a period (godot) // TODO: do something // want "TODO comment has no author" ^ testdata/src/testlintdata/todo/todo.go:13:61: Comment should end in a period (godot) // TODO(): do something // want "TODO comment has no author" ^ testdata/src/testlintdata/todo/todo.go:10:10: mnd: Magic number: 2, in detected (gomnd) _ = 1 + 2 ^ testdata/src/testlintdata/todo/todo.go:15:10: mnd: Magic number: 3, in detected (gomnd) _ = 1 + 3 ^ testdata/src/testlintdata/todo/todo.go:20:10: mnd: Magic number: 4, in detected (gomnd) _ = 1 + 4 ^ INFO File cache stats: 2 entries of total size 676B INFO Memory: 11 samples, avg is 56.7MB, max is 58.5MB INFO Execution took 949.439448ms ``` ## using enable ```console $ cat .golangci.yml linters-settings: custom: example: path: ./example.so linters: disable-all: true enable: - example ``` ```console $ golangci-lint cache clean $ golangci-lint run -v testdata/src/testlintdata/todo/todo.go INFO [config_reader] Config search paths: [./ ${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata/todo ${home}/go/src/github.com/example-plugin-linter/testdata/src/testlintdata ${home}/go/src/github.com/example-plugin-linter/testdata/src ${home}/go/src/github.com/example-plugin-linter/testdata ${home}/go/src/github.com/example-plugin-linter ${home}/go/src/github.com ${home}/go/src ${home}/go ${home} /Users /] INFO [config_reader] Used config file .golangci.yml INFO Loaded ./example.so: example INFO [lintersdb] Active 1 linters: [example] INFO [loader] Go packages loading at mode 7 (name|files|compiled_files) took 75.683456ms INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 686.716µs INFO [linters context/goanalysis] analyzers took 94.098µs with top 10 stages: todo: 94.098µs INFO [runner] Processors filtering stat (out/in): cgo: 2/2, filename_unadjuster: 2/2, identifier_marker: 2/2, exclude: 2/2, uniq_by_line: 2/2, max_per_file_from_linter: 2/2, max_same_issues: 2/2, max_from_linter: 2/2, path_shortener: 2/2, sort_results: 2/2, path_prettifier: 2/2, exclude-rules: 2/2, diff: 2/2, source_code: 2/2, skip_files: 2/2, skip_dirs: 2/2, severity-rules: 2/2, autogenerated_exclude: 2/2, nolint: 2/2, path_prefixer: 2/2 INFO [runner] processing took 1.957274ms with stages: autogenerated_exclude: 621.962µs, nolint: 585.109µs, source_code: 536.606µs, path_prettifier: 112.725µs, identifier_marker: 42.967µs, exclude-rules: 22.913µs, skip_dirs: 13.518µs, uniq_by_line: 8.757µs, max_from_linter: 4.033µs, max_same_issues: 2.433µs, cgo: 1.416µs, path_shortener: 1.194µs, filename_unadjuster: 936ns, max_per_file_from_linter: 908ns, sort_results: 546ns, skip_files: 313ns, severity-rules: 279ns, diff: 265ns, exclude: 261ns, path_prefixer: 133ns INFO [runner] linters took 7.313312ms with stages: example: 5.238708ms testdata/src/testlintdata/todo/todo.go:8:1: todo: TODO comment has no author (example) // TODO: do something // want "TODO comment has no author" ^ testdata/src/testlintdata/todo/todo.go:13:1: todo: TODO comment has no author (example) // TODO(): do something // want "TODO comment has no author" ^ INFO File cache stats: 1 entries of total size 338B INFO Memory: 3 samples, avg is 54.6MB, max is 54.7MB INFO Execution took 101.442545ms ```

Code example or link to a public repository

```go // add your code here ```

https://github.com/yuqengo/example-plugin-linter

boring-cyborg[bot] commented 2 years ago

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

ldez commented 2 years ago

Hello,

you have to explicitly activate your linter as it is not in the list of know/embedded linters.

The enable-all option only enables know/embedded linters.

yuqengo commented 2 years ago

Can this issue be reopened? I think it is inconvenient that custom linters are not available when in enable-all.

I suggest a solution to this issue. (https://github.com/golangci/golangci-lint/pull/3085)