diff --git a/Makefile b/Makefile index f2241e88..d89316bc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ test: go install ./cmd/... - golangci-lint run + golangci-lint run -v + golangci-lint run --fast --no-config -v + golangci-lint run --fast --no-config -v + golangci-lint run --no-config -v + golangci-lint run --fast --no-config -v ./pkg/testdata/with_issues/typecheck.go go test -v -race ./... diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 7e733de8..9cec4f2f 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -196,20 +196,24 @@ func discoverGoRoot() (string, error) { func separateNotCompilingPackages(lintCtx *golinters.Context) { prog := lintCtx.Program - compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created)) - for _, info := range prog.Created { - if len(info.Errors) != 0 { - lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) - } else { - compilingCreated = append(compilingCreated, info) + if prog.Created != nil { + compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created)) + for _, info := range prog.Created { + if len(info.Errors) != 0 { + lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) + } else { + compilingCreated = append(compilingCreated, info) + } } + prog.Created = compilingCreated } - prog.Created = compilingCreated - for k, info := range prog.Imported { - if len(info.Errors) != 0 { - lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) - delete(prog.Imported, k) + if prog.Imported != nil { + for k, info := range prog.Imported { + if len(info.Errors) != 0 { + lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) + delete(prog.Imported, k) + } } } } @@ -261,7 +265,9 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config) ASTCache: astCache, } - separateNotCompilingPackages(ret) + if prog != nil { + separateNotCompilingPackages(ret) + } return ret, nil } diff --git a/pkg/golinters/typecheck.go b/pkg/golinters/typecheck.go index b16f1050..dcea36cd 100644 --- a/pkg/golinters/typecheck.go +++ b/pkg/golinters/typecheck.go @@ -62,6 +62,10 @@ func (lint TypeCheck) parseError(err error) *result.Issue { } func (lint TypeCheck) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) { + if lintCtx.NotCompilingPackages == nil { + return nil, nil + } + var res []result.Issue for _, pkg := range lintCtx.NotCompilingPackages { for _, err := range pkg.Errors {