Merge pull request #38 from golangci/feature/dont-pass-not-compiling-packages-to-program-linters
#33: don't pass not compiling packages to linters accepting loader.Pr…
This commit is contained in:
commit
541cd1de48
@ -190,6 +190,30 @@ func discoverGoRoot() (string, error) {
|
|||||||
return strings.TrimSpace(string(output)), nil
|
return strings.TrimSpace(string(output)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// separateNotCompilingPackages moves not compiling packages into separate slices:
|
||||||
|
// a lot of linters crash on such packages. Leave them only for those linters
|
||||||
|
// which can work with them.
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prog.Created = compilingCreated
|
||||||
|
|
||||||
|
for k, info := range prog.Imported {
|
||||||
|
if len(info.Errors) != 0 {
|
||||||
|
lintCtx.NotCompilingPackages = append(lintCtx.NotCompilingPackages, info)
|
||||||
|
delete(prog.Imported, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config) (*golinters.Context, error) {
|
func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config) (*golinters.Context, error) {
|
||||||
// Set GOROOT to have working cross-compilation: cross-compiled binaries
|
// Set GOROOT to have working cross-compilation: cross-compiled binaries
|
||||||
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
|
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
|
||||||
@ -228,14 +252,18 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config)
|
|||||||
astCache = astcache.LoadFromFiles(paths.Files)
|
astCache = astcache.LoadFromFiles(paths.Files)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &golinters.Context{
|
ret := &golinters.Context{
|
||||||
Paths: paths,
|
Paths: paths,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Program: prog,
|
Program: prog,
|
||||||
SSAProgram: ssaProg,
|
SSAProgram: ssaProg,
|
||||||
LoaderConfig: loaderConfig,
|
LoaderConfig: loaderConfig,
|
||||||
ASTCache: astCache,
|
ASTCache: astCache,
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
separateNotCompilingPackages(ret)
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan result.Issue, error) {
|
func (e *Executor) runAnalysis(ctx context.Context, args []string) (<-chan result.Issue, error) {
|
||||||
|
@ -9,12 +9,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Paths *fsutils.ProjectPaths
|
Paths *fsutils.ProjectPaths
|
||||||
Cfg *config.Config
|
Cfg *config.Config
|
||||||
Program *loader.Program
|
Program *loader.Program
|
||||||
SSAProgram *ssa.Program
|
SSAProgram *ssa.Program
|
||||||
LoaderConfig *loader.Config
|
LoaderConfig *loader.Config
|
||||||
ASTCache *astcache.Cache
|
ASTCache *astcache.Cache
|
||||||
|
NotCompilingPackages []*loader.PackageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Settings() *config.LintersSettings {
|
func (c *Context) Settings() *config.LintersSettings {
|
||||||
|
@ -63,7 +63,7 @@ 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) {
|
||||||
var res []result.Issue
|
var res []result.Issue
|
||||||
for _, pkg := range lintCtx.Program.InitialPackages() {
|
for _, pkg := range lintCtx.NotCompilingPackages {
|
||||||
for _, err := range pkg.Errors {
|
for _, err := range pkg.Errors {
|
||||||
i := lint.parseError(err)
|
i := lint.parseError(err)
|
||||||
if i != nil {
|
if i != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user