1 Star 0 Fork 0

Laomo. / golangci-lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gas.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
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"
"github.com/sirupsen/logrus"
)
type Gas struct{}
func (Gas) Name() string {
return "gas"
}
func (Gas) Desc() string {
return "Inspects source code for security problems"
}
func (lint Gas) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
gasConfig := gas.NewConfig()
enabledRules := rules.Generate()
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
var r result.Range
line, err := strconv.Atoi(i.Line)
if err != nil {
if n, rerr := fmt.Sscanf(i.Line, "%d-%d", &r.From, &r.To); rerr != nil || n != 2 {
logrus.Infof("Can't convert gas line number %q of %v to int: %s", i.Line, i, err)
continue
}
line = r.From
}
res = append(res, result.Issue{
Pos: token.Position{
Filename: i.File,
Line: line,
},
Text: text,
LineRange: r,
FromLinter: lint.Name(),
})
}
return res, nil
}
1
https://gitee.com/LaomoBK/golangci-lint.git
git@gitee.com:LaomoBK/golangci-lint.git
LaomoBK
golangci-lint
golangci-lint
v1.3.5

搜索帮助

53164aa7 5694891 3bd8fe86 5694891