From 366f6fbde5586a45e65eb93bd9ab94409267df55 Mon Sep 17 00:00:00 2001 From: ckaznocha Date: Sat, 9 Nov 2024 15:05:54 -0800 Subject: [PATCH] Remove exception for testing.B --- intrange.go | 30 ------------------------------ testdata/main.go | 4 ++-- testdata/main.go.golden | 4 ++-- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/intrange.go b/intrange.go index f3c2ff5..4d3430e 100644 --- a/intrange.go +++ b/intrange.go @@ -101,10 +101,6 @@ func checkForStmt(pass *analysis.Pass, forStmt *ast.ForStmt) { switch cond.Op { case token.LSS: // ;i < n; - if isBenchmark(cond.Y) { - return - } - x, ok := cond.X.(*ast.Ident) if !ok { return @@ -116,10 +112,6 @@ func checkForStmt(pass *analysis.Pass, forStmt *ast.ForStmt) { operand = cond.Y case token.GTR: // ;n > i; - if isBenchmark(cond.X) { - return - } - y, ok := cond.Y.(*ast.Ident) if !ok { return @@ -406,28 +398,6 @@ func recursiveOperandToString(expr ast.Expr) string { } } -func isBenchmark(expr ast.Expr) bool { - selectorExpr, ok := expr.(*ast.SelectorExpr) - if !ok { - return false - } - - if selectorExpr.Sel.Name != "N" { - return false - } - - ident, ok := selectorExpr.X.(*ast.Ident) - if !ok { - return false - } - - if ident.Name == "b" { - return true - } - - return false -} - func identEqual(a, b ast.Expr) bool { if a == nil || b == nil { return false diff --git a/testdata/main.go b/testdata/main.go index d62c307..f017619 100644 --- a/testdata/main.go +++ b/testdata/main.go @@ -149,10 +149,10 @@ func main() { } var b *testing.B - for i := 0; i < b.N; i++ { + for i := 0; i < b.N; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)` } - for i := 0; b.N >= i; i++ { + for i := 0; b.N > i; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)` } var n int diff --git a/testdata/main.go.golden b/testdata/main.go.golden index 8a2c85c..48501eb 100644 --- a/testdata/main.go.golden +++ b/testdata/main.go.golden @@ -149,10 +149,10 @@ func main() { } var b *testing.B - for i := 0; i < b.N; i++ { + for i := range b.N { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)` } - for i := 0; b.N >= i; i++ { + for i := range b.N { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)` } var n int