Description
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
The depguard
golangci-lint integration unnecessarily type checks.
When run standalone depguard
does not experience this issue.
When run via golangci-lint this issue is experienced, resulting in typecheck
lints (catching the compilation errors).
Example to reproduce: edit test/testdata/depguard.go
func SpewDebugInfo() {
+ var a A
+ log.Println(A)
log.Println(gzip.BestCompression)
}
run go run ./cmd/golangci-lint/ run --no-config --disable-all --enable=depguard ./test/testdata/depguard.go
test/testdata/depguard.go:11:8: undeclared name: `A` (typecheck)
var a A
^
test/testdata/depguard.go:12:14: undeclared name: `A` (typecheck)
log.Println(A)
^
exit status 1
Separately you can run depguard
directly - to confirm that no errors are produced by depguard
itself - by running go run ./cmd/depguard -c ".depguard.json" <path_to>/golangci-lint/test/testdata/depguard.go
where .depguard.json
is some minimal depguard configuration.
This can be resolved by using LoadModeSyntax
and using a modified MakeFakeLoaderProgram
that doesn't attempt to access *pass.TypesInfo
.
(revive
, for example, doesn't experience this issue)
Version of golangci-lint
$ golangci-lint --version
golangci-lint has version (devel) built from (unknown, mod sum: "") on (unknown)
Configuration file
$ cat .golangci.yml
Go environment
$ go version && go env
go version go1.17.8 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/peregrine/.cache/go-build"
GOENV="/home/peregrine/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/peregrine/core3/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/peregrine/core3:/home/peregrine/core3/src/plz-out/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/tm/tools/go/1.17.8/usr/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/tm/tools/go/1.17.8/usr/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.8"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/peregrine/perrydunn/golangci-lint/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1358118786=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/peregrine/perrydunn/golangci-lint /home/peregrine/perrydunn /home/peregrine /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 34 linters: [bodyclose deadcode depguard dogsled dupl errcheck exportloopref funlen gochecknoinits goconst gocritic gocyclo gofmt goimports gomnd goprintffuncname gosec gosimple govet ineffassign lll misspell nakedret noctx nolintlint staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace]
INFO [loader] Go packages loading at mode 575 (imports|name|compiled_files|exports_file|types_sizes|deps|files) took 627.171864ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 9.054457ms
INFO [linters context/goanalysis] analyzers took 1m38.383934073s with top 10 stages: gocritic: 24.930130532s, buildir: 20.842760231s, printf: 6.489465218s, ctrlflow: 6.363960598s, nilness: 6.275353763s, fact_deprecated: 6.16640289s, typedness: 5.605870208s, fact_purity: 5.514132124s, SA5012: 4.762908426s, buildssa: 1.180452211s
INFO [runner/skip dirs] Skipped 3 issues from dir test/testdata_etc/abspath by pattern test/testdata_etc
INFO [runner/skip dirs] Skipped 18 issues from dir internal/renameio by pattern internal/renameio
INFO [runner/skip dirs] Skipped 82 issues from dir internal/cache by pattern internal/cache
INFO [runner/skip dirs] Skipped 3 issues from dir internal/robustio by pattern internal/robustio
INFO [runner/skip dirs] Skipped 1 issues from dir test/testdata_etc/unused_exported/lib by pattern test/testdata_etc
INFO [runner] Issues before processing: 478, after processing: 0
INFO [runner] Processors filtering stat (out/in): filename_unadjuster: 478/478, skip_files: 478/478, autogenerated_exclude: 371/371, cgo: 478/478, path_prettifier: 478/478, exclude: 371/371, nolint: 0/143, skip_dirs: 371/478, identifier_marker: 371/371, exclude-rules: 143/371
INFO [runner] processing took 24.654164ms with stages: nolint: 9.015158ms, exclude-rules: 7.616803ms, identifier_marker: 3.949303ms, path_prettifier: 1.958529ms, autogenerated_exclude: 1.806398ms, skip_dirs: 263.408µs, cgo: 25.493µs, filename_unadjuster: 15.365µs, max_same_issues: 872ns, diff: 580ns, uniq_by_line: 450ns, source_code: 315ns, skip_files: 285ns, max_from_linter: 228ns, severity-rules: 191ns, max_per_file_from_linter: 180ns, path_shortener: 177ns, exclude: 174ns, sort_results: 170ns, path_prefixer: 85ns
INFO [runner] linters took 8.893161966s with stages: goanalysis_metalinter: 8.868457234s
INFO File cache stats: 243 entries of total size 637.9KiB
INFO Memory: 97 samples, avg is 820.0MB, max is 1623.4MB
INFO Execution took 9.533104968s
Code example or link to a public repository
//args: -Edepguard
//config_path: testdata/configs/depguard.yml
package testdata
import (
"compress/gzip" // ERROR "`compress/gzip` is in the blacklist"
"log" // ERROR "`log` is in the blacklist: don't use log"
)
func SpewDebugInfo() {
var a A
log.Println(A)
log.Println(gzip.BestCompression)
}