Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tools/fmtpercentv/fmtpercentv.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func checkCallExpr(expr *ast.CallExpr, tokenPos token.Pos, pass *analysis.Pass)
if fun.Sel.Name != "Sprintf" && fun.Sel.Name != "Printf" && fun.Sel.Name != "Fprintf" && fun.Sel.Name != "Errorf" {
return
}
fmtStrBasicLit, ok := expr.Args[0].(*ast.BasicLit)
argIdx := 0
if fun.Sel.Name == "Fprintf" {
argIdx = 1
}
fmtStrBasicLit, ok := expr.Args[argIdx].(*ast.BasicLit)
if !ok {
return
}
Expand Down
1 change: 1 addition & 0 deletions tools/fmtpercentv/testdata/src/has-warnings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ func main() {
_ = fmt.Sprintf("some/%d/%s/url", 1, "yo") // want `use %v instead of %s and %d`
fmt.Printf("some %d", 1) // want `use %v instead of %d`
fmt.Printf("some %s", "thing") // want `use %v instead of %s`
fmt.Fprintf(nil, "some %s", "thing") // want `use %v instead of %s`
}
1 change: 1 addition & 0 deletions tools/fmtpercentv/testdata/src/no-warnings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ func main() {
_ = fmt.Sprintf("some/%v/url", 1) // Should not be flagged
fmt.Printf("some %v", 1) // Should not be flagged
fmt.Printf("some %v", "thing") // Should not be flagged
fmt.Fprintf(nil, "some %v", 1) // Should not be flagged
}
Loading