File tree Expand file tree Collapse file tree 2 files changed +2
-11
lines changed Expand file tree Collapse file tree 2 files changed +2
-11
lines changed Original file line number Diff line number Diff line change 1
- // nolint:dupl
2
1
package golinters
3
2
4
3
import (
Original file line number Diff line number Diff line change 1
- // nolint:dupl
2
1
package golinters
3
2
4
3
import (
5
4
"fmt"
6
- "sort"
7
5
"sync"
8
6
9
7
"github.com/fzipp/gocyclo"
@@ -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 [] gocyclo.Stat
32
+ var stats gocyclo.Stats
35
33
for _ , f := range pass .Files {
36
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)" ,
You can’t perform that action at this time.
0 commit comments