Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions rule/use-any.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package rule

import (
"github.com/mgechev/revive/lint"
"go/ast"

"github.com/mgechev/revive/lint"
)

// UseAnyRule lints given else constructs.
Expand All @@ -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)
},
Expand All @@ -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 {
Expand All @@ -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{
Expand All @@ -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 changes: 0 additions & 4 deletions testdata/use-any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand Down