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

--output-format no longer reporting typecheck errors #1002

Closed
vektah opened this issue Mar 26, 2020 · 3 comments · Fixed by #1861
Closed

--output-format no longer reporting typecheck errors #1002

vektah opened this issue Mar 26, 2020 · 3 comments · Fixed by #1861
Labels
bug Something isn't working false negative An error is not reported when one exists

Comments

@vektah
Copy link

vektah commented Mar 26, 2020

package setup
mkdir foo
cd foo
go mod init foo
echo "syntax error" > main.go

In golangci-lint versions 1.21 and prior running golangci-lint run --output-format json would give json output with any syntax violations.

golangci-lint-1.21.0 run --out-format json    
WARN [runner] Can't run linter unused: buildssa: analysis skipped: errors in package: [-: main.go:1:1: expected 'package', found syntax] 
ERRO [runner/goanalysis_metalinter] typechecking error: main.go:1:1: expected 'package', found syntax 
WARN [runner] Can't run linter goanalysis_metalinter: assign: failed prerequisites: inspect@foo 
{"Issues":null,"Report":{"Warnings":[{"Tag":"runner","Text":"Can't run linter unused: buildssa: analysis skipped: errors in package: [-: main.go:1:1: expected 'package', found syntax]"},{"Tag":"runner","Text":"Can't run linter goanalysis_metalinter: assign: failed prerequisites: inspect@foo"}],"Linters":[{"Name":"govet","EnabledByDefault":true},{"Name":"bodyclose"},{"Name":"errcheck","EnabledByDefault":true},{"Name":"golint"},{"Name":"staticcheck","EnabledByDefault":true},{"Name":"unused","Enabled":true,"EnabledByDefault":true},{"Name":"gosimple","EnabledByDefault":true},{"Name":"stylecheck"},{"Name":"gosec"},{"Name":"structcheck","EnabledByDefault":true},{"Name":"varcheck","EnabledByDefault":true},{"Name":"interfacer"},{"Name":"unconvert"},{"Name":"ineffassign","EnabledByDefault":true},{"Name":"dupl"},{"Name":"goconst"},{"Name":"deadcode","EnabledByDefault":true},{"Name":"gocyclo"},{"Name":"gocognit"},{"Name":"typecheck","EnabledByDefault":true},{"Name":"gofmt"},{"Name":"goimports"},{"Name":"maligned"},{"Name":"depguard"},{"Name":"misspell"},{"Name":"lll"},{"Name":"unparam"},{"Name":"dogsled"},{"Name":"nakedret"},{"Name":"prealloc"},{"Name":"scopelint"},{"Name":"gocritic"},{"Name":"gochecknoinits"},{"Name":"gochecknoglobals"},{"Name":"godox"},{"Name":"funlen"},{"Name":"whitespace"},{"Name":"wsl"}],"Error":"typechecking error: main.go:1:1: expected 'package', found syntax"}}

In v1.22.0, specifically #890, the first linter to error (goanalysis_metalinter) now prevents typecheck from running so we get no json output at all.

golangci-lint-1.22.0 run --out-format json              
WARN [runner] Can't run linter unused: buildir: analysis skipped: errors in package: [-: main.go:1:1: expected 'package', found syntax] 
ERRO [runner/goanalysis_metalinter] typechecking error: main.go:1:1: expected 'package', found syntax 
WARN [runner] Can't run linter goanalysis_metalinter: assign: failed prerequisites: [inspect@foo: analysis skipped: errors in package: [-: main.go:1:1: expected 'package', found syntax]] 
ERRO Running error: assign: failed prerequisites: [inspect@foo: analysis skipped: errors in package: [-: main.go:1:1: expected 'package', found syntax]] 
Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.24.0 built from 6fd4383 on 2020-03-15T11:38:02Z
Config file
$ cat .golangci.yml
cat: .golangci.yml: No such file or directory

not using a config file
Go environment
$ go version && go env
go version go1.14.1 linux/amd64
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vektah/.cache/go-build"
GOENV="/home/vektah/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vektah/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/vektah/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/vektah/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/vektah/projects/redacted/redacted/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-build271118658=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/vektah/projects/redacted/redacted/home/vektah/projects/redacted/home/vektah/projects /home/vektah /home /] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Go packages loading at mode 575 (deps|exports_file|imports|compiled_files|files|name|types_sizes) took 99.258594ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 4.927623ms 
ERRO [runner/goanalysis_metalinter] typechecking error: generated.go:10:8: expected ';', found ',' 
INFO [runner/goanalysis_metalinter/goanalysis] analyzers took 1.41716ms with top 10 stages: fact_deprecated: 128.515µs, buildir: 64.929µs, SA4019: 30.222µs, S1018: 26.9µs, S1033: 26.145µs, S1017: 23.934µs, S1024: 21.841µs, SA1018: 17.777µs, typecheck: 16.943µs, SA6005: 16.126µs 
WARN [runner] Can't run linter goanalysis_metalinter: SA1011: failed prerequisites: [(buildir@github.com/redacted/redacted, tokenfileanalyzer@github.com/redacted/redacted): analysis skipped: errors in package: [-: generated.go:10:8: expected ';', found ',']] 
INFO [runner/unused/goanalysis] analyzers took 69.697µs with top 10 stages: buildir: 58.101µs, U1000: 11.596µs 
WARN [runner] Can't run linter unused: buildir: analysis skipped: errors in package: [-: generated.go:10:8: expected ';', found ','] 
INFO [runner] processing took 1.854µs with stages: max_same_issues: 302ns, skip_dirs: 202ns, nolint: 174ns, max_from_linter: 142ns, filename_unadjuster: 133ns, cgo: 129ns, source_code: 104ns, autogenerated_exclude: 94ns, path_prettifier: 93ns, diff: 93ns, identifier_marker: 92ns, skip_files: 90ns, exclude: 46ns, max_per_file_from_linter: 44ns, path_shortener: 40ns, exclude-rules: 38ns, uniq_by_line: 38ns 
INFO [runner] linters took 34.186565ms with stages: goanalysis_metalinter: 33.767629ms, unused: 384.53µs 
ERRO Running error: buildir: analysis skipped: errors in package: [-: generated.go:10:8: expected ';', found ','] 
INFO Memory: 3 samples, avg is 70.2MB, max is 70.6MB 
INFO Execution took 142.934549ms    
@fabrepe
Copy link

fabrepe commented Apr 7, 2020

I can confirm this issue in version 1.24

Maybe just modifying

issues, err := runner.Run(ctx, enabledLinters, lintCtx)

from

	issues, err := runner.Run(ctx, enabledLinters, lintCtx)
	if err != nil {
		return nil, err
	}

	fixer := processors.NewFixer(e.cfg, e.log, e.fileCache)
	return fixer.Process(issues), nil

to

	issues, err := runner.Run(ctx, enabledLinters, lintCtx)

	fixer := processors.NewFixer(e.cfg, e.log, e.fileCache)
	return fixer.Process(issues), err

@fabrepe
Copy link

fabrepe commented Apr 28, 2020

Will a push request have more success ?

@ernado ernado added bug Something isn't working false negative An error is not reported when one exists labels Apr 28, 2020
@ernado
Copy link
Member

ernado commented Apr 28, 2020

We need a proper fix that will both return non-zero code and report typecheck errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false negative An error is not reported when one exists
Projects
None yet
3 participants