}
arg := args[0]
if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING {
- if strings.Contains(lit.Value, "%") {
+ // Ignore trailing % character in lit.Value.
+ // The % in "abc 0.0%" couldn't be a formatting directive.
+ s := strings.TrimSuffix(lit.Value, `%"`)
+ if strings.Contains(s, "%") {
f.Badf(call.Pos(), "possible formatting directive in %s call", name)
}
}
fmt.Printf("%.*s %d %g", 3, "hi", 23, 'x') // ERROR "arg 'x' for printf verb %g of wrong type"
fmt.Println() // not an error
fmt.Println("%s", "hi") // ERROR "possible formatting directive in Println call"
+ fmt.Println("0.0%") // correct (trailing % couldn't be a formatting directive)
fmt.Printf("%s", "hi", 3) // ERROR "wrong number of args for format in Printf call"
_ = fmt.Sprintf("%"+("s"), "hi", 3) // ERROR "wrong number of args for format in Sprintf call"
fmt.Printf("%s%%%d", "hi", 3) // correct