Skip to content

Commit

Permalink
flag: option to disable errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Oct 25, 2023
1 parent bb9d531 commit 8c0a424
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ go get github.com/catenacyber/perfsprint@latest
perfsprint --fix ./...
```

To disable int/uint cast, you can use flag `-int-conversion=false`
To disable int/uint cast, you can use the flag `-int-conversion=false`

To disable `fmt.Errorf` optimization, you can use the flag `-errorf=false`

To enable `err.Error()` optimization, you can use the flag `-err-error=true`
This optimization only works when the error is not nil, otherwise the resulting code will panic.

### Replacements

Expand Down
4 changes: 3 additions & 1 deletion analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
type perfSprint struct {
intConv bool
errError bool
errorf bool
}

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

func New() *analysis.Analyzer {
Expand All @@ -34,6 +35,7 @@ func New() *analysis.Analyzer {
}
r.Flags.BoolVar(&n.intConv, "int-conversion", true, "optimizes even if it requires an int or uint type cast")
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")
return r
}

Expand Down

0 comments on commit 8c0a424

Please sign in to comment.