2018-05-08 11:54:30 +03:00

48 lines
1.1 KiB
Go

package golinters
import (
"context"
"fmt"
"go/token"
"io/ioutil"
"log"
"strconv"
"github.com/GoASTScanner/gas"
"github.com/GoASTScanner/gas/rules"
"github.com/golangci/golangci-lint/pkg/result"
)
type Gas struct{}
func (Gas) Name() string {
return "gas"
}
func (lint Gas) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
gasConfig := gas.NewConfig()
enabledRules := rules.Generate(rules.NewRuleFilter(true, "G104")) // disable what errcheck does: it reports on Close etc
logger := log.New(ioutil.Discard, "", 0)
analyzer := gas.NewAnalyzer(gasConfig, logger)
analyzer.LoadRules(enabledRules.Builders())
analyzer.ProcessProgram(lintCtx.Program)
issues, _ := analyzer.Report()
var res []result.Issue
for _, i := range issues {
text := fmt.Sprintf("%s: %s", i.RuleID, i.What) // TODO: use severity and confidence
line, _ := strconv.Atoi(i.Line)
res = append(res, result.Issue{
Pos: token.Position{
Filename: i.File,
Line: line,
},
Text: text,
FromLinter: lint.Name(),
})
}
return res, nil
}