diff --git a/.gitignore b/.gitignore index 1d85c074..e2ace38b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /dist/ /.idea/ /test/path +/golangci-lint diff --git a/Makefile b/Makefile index b753315b..5ff27222 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ test: - go install ./cmd/... - GL_TEST_RUN=1 golangci-lint run -v - GL_TEST_RUN=1 golangci-lint run --fast --no-config -v - GL_TEST_RUN=1 golangci-lint run --no-config -v + go build -o golangci-lint ./cmd/golangci-lint + GL_TEST_RUN=1 ./golangci-lint run -v + GL_TEST_RUN=1 ./golangci-lint run --fast --no-config -v + GL_TEST_RUN=1 ./golangci-lint run --no-config -v GL_TEST_RUN=1 go test -v ./... +test_race: + go build -race -o golangci-lint ./cmd/golangci-lint + GL_TEST_RUN=1 ./golangci-lint run -v --deadline=5m + test_linters: GL_TEST_RUN=1 go test -v ./test -count 1 -run TestSourcesFromTestdataWithIssuesDir/$T diff --git a/pkg/golinters/megacheck.go b/pkg/golinters/megacheck.go index 40b53419..7b9d3ab4 100644 --- a/pkg/golinters/megacheck.go +++ b/pkg/golinters/megacheck.go @@ -106,7 +106,7 @@ func (m Megacheck) Run(ctx context.Context, lintCtx *linter.Context) ([]result.I return nil, nil } - issues := runMegacheck(lintCtx.Program, lintCtx.SSAProgram, lintCtx.LoaderConfig, + issues := runMegacheck(lintCtx.Program, lintCtx.MegacheckSSAProgram, lintCtx.LoaderConfig, m.StaticcheckEnabled, m.GosimpleEnabled, m.UnusedEnabled, lintCtx.Settings().Unused.CheckExported) if len(issues) == 0 { return nil, nil diff --git a/pkg/lint/linter/context.go b/pkg/lint/linter/context.go index 443f7d60..02d4acef 100644 --- a/pkg/lint/linter/context.go +++ b/pkg/lint/linter/context.go @@ -17,7 +17,8 @@ type Context struct { LoaderConfig *loader.Config // deprecated, don't use for new linters Program *loader.Program // deprecated, use Packages for new linters - SSAProgram *ssa.Program + SSAProgram *ssa.Program // for unparam and interfacer: they don't change it + MegacheckSSAProgram *ssa.Program // for megacheck: it modifies ssa program Cfg *config.Config ASTCache *astcache.Cache diff --git a/pkg/lint/load.go b/pkg/lint/load.go index 43710224..d098d0ef 100644 --- a/pkg/lint/load.go +++ b/pkg/lint/load.go @@ -126,13 +126,16 @@ func (cl ContextLoader) makeFakeLoaderProgram(pkgs []*packages.Package) *loader. } } -func (cl ContextLoader) buildSSAProgram(pkgs []*packages.Package) *ssa.Program { +func (cl ContextLoader) buildSSAProgram(pkgs []*packages.Package, name string) *ssa.Program { startedAt := time.Now() + var pkgsBuiltDuration time.Duration defer func() { - cl.log.Infof("SSA repr building took %s", time.Since(startedAt)) + cl.log.Infof("SSA %srepr building timing: packages building %s, total %s", + name, pkgsBuiltDuration, time.Since(startedAt)) }() ssaProg, _ := ssautil.Packages(pkgs, ssa.GlobalDebug) + pkgsBuiltDuration = time.Since(startedAt) ssaProg.Build() return ssaProg } @@ -300,24 +303,10 @@ func (cl ContextLoader) Load(ctx context.Context, linters []linter.Config) (*lin prog = cl.makeFakeLoaderProgram(pkgs) } - var ssaProg *ssa.Program + var ssaProg, megacheckSSAProg *ssa.Program if loadMode == packages.LoadAllSyntax { - ssaProg = cl.buildSSAProgram(pkgs) - for _, pkginfo := range prog.InitialPackages() { - if pkginfo == nil { - cl.log.Infof("Pkginfo is nil") - continue - } - if pkginfo.Pkg == nil { - cl.log.Infof("Pkg %#v: types package is nil", *pkginfo) - continue - } - ssaPkg := ssaProg.Package(pkginfo.Pkg) - if ssaPkg == nil { - cl.log.Infof("Pkg %#v: ssaPkg is nil: %#v", *pkginfo, *pkginfo.Pkg) - continue - } - } + ssaProg = cl.buildSSAProgram(pkgs, "") + megacheckSSAProg = cl.buildSSAProgram(pkgs, "for megacheck ") } astLog := cl.log.Child("astcache") @@ -327,9 +316,10 @@ func (cl ContextLoader) Load(ctx context.Context, linters []linter.Config) (*lin } ret := &linter.Context{ - Packages: pkgs, - Program: prog, - SSAProgram: ssaProg, + Packages: pkgs, + Program: prog, + SSAProgram: ssaProg, + MegacheckSSAProgram: megacheckSSAProg, LoaderConfig: &loader.Config{ Cwd: "", // used by depguard and fallbacked to os.Getcwd Build: nil, // used by depguard and megacheck and fallbacked to build.Default