From d6d27c741f290c9e7615306b7443b468e07c7429 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Wed, 13 Dec 2023 22:35:12 +0100 Subject: [PATCH] Generic simplification for explicit arg --- analyzer/analyzer.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index c337f5c..2e93d04 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -126,6 +126,10 @@ func (n *perfSprint) run(pass *analysis.Pass) (interface{}, error) { // Probably unreachable. return } + // one single explicit arg is simplified + if strings.HasPrefix(verb, "%[1]") { + verb = "%" + verb[4:] + } fn = "fmt.Sprintf" value = call.Args[1] @@ -140,7 +144,7 @@ func (n *perfSprint) run(pass *analysis.Pass) (interface{}, error) { break } return - case "%d", "%v", "%x", "%t", "%s", "%[1]s": + case "%d", "%v", "%x", "%t", "%s": } valueType := pass.TypesInfo.TypeOf(value) @@ -149,7 +153,7 @@ func (n *perfSprint) run(pass *analysis.Pass) (interface{}, error) { var d *analysis.Diagnostic switch { - case isBasicType(valueType, types.String) && oneOf(verb, "%v", "%s", "%[1]s"): + case isBasicType(valueType, types.String) && oneOf(verb, "%v", "%s"): fname := pass.Fset.File(call.Pos()).Name() _, ok := neededPackages[fname] if !ok {