1
1
package rule
2
2
3
3
import (
4
- "go/ast"
5
-
6
4
"github.com/mgechev/revive/lint"
5
+ "go/ast"
7
6
)
8
7
9
8
// UseAnyRule lints given else constructs.
@@ -14,6 +13,7 @@ func (*UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
14
13
var failures []lint.Failure
15
14
16
15
walker := lintUseAny {
16
+ commentPositions : getCommentsPositions (file .AST .Comments ),
17
17
onFailure : func (failure lint.Failure ) {
18
18
failures = append (failures , failure )
19
19
},
@@ -30,7 +30,8 @@ func (*UseAnyRule) Name() string {
30
30
}
31
31
32
32
type lintUseAny struct {
33
- onFailure func (lint.Failure )
33
+ commentPositions []int
34
+ onFailure func (lint.Failure )
34
35
}
35
36
36
37
func (w lintUseAny ) Visit (n ast.Node ) ast.Visitor {
@@ -40,7 +41,13 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
40
41
}
41
42
42
43
if len (it .Methods .List ) != 0 {
43
- return w // it is not and empty interface
44
+ return w // it is not an empty interface
45
+ }
46
+
47
+ for _ , pos := range w .commentPositions {
48
+ if pos > int (it .Pos ()) && pos < int (it .End ()) {
49
+ return w // it is a comment inside the interface
50
+ }
44
51
}
45
52
46
53
w .onFailure (lint.Failure {
@@ -52,3 +59,14 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
52
59
53
60
return w
54
61
}
62
+
63
+ func getCommentsPositions (commentGroups []* ast.CommentGroup ) []int {
64
+ result := []int {}
65
+ for _ , commentGroup := range commentGroups {
66
+ for _ , comment := range commentGroup .List {
67
+ result = append (result , int (comment .Pos ()))
68
+ }
69
+ }
70
+
71
+ return result
72
+ }
0 commit comments