go/analysis/passes/printf: return when suppressing a non-constant diagnostic

Change-Id: Ied134c5e3b3414253de02f3ac4f8a7f73e9427ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/613516
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Tim King 2024-09-17 10:49:49 -07:00
Родитель 5cb6eeba24
Коммит 2aabc4f384
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -508,14 +508,14 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
}
formatArg := call.Args[idx]
format, ok := stringConstantExpr(pass, formatArg)
if !ok && !suppressNonconstants {
if !ok {
// Format string argument is non-constant.
// It is a common mistake to call fmt.Printf(msg) with a
// non-constant format string and no arguments:
// if msg contains "%", misformatting occurs.
// Report the problem and suggest a fix: fmt.Printf("%s", msg).
if idx == len(call.Args)-1 {
if !suppressNonconstants && idx == len(call.Args)-1 {
pass.Report(analysis.Diagnostic{
Pos: formatArg.Pos(),
End: formatArg.End(),