代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。