
Use build.Import instead of manual parser.ParseFile and paths traversal. It allows: 1. support build tags for all linters. 2. analyze files only for current GOOS/GOARCH: less false-positives. 3. analyze xtest packages (*_test) by golint: upstream golint and gometalinter can't do it! And don't break analysis on the first xtest package like it was before. 4. proper handling of xtest packages for linters like goconst where package boundary is important: less false-positives is expected. Also: 1. reuse AST parsing for golint and goconst: minor speedup. 2. allow to specify path (not only name) regexp for --skip-files and --skip-dirs 3. add more default exclude filters for golint about commits: `(comment on exported (method|function)|should have( a package)? comment|comment should be of the form)` 4. print skipped dir in verbose (-v) mode 5. refactor per-linter tests: declare arguments in comments, run only one linter and in combination with slow linter
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package golinters
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
govetAPI "github.com/golangci/govet"
|
|
)
|
|
|
|
type Govet struct{}
|
|
|
|
func (Govet) Name() string {
|
|
return "govet"
|
|
}
|
|
|
|
func (Govet) Desc() string {
|
|
return "Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string"
|
|
}
|
|
|
|
func (g Govet) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
|
// TODO: check .S asm files: govet can do it if pass dirs
|
|
var govetIssues []govetAPI.Issue
|
|
for _, pkg := range lintCtx.PkgProgram.Packages() {
|
|
issues, err := govetAPI.Run(pkg.Files(lintCtx.Cfg.Run.AnalyzeTests), lintCtx.Settings().Govet.CheckShadowing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
govetIssues = append(govetIssues, issues...)
|
|
}
|
|
if len(govetIssues) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
res := make([]result.Issue, 0, len(govetIssues))
|
|
for _, i := range govetIssues {
|
|
res = append(res, result.Issue{
|
|
Pos: i.Pos,
|
|
Text: i.Message,
|
|
FromLinter: g.Name(),
|
|
})
|
|
}
|
|
return res, nil
|
|
}
|