Skip to content

Commit

Permalink
fix issue 556 (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava authored Aug 16, 2021
1 parent c582d62 commit 2855950
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions rule/useless-break.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func (w *lintUselessBreak) Visit(node ast.Node) ast.Visitor {
ast.Walk(w, v.Body)
w.inLoopBody = false
return nil
case *ast.RangeStmt:
w.inLoopBody = true
ast.Walk(w, v.Body)
w.inLoopBody = false
return nil
case *ast.CommClause:
for _, n := range v.Body {
w.inspectCaseStatement(n)
Expand Down
9 changes: 6 additions & 3 deletions testdata/useless-break.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fixtures

import "reflect"
import (
ast "go/ast"
"reflect"
)

func UselessBreaks() {

Expand Down Expand Up @@ -28,7 +31,7 @@ func UselessBreaks() {
for {
switch {
case c1:
break // MATCH /useless break in case clause (WARN: this break statement affects the switch or select statement and not the loop enclosing it)/
break // MATCH /useless break in case clause (WARN: this break statement affects this switch or select statement and not the loop enclosing it)/
}
}

Expand All @@ -37,7 +40,7 @@ func UselessBreaks() {
case *ast.FuncLit:
found = true
funcLit = node
break // MATCH /useless break in case clause (WARN: this break statement affects the switch or select statement and not the loop enclosing it)/
break // MATCH /useless break in case clause (WARN: this break statement affects this switch or select statement and not the loop enclosing it)/
}
}

Expand Down

0 comments on commit 2855950

Please sign in to comment.