
Also do following improvements: - show proper sublinter name for megacheck sublinters - refactor and make more simple and robust megacheck merging/optimizing - improve handling of unknown linter names in //nolint directives - minimize diff of our megacheck version from the upstream, https://github.com/golang/go/issues/29612 blocks usage of the upstream version - support the new `stylecheck` linter - improve tests coverage for megacheck and nolint related cases - update and use upstream versions of unparam and interfacer instead of forked ones - don't use golangci/tools repo anymore - fix newly found issues after updating linters Also should be noted that megacheck works much faster and consumes less memory in the newest release, therefore golangci-lint works noticeably faster and consumes less memory for large repos. Relates: #314
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
|
// See LICENSE for licensing information
|
|
|
|
package check
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/types"
|
|
)
|
|
|
|
type pkgTypes struct {
|
|
ifaces map[string]string
|
|
funcSigns map[string]bool
|
|
}
|
|
|
|
func (p *pkgTypes) getTypes(pkg *types.Package) {
|
|
p.ifaces = make(map[string]string)
|
|
p.funcSigns = make(map[string]bool)
|
|
done := make(map[*types.Package]bool)
|
|
addTypes := func(pkg *types.Package, top bool) {
|
|
if done[pkg] {
|
|
return
|
|
}
|
|
done[pkg] = true
|
|
ifs, funs := fromScope(pkg.Scope())
|
|
fullName := func(name string) string {
|
|
if !top {
|
|
return pkg.Path() + "." + name
|
|
}
|
|
return name
|
|
}
|
|
for iftype, name := range ifs {
|
|
// only suggest exported interfaces
|
|
if ast.IsExported(name) {
|
|
p.ifaces[iftype] = fullName(name)
|
|
}
|
|
}
|
|
for ftype := range funs {
|
|
// ignore non-exported func signatures too
|
|
p.funcSigns[ftype] = true
|
|
}
|
|
}
|
|
for _, imp := range pkg.Imports() {
|
|
addTypes(imp, false)
|
|
for _, imp2 := range imp.Imports() {
|
|
addTypes(imp2, false)
|
|
}
|
|
}
|
|
addTypes(pkg, true)
|
|
}
|