Skip to content

Commit

Permalink
analyzer: fix case for errorf=false
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Nov 21, 2023
1 parent 818daea commit 06b78c0
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 +133,32 @@ func (n *perfSprint) run(pass *analysis.Pass) (interface{}, error) {
switch {
case isBasicType(valueType, types.String) && oneOf(verb, "%v", "%s"):
fname := pass.Fset.File(call.Pos()).Name()
removedFmtUsages[fname] = removedFmtUsages[fname] + 1
_, ok := neededPackages[fname]
if !ok {
neededPackages[fname] = make(map[string]bool)
}
if fn == "fmt.Errorf" {
neededPackages[fname]["errors"] = true
d = &analysis.Diagnostic{
Pos: call.Pos(),
End: call.End(),
Message: fn + " can be replaced with errors.New",
SuggestedFixes: []analysis.SuggestedFix{
{
Message: "Use errors.New",
TextEdits: []analysis.TextEdit{{
Pos: call.Pos(),
End: value.Pos(),
NewText: []byte("errors.New("),
}},
if n.errorf {
removedFmtUsages[fname] = removedFmtUsages[fname] + 1
neededPackages[fname]["errors"] = true
d = &analysis.Diagnostic{
Pos: call.Pos(),
End: call.End(),
Message: fn + " can be replaced with errors.New",
SuggestedFixes: []analysis.SuggestedFix{
{
Message: "Use errors.New",
TextEdits: []analysis.TextEdit{{
Pos: call.Pos(),
End: value.Pos(),
NewText: []byte("errors.New("),
}},
},
},
},
}
}
} else {
removedFmtUsages[fname] = removedFmtUsages[fname] + 1
d = &analysis.Diagnostic{
Pos: call.Pos(),
End: call.End(),
Expand Down

0 comments on commit 06b78c0

Please sign in to comment.