Skip to content

Commit

Permalink
analyzer: make imports fixing optional
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Feb 2, 2024
1 parent fae648a commit 94b53d9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ import (
)

type perfSprint struct {
intConv bool
errError bool
errorf bool
sprintf1 bool
intConv bool
errError bool
errorf bool
sprintf1 bool
fiximports bool
}

func newPerfSprint() *perfSprint {
return &perfSprint{
intConv: true,
errError: false,
errorf: true,
sprintf1: true,
intConv: true,
errError: false,
errorf: true,
sprintf1: true,
fiximports: true,
}
}

Expand All @@ -44,6 +46,7 @@ func New() *analysis.Analyzer {
r.Flags.BoolVar(&n.errError, "err-error", false, "optimizes into err.Error() even if it is only equivalent for non-nil errors")
r.Flags.BoolVar(&n.errorf, "errorf", true, "optimizes fmt.Errorf")
r.Flags.BoolVar(&n.sprintf1, "sprintf1", true, "optimizes fmt.Sprintf with only one argument")
r.Flags.BoolVar(&n.fiximports, "fiximports", true, "fix needed imports from other fixes")
return r
}

Expand Down Expand Up @@ -486,7 +489,7 @@ func (n *perfSprint) run(pass *analysis.Pass) (interface{}, error) {
}
})

if len(removedFmtUsages) > 0 {
if len(removedFmtUsages) > 0 && n.fiximports {
for _, pkg := range pass.Pkg.Imports() {
if pkg.Path() == "fmt" {
insp = pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
Expand Down

0 comments on commit 94b53d9

Please sign in to comment.