зеркало из https://github.com/golang/tools.git
go/analysis/passes/printf: add global to disable new diagnostics
Adds a global to allow for disabling the new constant format string for Printf calls. This is to allow for easier staged upgrades of x/tools. Change-Id: I5dc0d88cf6328a68e8994010e388366102afc892 Reviewed-on: https://go-review.googlesource.com/c/tools/+/613655 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Родитель
a319a85de8
Коммит
765ea95f2b
|
@ -508,7 +508,7 @@ func checkPrintf(pass *analysis.Pass, kind Kind, call *ast.CallExpr, fn *types.F
|
|||
}
|
||||
formatArg := call.Args[idx]
|
||||
format, ok := stringConstantExpr(pass, formatArg)
|
||||
if !ok {
|
||||
if !ok && !suppressNonconstants {
|
||||
// Format string argument is non-constant.
|
||||
|
||||
// It is a common mistake to call fmt.Printf(msg) with a
|
||||
|
@ -1101,3 +1101,12 @@ func (ss stringSet) Set(flag string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// suppressNonconstants suppresses reporting printf calls with
|
||||
// non-constant formatting strings (proposal #60529) when true.
|
||||
//
|
||||
// This variable is to allow for staging the transition to newer
|
||||
// versions of x/tools by vendoring.
|
||||
//
|
||||
// Remove this after the 1.24 release.
|
||||
var suppressNonconstants bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче