Skip to content

Commit e758901

Browse files
authored
Revert "fix: unnecesary alert for use-any when comments inside interface{} (#873)" (#874)
This reverts commit 519ffbd.
1 parent 9acfcc8 commit e758901

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

rule/use-any.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package rule
22

33
import (
4-
"github.com/mgechev/revive/lint"
54
"go/ast"
5+
6+
"github.com/mgechev/revive/lint"
67
)
78

89
// UseAnyRule lints given else constructs.
@@ -13,7 +14,6 @@ func (*UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
1314
var failures []lint.Failure
1415

1516
walker := lintUseAny{
16-
commentPositions: getCommentsPositions(file.AST.Comments),
1717
onFailure: func(failure lint.Failure) {
1818
failures = append(failures, failure)
1919
},
@@ -30,8 +30,7 @@ func (*UseAnyRule) Name() string {
3030
}
3131

3232
type lintUseAny struct {
33-
commentPositions []int
34-
onFailure func(lint.Failure)
33+
onFailure func(lint.Failure)
3534
}
3635

3736
func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
@@ -41,13 +40,7 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
4140
}
4241

4342
if len(it.Methods.List) != 0 {
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-
}
43+
return w // it is not and empty interface
5144
}
5245

5346
w.onFailure(lint.Failure{
@@ -59,14 +52,3 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
5952

6053
return w
6154
}
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-
}

testdata/use-any.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ func any2(a int) interface{} {} // MATCH /since GO 1.18 'interface{}' can be rep
1717

1818
var ni interface{ Close() }
1919

20-
var ni interface {
21-
// Close()
22-
}
23-
2420
type nt interface{ Close() }
2521
type na = interface{ Close() }
2622

0 commit comments

Comments
 (0)