Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/lint/linter/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package linter

import (
"go/ast"

"golang.org/x/tools/go/packages"

"github.com/golangci/golangci-lint/internal/pkgcache"
Expand Down Expand Up @@ -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{}
}
4 changes: 4 additions & 0 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
specificLintCtx := *lintCtx
specificLintCtx.Log = r.Log.Child(lc.Name())

// Packages in lintCtx might be dirty due to the last analysis,
// which affects to the next analysis.
// To avoid this issue, we clear type information from the packages.
specificLintCtx.ClearTypesInPackages()
issues, err := lc.Linter.Run(ctx, &specificLintCtx)
if err != nil {
return nil, err
Expand Down