
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)
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package packages
|
|
|
|
import (
|
|
"fmt"
|
|
"go/build"
|
|
)
|
|
|
|
type Program struct {
|
|
packages []Package
|
|
|
|
bctx build.Context
|
|
}
|
|
|
|
func (p *Program) String() string {
|
|
files := p.Files(true)
|
|
if len(files) == 1 {
|
|
return files[0]
|
|
}
|
|
|
|
return fmt.Sprintf("%s", p.Dirs())
|
|
}
|
|
|
|
func (p *Program) BuildContext() *build.Context {
|
|
return &p.bctx
|
|
}
|
|
|
|
func (p Program) Packages() []Package {
|
|
return p.packages
|
|
}
|
|
|
|
func (p *Program) addPackage(pkg *Package) {
|
|
packagesToAdd := []Package{*pkg}
|
|
if len(pkg.bp.XTestGoFiles) != 0 {
|
|
// create separate package because xtest files have different package name
|
|
xbp := build.Package{
|
|
Dir: pkg.bp.Dir,
|
|
ImportPath: pkg.bp.ImportPath + "_test",
|
|
XTestGoFiles: pkg.bp.XTestGoFiles,
|
|
XTestImportPos: pkg.bp.XTestImportPos,
|
|
XTestImports: pkg.bp.XTestImports,
|
|
}
|
|
packagesToAdd = append(packagesToAdd, Package{
|
|
bp: &xbp,
|
|
})
|
|
pkg.bp.XTestGoFiles = nil
|
|
pkg.bp.XTestImportPos = nil
|
|
pkg.bp.XTestImports = nil
|
|
}
|
|
|
|
p.packages = append(p.packages, packagesToAdd...)
|
|
}
|
|
|
|
func (p *Program) Files(includeTest bool) []string {
|
|
var ret []string
|
|
for _, pkg := range p.packages {
|
|
ret = append(ret, pkg.Files(includeTest)...)
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
func (p *Program) Dirs() []string {
|
|
var ret []string
|
|
for _, pkg := range p.packages {
|
|
if !pkg.isFake {
|
|
ret = append(ret, pkg.Dir())
|
|
}
|
|
}
|
|
|
|
return ret
|
|
}
|