1 Star 0 Fork 0

Laomo. / golangci-lint

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gocyclo.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
package golinters
import (
"context"
"fmt"
"sort"
gocycloAPI "github.com/golangci/gocyclo/pkg/gocyclo"
"github.com/golangci/golangci-lint/pkg/result"
)
type Gocyclo struct{}
func (Gocyclo) Name() string {
return "gocyclo"
}
func (Gocyclo) Desc() string {
return "Computes and checks the cyclomatic complexity of functions"
}
func (g Gocyclo) Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) {
var stats []gocycloAPI.Stat
for _, f := range lintCtx.ASTCache.GetAllValidFiles() {
stats = gocycloAPI.BuildStats(f.F, f.Fset, stats)
}
sort.Slice(stats, func(i, j int) bool {
return stats[i].Complexity > stats[j].Complexity
})
var res []result.Issue
for _, s := range stats {
if s.Complexity <= lintCtx.Settings().Gocyclo.MinComplexity {
continue
}
res = append(res, result.Issue{
Pos: s.Pos,
Text: fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)",
s.Complexity, formatCode(s.FuncName, lintCtx.Cfg), lintCtx.Settings().Gocyclo.MinComplexity),
FromLinter: g.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