Skip to content

Commit 2855950

Browse files
authored
fix issue 556 (#557)
1 parent c582d62 commit 2855950

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

rule/useless-break.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func (w *lintUselessBreak) Visit(node ast.Node) ast.Visitor {
4141
ast.Walk(w, v.Body)
4242
w.inLoopBody = false
4343
return nil
44+
case *ast.RangeStmt:
45+
w.inLoopBody = true
46+
ast.Walk(w, v.Body)
47+
w.inLoopBody = false
48+
return nil
4449
case *ast.CommClause:
4550
for _, n := range v.Body {
4651
w.inspectCaseStatement(n)

testdata/useless-break.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package fixtures
22

3-
import "reflect"
3+
import (
4+
ast "go/ast"
5+
"reflect"
6+
)
47

58
func UselessBreaks() {
69

@@ -28,7 +31,7 @@ func UselessBreaks() {
2831
for {
2932
switch {
3033
case c1:
31-
break // MATCH /useless break in case clause (WARN: this break statement affects the switch or select statement and not the loop enclosing it)/
34+
break // MATCH /useless break in case clause (WARN: this break statement affects this switch or select statement and not the loop enclosing it)/
3235
}
3336
}
3437

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

0 commit comments

Comments
 (0)