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

Disabling alias silently disables enabled linters #3746

Closed
4 tasks done
matthewhughes934 opened this issue Mar 29, 2023 · 7 comments
Closed
4 tasks done

Disabling alias silently disables enabled linters #3746

matthewhughes934 opened this issue Mar 29, 2023 · 7 comments
Labels
area: config Related to .golangci.yml and/or cli options bug Something isn't working won't fix This will not be worked on

Comments

@matthewhughes934
Copy link
Contributor

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

Given the file:

$ cat bare.go 
package barepkg

func SomeFunc() {
	if 1 == 1 {}	// trigger staticcheck error
}

Running with staticcheck reports an issue as expected:

$ ./golangci-lint run --no-config --enable staticcheck bare.go 
bare.go:4:2: SA9003: empty branch (staticcheck)
	if 1 == 1 {}	// trigger staticcheck error
	^

Disabling and enabling staticcheck errors as expected:

$ ./golangci-lint run --no-config --enable staticcheck --disable staticcheck bare.go 
ERRO Running error: linter "staticcheck" can't be disabled and enabled at one moment 

but Disabling megacheck (alias for staticcheck) and enabling staticcheck silently disables staticcheck:

$ ./golangci-lint run --no-config --enable staticcheck --disable megacheck bare.go
$ echo $?
0

Version of golangci-lint

Tested on 1.52.1 and the current head of master: ca05239

$ golangci-lint --version
golangci-lint has version 1.52.1 built with go1.20.2 from d92b38cc on 2023-03-21T19:48:38Z
$ ./golangci-lint --version
golangci-lint has version (devel) built with go1.20.2 from (unknown, mod sum: "") on (unknown

Configuration file

No config, see flags in description

Go environment

$ go version && go env | sed 's/mjh/me/g'
go version go1.20.2 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOENV="/home/me/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/me/.local/share/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/me/.local/share/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/me/src/golangci-lint/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build635768465=/tmp/go-build -gno-record-gcc-switches

Verbose output of running

Adding verbosity to example above

$ golangci-lint cache clean
$ ./golangci-lint run --verbose --no-config --enable staticcheck --disable megacheck bare.go 
INFO [lintersdb] Active 4 linters: [errcheck govet ineffassign typecheck] 
INFO [loader] Go packages loading at mode 575 (imports|name|types_sizes|deps|files|compiled_files|exports_file) took 12.13721ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 165.104µs 
INFO [linters_context/goanalysis] analyzers took 0s with no stages 
INFO [runner] processing took 33.805µs with stages: max_same_issues: 1.956µs, path_prettifier: 1.955µs, cgo: 1.886µs, skip_dirs: 1.886µs, uniq_by_line: 1.886µs, nolint: 1.886µs, autogenerated_exclude: 1.886µs, fixer: 1.816µs, max_per_file_from_linter: 1.467µs, sort_results: 1.467µs, severity-rules: 1.467µs, exclude: 1.467µs, identifier_marker: 1.467µs, path_prefixer: 1.467µs, filename_unadjuster: 1.466µs, source_code: 1.397µs, diff: 1.397µs, exclude-rules: 1.397µs, max_from_linter: 1.397µs, path_shortener: 1.396µs, skip_files: 1.396µs 
INFO [runner] linters took 536.516µs with stages: goanalysis_metalinter: 395.718µs 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 2 samples, avg is 31.6MB, max is 31.6MB 
INFO Execution took 18.626256ms 

Code example or link to a public repository

See description

@matthewhughes934 matthewhughes934 added the bug Something isn't working label Mar 29, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 29, 2023

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

@matthewhughes934
Copy link
Contributor Author

I had an attempt at changing the behaviour here: master...matthewhughes934:golangci-lint:fix-silent-linter-disable-through-alias

@ldez ldez added the area: config Related to .golangci.yml and/or cli options label Mar 29, 2023
@ldez
Copy link
Member

ldez commented Mar 29, 2023

Hello,

It is a side effect of a "feature" because megacheck is a kind of set.
From what I can read in the code, the goal was to provide a compatibility layer when megacheck was split into 3 linters, i.e., enable/disable the 3 linters simultaneously.

$ golangci-lint run -v --disable-all -Emegacheck
... 
INFO [lintersdb] Active 3 linters: [gosimple staticcheck unused]
...
$ golangci-lint run -v -Dmegacheck
...
INFO [lintersdb] Active 4 linters: [errcheck govet ineffassign typecheck]
...
$ golangci-lint run -v            
...
INFO [lintersdb] Active 7 linters: [errcheck gosimple govet ineffassign staticcheck typecheck unused]
...

I think this "feature" must be removed in the future (a major version).

@ldez
Copy link
Member

ldez commented Mar 29, 2023

To be precise I think I was expected: as megacheck is a kind of set, the possibility to enable/disable one of the linter is expected.

the following test is explaining the expected behavior:

func TestGetEnabledLintersSet(t *testing.T) {

@ldez ldez added the won't fix This will not be worked on label Mar 29, 2023
@ldez
Copy link
Member

ldez commented Mar 29, 2023

For now, this issue cannot be fixed.

@ldez ldez added this to the v2.0.0 milestone Mar 29, 2023
@matthewhughes934
Copy link
Contributor Author

Thanks for the response, and thanks for the extra info 🙂

@ldez
Copy link
Member

ldez commented Jun 10, 2024

now alternative names are deprecated, so we can consider this issue as fixed.

@ldez ldez closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: config Related to .golangci.yml and/or cli options bug Something isn't working won't fix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants