Skip to content

Commit bb12ee5

Browse files
authored
Remove exception for testing.B (#36)
1 parent cd7c74e commit bb12ee5

File tree

3 files changed

+4
-34
lines changed

3 files changed

+4
-34
lines changed

intrange.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ func checkForStmt(pass *analysis.Pass, forStmt *ast.ForStmt) {
101101

102102
switch cond.Op {
103103
case token.LSS: // ;i < n;
104-
if isBenchmark(cond.Y) {
105-
return
106-
}
107-
108104
x, ok := cond.X.(*ast.Ident)
109105
if !ok {
110106
return
@@ -116,10 +112,6 @@ func checkForStmt(pass *analysis.Pass, forStmt *ast.ForStmt) {
116112

117113
operand = cond.Y
118114
case token.GTR: // ;n > i;
119-
if isBenchmark(cond.X) {
120-
return
121-
}
122-
123115
y, ok := cond.Y.(*ast.Ident)
124116
if !ok {
125117
return
@@ -406,28 +398,6 @@ func recursiveOperandToString(expr ast.Expr) string {
406398
}
407399
}
408400

409-
func isBenchmark(expr ast.Expr) bool {
410-
selectorExpr, ok := expr.(*ast.SelectorExpr)
411-
if !ok {
412-
return false
413-
}
414-
415-
if selectorExpr.Sel.Name != "N" {
416-
return false
417-
}
418-
419-
ident, ok := selectorExpr.X.(*ast.Ident)
420-
if !ok {
421-
return false
422-
}
423-
424-
if ident.Name == "b" {
425-
return true
426-
}
427-
428-
return false
429-
}
430-
431401
func identEqual(a, b ast.Expr) bool {
432402
if a == nil || b == nil {
433403
return false

testdata/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ func main() {
149149
}
150150

151151
var b *testing.B
152-
for i := 0; i < b.N; i++ {
152+
for i := 0; i < b.N; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
153153
}
154154

155-
for i := 0; b.N >= i; i++ {
155+
for i := 0; b.N > i; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
156156
}
157157

158158
var n int

testdata/main.go.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ func main() {
149149
}
150150

151151
var b *testing.B
152-
for i := 0; i < b.N; i++ {
152+
for i := range b.N { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
153153
}
154154

155-
for i := 0; b.N >= i; i++ {
155+
for i := range b.N { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
156156
}
157157

158158
var n int

0 commit comments

Comments
 (0)