
1. Allow govet to work in 2 modes: fast and slow. Default is slow. In fast mode golangci-lint runs `go install -i` and `go test -i` for analyzed packages. But it's fast only when: - go >= 1.10 - it's repeated run or $GOPATH/pkg or `go env GOCACHE` is cached between CI builds In slow mode we load program from source code like for another linters and do it only once for all linters. 3. Patch govet code to warn about any troubles with the type information. Default behaviour of govet was to hide such warnings. Fail analysis if there are any troubles with type loading: it will prevent false-positives and false-negatives from govet. 4. Describe almost all options in .golangci.example.yml and include it into README. Describe when to use slow or fast mode of govet. 5. Speed up govet: reuse AST parsing: it's already parsed once by golangci-lint. For "slow" runs (when we run at least one slow linter) speedup by not loading type information second time. 6. Improve logging, debug logging 7. Fix crash in logging of AST cache warnings (#118)
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package lint
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/golinters"
|
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/config"
|
|
"github.com/golangci/golangci-lint/pkg/lint/astcache"
|
|
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
|
"github.com/golangci/golangci-lint/pkg/packages"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestASTCacheLoading(t *testing.T) {
|
|
ctx := context.Background()
|
|
linters := []linter.Config{
|
|
linter.NewConfig(golinters.Errcheck{}).WithFullImport(),
|
|
}
|
|
|
|
inputPaths := []string{"./...", "./", "./load.go", "load.go"}
|
|
log := logutils.NewStderrLog("")
|
|
for _, inputPath := range inputPaths {
|
|
r, err := packages.NewResolver(nil, nil, log)
|
|
assert.NoError(t, err)
|
|
|
|
pkgProg, err := r.Resolve(inputPath)
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, pkgProg.Files(true))
|
|
|
|
cfg := &config.Config{
|
|
Run: config.Run{
|
|
AnalyzeTests: true,
|
|
},
|
|
}
|
|
prog, _, err := loadWholeAppIfNeeded(ctx, linters, cfg, pkgProg, logutils.NewStderrLog(""))
|
|
assert.NoError(t, err)
|
|
|
|
astCacheFromProg, err := astcache.LoadFromProgram(prog, log)
|
|
assert.NoError(t, err)
|
|
|
|
astCacheFromFiles, err := astcache.LoadFromFiles(pkgProg.Files(true), log)
|
|
assert.NoError(t, err)
|
|
|
|
filesFromProg := astCacheFromProg.GetAllValidFiles()
|
|
filesFromFiles := astCacheFromFiles.GetAllValidFiles()
|
|
if len(filesFromProg) != len(filesFromFiles) {
|
|
t.Logf("files: %s", pkgProg.Files(true))
|
|
t.Logf("from prog:")
|
|
for _, f := range filesFromProg {
|
|
t.Logf("%+v", *f)
|
|
}
|
|
t.Logf("from files:")
|
|
for _, f := range filesFromFiles {
|
|
t.Logf("%+v", *f)
|
|
}
|
|
t.Fatalf("lengths differ")
|
|
}
|
|
|
|
if len(filesFromProg) != len(pkgProg.Files(true)) {
|
|
t.Fatalf("filesFromProg differ from path.Files")
|
|
}
|
|
}
|
|
}
|