1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-01 13:07:44 +02:00

Revert "fix: unnecesary alert for use-any when comments inside interface{} (#873)" (#874)

This reverts commit 519ffbdd7a328599a2fd123d28b31e5bb6225a89.
This commit is contained in:
chavacava 2023-08-19 08:07:28 +02:00 committed by GitHub
parent 9acfcc8f86
commit e758901c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 26 deletions

View File

@ -1,8 +1,9 @@
package rule
import (
"github.com/mgechev/revive/lint"
"go/ast"
"github.com/mgechev/revive/lint"
)
// UseAnyRule lints given else constructs.
@ -13,7 +14,6 @@ func (*UseAnyRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
walker := lintUseAny{
commentPositions: getCommentsPositions(file.AST.Comments),
onFailure: func(failure lint.Failure) {
failures = append(failures, failure)
},
@ -30,8 +30,7 @@ func (*UseAnyRule) Name() string {
}
type lintUseAny struct {
commentPositions []int
onFailure func(lint.Failure)
onFailure func(lint.Failure)
}
func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
@ -41,13 +40,7 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
}
if len(it.Methods.List) != 0 {
return w // it is not an empty interface
}
for _, pos := range w.commentPositions {
if pos > int(it.Pos()) && pos < int(it.End()) {
return w // it is a comment inside the interface
}
return w // it is not and empty interface
}
w.onFailure(lint.Failure{
@ -59,14 +52,3 @@ func (w lintUseAny) Visit(n ast.Node) ast.Visitor {
return w
}
func getCommentsPositions(commentGroups []*ast.CommentGroup) []int {
result := []int{}
for _, commentGroup := range commentGroups {
for _, comment := range commentGroup.List {
result = append(result, int(comment.Pos()))
}
}
return result
}

4
testdata/use-any.go vendored
View File

@ -17,10 +17,6 @@ func any2(a int) interface{} {} // MATCH /since GO 1.18 'interface{}' can be rep
var ni interface{ Close() }
var ni interface {
// Close()
}
type nt interface{ Close() }
type na = interface{ Close() }