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

golangci-lint run --disable-all does not disable all linters #3453

Closed
4 tasks done
stdedos opened this issue Jan 3, 2023 · 3 comments
Closed
4 tasks done

golangci-lint run --disable-all does not disable all linters #3453

stdedos opened this issue Jan 3, 2023 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@stdedos
Copy link

stdedos commented Jan 3, 2023

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 (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

$ golangci-lint run -v --disable-all 
INFO [config_reader] Config search paths: [./ /home/stdedos/Documents/RelexOy/shift-optimization-algorithm /home/stdedos/Documents/RelexOy /home/stdedos/Documents /home/stdedos /home /] 
INFO [config_reader] Used config file golang-utilities/test_scripts/.golangci.yml 
INFO [lintersdb] Active 10 linters: [exhaustive gocritic gofumpt goimports gomnd prealloc revive stylecheck unparam wastedassign] 
INFO [loader] Go packages loading at mode 575 (files|name|types_sizes|compiled_files|deps|exports_file|imports) took 223.491004ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 9.90698ms 
...

I am trying to do $ golangci-lint run -v --disable-all -E goimports, with the intention of only running goimports.
golangci-lint runs successfully, but my intention fails miserably.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.50.1 built from 8926a95f on 2022-10-22T10:50:47Z

Configuration file

$ cat .golangci.yml
run:
  timeout: 10m

linters:
  fast: false
  enable:
    - revive
    - unparam
    - wastedassign
    - exhaustive
    - gomnd
    - gofumpt
    - goimports
    - stylecheck
    - prealloc
    - gocritic

linters-settings:
  govet:
    check-shadowing: true
  goimports:
    local-prefixes: <local prefix>
  gocritic:
    enabled-checks:
      # first default checks
      - appendAssign
      - argOrder
      - assignOp
      - badCall
      - badCond
      - captLocal
      - caseOrder
      - codegenComment
      # - commentFormatting # conflict with gofumpt and --fix
      - defaultCaseOrder
      - deprecatedComment
      - dupArg
      - dupBranchBody
      - dupCase
      - dupSubExpr
      - elseif
      - exitAfterDefer
      - flagDeref
      - flagName
      - ifElseChain
      - mapKey
      - newDeref
      - offBy1
      - regexpMust
      - singleCaseSwitch
      - sloppyLen
      - sloppyTypeAssert
      - switchTrue
      - typeSwitchVar
      - underef
      - unlambda
      - unslice
      - valSwap
      - wrapperFunc
      # non-defaults
      # perf
      - appendCombine
      - equalFold
      - indexAlloc
      - preferDecodeRune
      - preferFprint
      - preferStringWriter
      - preferWriteByte
      - rangeExprCopy
      - sliceClear
      - stringXbytes
      # style
      - boolExprSimplify
      - commentedOutImport
      - deferUnlambda
      - emptyStringTest
      - hexLiteral
      - httpNoBody
      - importShadow
      - initClause
      - methodExprCall
      - preferFilepathJoin
      - ptrToRefParam
      - redundantSprint
      - regexpSimplify
      - stringConcatSimplify
      - timeExprSimplify
      # - typeDefFirst # disabled for generics
      - typeUnparen
      - unlabelStmt
      - unnecessaryBlock
      - yodaStyleExpr
      # diagnostics
      - badLock
      - badRegexp
      - builtinShadowDecl
      - emptyDecl
      - evalOrder
      # - externalErrorReassign # disabled for generics
      - filepathJoin
      - nilValReturn
      - regexpPattern
      - returnAfterHttpError
      - sloppyReassign
      - sortSlice
      - sprintfQuotedString
      - sqlQuery
      # - suspiciousSorting # add this when updating linter
      - syncMapLoadAndDelete
      - truncateCmp
      - unnecessaryDefer
      - weakCond

issues:
  exclude-rules:
    - linters:
        - revive
      text: "var-naming: don't use leading k in Go names"
    - linters:
        - revive
      text: "package-comments: should have a package comment"
    - linters:
      - unparam
      text: "always receives"
  include:
    - EXC0012
    - EXC0013
    - EXC0014

severity:
  default-severity: Major

output:
  format: code-climate
  uniq-by-line: false

Go environment

$ go version && go env
go version go1.19.4 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/stdedos/.cache/go-build"
GOENV="/home/stdedos/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/stdedos/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/stdedos/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.19"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.19/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="<proj/path>/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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3396845793=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

Code example or link to a public repository

Private repo 🤷
// add your code here
@stdedos stdedos added the bug Something isn't working label Jan 3, 2023
@ldez ldez added duplicate This issue or pull request already exists and removed bug Something isn't working labels Jan 3, 2023
@ldez
Copy link
Member

ldez commented Jan 3, 2023

duplicate of #1188 #1972 ...

@ldez ldez closed this as completed Jan 3, 2023
@stdedos
Copy link
Author

stdedos commented Jan 3, 2023

The underlying question of this and #1972 is still not answered:

How can one run a singular linter, if --enable*/--disable* flags merge instead of overwrite?

@kerma
Copy link

kerma commented Feb 1, 2023

I came here to report the same issue (second time in 6 months). Given that this has been popping up quite a bit in the past would the maintainers consider changing this behavior to be more in line of what users actually expect?

The (standard?) behavior for CLI arguments is that they override what's specified in other sources, like environment or config file.

In order to just run one linter one needs to:

golangci-lint run --no-config --disable-all --enable nilnil ./...

.. but you may need to add more arguments depending on how much you have changed under run and issues sections.

Also, if you look at the --help output for run, there is nothing to suggest that this clever "merge" is happening:

  -E, --enable strings                 Enable specific linter
  -D, --disable strings                Disable specific linter
      --enable-all                     Enable all linters
      --disable-all                    Disable all linters

At minimum please add a warning to help output and the relevant docs section that it would be clear that these arguments do not override config file values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants