File tree Expand file tree Collapse file tree 1 file changed +2
-9
lines changed Expand file tree Collapse file tree 1 file changed +2
-9
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package golinters
3
3
4
4
import (
5
5
"fmt"
6
- "sort"
7
6
"sync"
8
7
9
8
"github.com/fzipp/gocyclo"
@@ -31,24 +30,18 @@ func NewGocyclo() *goanalysis.Linter {
31
30
nil ,
32
31
).WithContextSetter (func (lintCtx * linter.Context ) {
33
32
analyzer .Run = func (pass * analysis.Pass ) (interface {}, error ) {
34
- var stats [] gocyclo.Stat
33
+ var stats gocyclo.Stats
35
34
for _ , f := range pass .Files {
36
35
stats = gocyclo .AnalyzeASTFile (f , pass .Fset , stats )
37
36
}
38
37
if len (stats ) == 0 {
39
38
return nil , nil
40
39
}
41
40
42
- sort .SliceStable (stats , func (i , j int ) bool {
43
- return stats [i ].Complexity > stats [j ].Complexity
44
- })
41
+ stats = stats .SortAndFilter (- 1 , lintCtx .Settings ().Gocyclo .MinComplexity )
45
42
46
43
res := make ([]goanalysis.Issue , 0 , len (stats ))
47
44
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
45
res = append (res , goanalysis .NewIssue (& result.Issue {
53
46
Pos : s .Pos ,
54
47
Text : fmt .Sprintf ("cyclomatic complexity %d of func %s is high (> %d)" ,
You can’t perform that action at this time.
0 commit comments