Skip to content

Commit

Permalink
Remove exception for testing.B
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaznocha committed Nov 9, 2024
1 parent cd7c74e commit 366f6fb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
30 changes: 0 additions & 30 deletions intrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testdata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testdata/main.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 366f6fb

Please sign in to comment.