
1. Log all warnings, don't hide none of them 2. Write fatal messages (stop analysis) with error log level 3. Remove ugly timestamp counter from logrus output 4. Print nested module prefix in log 5. Make logger abstraction: no global logging anymore 6. Refactor config reading to config.FileReader struct to avoid passing logger into every function 7. Replace exit codes hardcoding with constants in exitcodes package 8. Fail test if any warning was logged 9. Fix calculation of relative path if we analyze parent dir ../ 10. Move Runner initialization from Executor to NewRunner func 11. Log every AST parsing error 12. Properly print used config file path in verbose mode 13. Print package files if only 1 package is analyzedin verbose mode, print not compiling packages in verbose mode 14. Forbid usage of github.com/sirupsen/logrus by DepGuard linter 15. Add default ignore pattern to folint: "comment on exported const"
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package golinters
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"go/ast"
|
|
"go/token"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
lintAPI "github.com/golangci/lint-1"
|
|
)
|
|
|
|
type Golint struct{}
|
|
|
|
func (Golint) Name() string {
|
|
return "golint"
|
|
}
|
|
|
|
func (Golint) Desc() string {
|
|
return "Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes"
|
|
}
|
|
|
|
func (g Golint) Run(ctx context.Context, lintCtx *linter.Context) ([]result.Issue, error) {
|
|
var issues []result.Issue
|
|
var lintErr error
|
|
for _, pkg := range lintCtx.PkgProgram.Packages() {
|
|
files, fset, err := getASTFilesForPkg(lintCtx, &pkg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
i, err := g.lintPkg(lintCtx.Settings().Golint.MinConfidence, files, fset)
|
|
if err != nil {
|
|
lintErr = err
|
|
continue
|
|
}
|
|
issues = append(issues, i...)
|
|
}
|
|
if lintErr != nil {
|
|
lintCtx.Log.Warnf("Golint: %s", lintErr)
|
|
}
|
|
|
|
return issues, nil
|
|
}
|
|
|
|
func (g Golint) lintPkg(minConfidence float64, files []*ast.File, fset *token.FileSet) ([]result.Issue, error) {
|
|
l := new(lintAPI.Linter)
|
|
ps, err := l.LintASTFiles(files, fset)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("can't lint %d files: %s", len(files), err)
|
|
}
|
|
|
|
if len(ps) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
issues := make([]result.Issue, 0, len(ps)) // This is worst case
|
|
for _, p := range ps {
|
|
if p.Confidence >= minConfidence {
|
|
issues = append(issues, result.Issue{
|
|
Pos: p.Position,
|
|
Text: p.Text,
|
|
FromLinter: g.Name(),
|
|
})
|
|
// TODO: use p.Link and p.Category
|
|
}
|
|
}
|
|
|
|
return issues, nil
|
|
}
|