#40: fix panic in fast mode

This commit is contained in:
golangci 2018-05-30 09:15:09 +03:00
parent 0eb6aa7c59
commit 5646c61c73
3 changed files with 27 additions and 13 deletions

View File

@ -1,4 +1,8 @@
test: test:
go install ./cmd/... 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 ./... go test -v -race ./...

View File

@ -196,20 +196,24 @@ func discoverGoRoot() (string, error) {
func separateNotCompilingPackages(lintCtx *golinters.Context) { func separateNotCompilingPackages(lintCtx *golinters.Context) {
prog := lintCtx.Program prog := lintCtx.Program
compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created)) if prog.Created != nil {
for _, info := range prog.Created { compilingCreated := make([]*loader.PackageInfo, 0, len(prog.Created))
if len(info.Errors) != 0 { for _, info := range prog.Created {
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) if len(info.Errors) != 0 {
} else { lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
compilingCreated = append(compilingCreated, info) } else {
compilingCreated = append(compilingCreated, info)
}
} }
prog.Created = compilingCreated
} }
prog.Created = compilingCreated
for k, info := range prog.Imported { if prog.Imported != nil {
if len(info.Errors) != 0 { for k, info := range prog.Imported {
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info) if len(info.Errors) != 0 {
delete(prog.Imported, k) 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, ASTCache: astCache,
} }
separateNotCompilingPackages(ret) if prog != nil {
separateNotCompilingPackages(ret)
}
return ret, nil return ret, nil
} }

View File

@ -62,6 +62,10 @@ func (lint TypeCheck) parseError(err error) *result.Issue {
} }
func (lint TypeCheck) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) { func (lint TypeCheck) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
if lintCtx.NotCompilingPackages == nil {
return nil, nil
}
var res []result.Issue var res []result.Issue
for _, pkg := range lintCtx.NotCompilingPackages { for _, pkg := range lintCtx.NotCompilingPackages {
for _, err := range pkg.Errors { for _, err := range pkg.Errors {