Clear part of package fields before analysis

This commit is contained in:
Soichiro Kashima 2020-01-28 16:04:43 +09:00
commit 796b4fffbe
2 changed files with 21 additions and 19 deletions

View file

@ -1,6 +1,8 @@
package linter
import (
"go/ast"
"golang.org/x/tools/go/packages"
"github.com/golangci/golangci-lint/internal/pkgcache"
@ -30,3 +32,18 @@ type Context struct {
func (c *Context) Settings() *config.LintersSettings {
return &c.Cfg.LintersSettings
}
func (c *Context) ClearTypesInPackages() {
for _, p := range c.Packages {
clearTypes(p)
}
for _, p := range c.OriginalPackages {
clearTypes(p)
}
}
func clearTypes(p *packages.Package) {
p.Types = nil
p.TypesInfo = nil
p.Syntax = []*ast.File{}
}