Speed up linting: use deduplicated packages (#667)
Use deduplicated packages for all linters except megacheck. See https://github.com/golangci/golangci-lint/pull/585 for details.
This commit is contained in:
parent
e1a7422dd5
commit
375a5a8cae
pkg
@ -177,7 +177,9 @@ func (m MegacheckMetalinter) isValidChild(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m megacheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
func (m megacheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
||||||
issues, err := m.runMegacheck(lintCtx.Packages, lintCtx.Settings().Unused.CheckExported)
|
// Use OriginalPackages not Packages because `unused` doesn't work properly
|
||||||
|
// when we deduplicate normal and test packages.
|
||||||
|
issues, err := m.runMegacheck(lintCtx.OriginalPackages, lintCtx.Settings().Unused.CheckExported)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to run megacheck")
|
return nil, errors.Wrap(err, "failed to run megacheck")
|
||||||
}
|
}
|
||||||
@ -231,7 +233,7 @@ func (m megacheck) runMegacheck(workingPkgs []*packages.Package, checkExportedUn
|
|||||||
opts := &lintutil.Options{
|
opts := &lintutil.Options{
|
||||||
// TODO: get current go version, but now it doesn't matter,
|
// TODO: get current go version, but now it doesn't matter,
|
||||||
// may be needed after next updates of megacheck
|
// may be needed after next updates of megacheck
|
||||||
GoVersion: 11,
|
GoVersion: 12,
|
||||||
|
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
// TODO: support Ignores option
|
// TODO: support Ignores option
|
||||||
|
@ -13,7 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
|
// Packages are deduplicated (test and normal packages) packages
|
||||||
Packages []*packages.Package
|
Packages []*packages.Package
|
||||||
|
|
||||||
|
// OriginalPackages aren't deduplicated: they contain both normal and test
|
||||||
|
// version for each of packages
|
||||||
|
OriginalPackages []*packages.Package
|
||||||
|
|
||||||
NotCompilingPackages []*packages.Package
|
NotCompilingPackages []*packages.Package
|
||||||
|
|
||||||
LoaderConfig *loader.Config // deprecated, don't use for new linters
|
LoaderConfig *loader.Config // deprecated, don't use for new linters
|
||||||
|
@ -381,7 +381,12 @@ func (cl ContextLoader) Load(ctx context.Context, linters []*linter.Config) (*li
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret := &linter.Context{
|
ret := &linter.Context{
|
||||||
Packages: pkgs,
|
Packages: deduplicatedPkgs,
|
||||||
|
|
||||||
|
// At least `unused` linters works properly only on original (not deduplicated) packages,
|
||||||
|
// see https://github.com/golangci/golangci-lint/pull/585.
|
||||||
|
OriginalPackages: pkgs,
|
||||||
|
|
||||||
Program: prog,
|
Program: prog,
|
||||||
SSAProgram: ssaProg,
|
SSAProgram: ssaProg,
|
||||||
LoaderConfig: &loader.Config{
|
LoaderConfig: &loader.Config{
|
||||||
@ -402,6 +407,7 @@ func (cl ContextLoader) Load(ctx context.Context, linters []*linter.Config) (*li
|
|||||||
// separateNotCompilingPackages moves not compiling packages into separate slice:
|
// separateNotCompilingPackages moves not compiling packages into separate slice:
|
||||||
// a lot of linters crash on such packages
|
// a lot of linters crash on such packages
|
||||||
func separateNotCompilingPackages(lintCtx *linter.Context) {
|
func separateNotCompilingPackages(lintCtx *linter.Context) {
|
||||||
|
// Separate deduplicated packages
|
||||||
goodPkgs := make([]*packages.Package, 0, len(lintCtx.Packages))
|
goodPkgs := make([]*packages.Package, 0, len(lintCtx.Packages))
|
||||||
for _, pkg := range lintCtx.Packages {
|
for _, pkg := range lintCtx.Packages {
|
||||||
if pkg.IllTyped {
|
if pkg.IllTyped {
|
||||||
@ -415,4 +421,13 @@ func separateNotCompilingPackages(lintCtx *linter.Context) {
|
|||||||
if len(lintCtx.NotCompilingPackages) != 0 {
|
if len(lintCtx.NotCompilingPackages) != 0 {
|
||||||
lintCtx.Log.Infof("Packages that do not compile: %+v", lintCtx.NotCompilingPackages)
|
lintCtx.Log.Infof("Packages that do not compile: %+v", lintCtx.NotCompilingPackages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Separate original (not deduplicated) packages
|
||||||
|
goodOriginalPkgs := make([]*packages.Package, 0, len(lintCtx.OriginalPackages))
|
||||||
|
for _, pkg := range lintCtx.OriginalPackages {
|
||||||
|
if !pkg.IllTyped {
|
||||||
|
goodOriginalPkgs = append(goodOriginalPkgs, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lintCtx.OriginalPackages = goodOriginalPkgs
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user