Skip to content

Commit

Permalink
Generic simplification for explicit arg
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Dec 13, 2023
1 parent 6a832b9 commit c553de9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit c553de9

Please sign in to comment.