1
- // nolint:dupl
2
1
package golinters
3
2
4
3
import (
5
4
"fmt"
6
- "sort"
7
5
"sync"
8
6
9
- gocycloAPI "github.com/golangci/gocyclo/pkg /gocyclo"
7
+ "github.com/fzipp /gocyclo"
10
8
"golang.org/x/tools/go/analysis"
11
9
12
10
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
@@ -31,24 +29,18 @@ func NewGocyclo() *goanalysis.Linter {
31
29
nil ,
32
30
).WithContextSetter (func (lintCtx * linter.Context ) {
33
31
analyzer .Run = func (pass * analysis.Pass ) (interface {}, error ) {
34
- var stats []gocycloAPI. Stat
32
+ var stats gocyclo. Stats
35
33
for _ , f := range pass .Files {
36
- stats = gocycloAPI . BuildStats (f , pass .Fset , stats )
34
+ stats = gocyclo . AnalyzeASTFile (f , pass .Fset , stats )
37
35
}
38
36
if len (stats ) == 0 {
39
37
return nil , nil
40
38
}
41
39
42
- sort .SliceStable (stats , func (i , j int ) bool {
43
- return stats [i ].Complexity > stats [j ].Complexity
44
- })
40
+ stats = stats .SortAndFilter (- 1 , lintCtx .Settings ().Gocyclo .MinComplexity )
45
41
46
42
res := make ([]goanalysis.Issue , 0 , len (stats ))
47
43
for _ , s := range stats {
48
- if s .Complexity <= lintCtx .Settings ().Gocyclo .MinComplexity {
49
- break // Break as the stats is already sorted from greatest to least
50
- }
51
-
52
44
res = append (res , goanalysis .NewIssue (& result.Issue {
53
45
Pos : s .Pos ,
54
46
Text : fmt .Sprintf ("cyclomatic complexity %d of func %s is high (> %d)" ,
0 commit comments