GitXplorerGitXplorer
c

perfsprint

public
27 stars
4 forks
5 issues

Commits

List of commits on branch main.
Unverified
9d2eaecf6b1859a0b8ca6537ab4bc24de5f6de40

analyzer: fix false positive with multiple pos args

ccatenacyber committed a year ago
Unverified
5dbf3ce6a74f300ff33995270337a1ba41a0467f

analyzer: use word concatenation rather than addition

ccatenacyber committed a year ago
Unverified
b66013fa8dbdf5540a474aecfed5a925bf99a98f

analyzer: make string concatenation optional

ccatenacyber committed a year ago
Unverified
94b53d906abe32e514fc4bc3e8b1fd5e6542266c

analyzer: make imports fixing optional

ccatenacyber committed a year ago
Unverified
fae648ae9587a4d239c3517a24b7bd3ed995203b

style: simplify assignments using assignment operators

aalexandear committed a year ago
Unverified
c553de90c97992aeddd4f45d22b428c925ea78bf

Generic simplification for explicit arg

ccatenacyber committed a year ago

README

The README file for this repository.

perfsprint

CI Go Report Card

Golang linter for performance, aiming at usages of fmt.Sprintf which have faster alternatives.

Installation

go install github.com/catenacyber/perfsprint@latest

Usage

perfsprint --fix ./...

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 This optimization is not always equivalent. The code

msg := "format string attack %s"
fmt.Errorf(msg)

will panic when its optimized version will not (so it should be safer).

To disable fmt.Sprintf("toto") optimization, you can use the flag -sprintf1=false This optimization is not always equivalent. The code

msg := "format string attack %s"
fmt.Sprintf(msg)

will panic when its optimized version will not (so it should be safer).

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

fmt.Sprintf("%s", strVal)  ->  strVal
fmt.Sprintf("%t", boolVal) ->  strconv.FormatBool(boolBal)
fmt.Sprintf("%x", hash)    ->  hex.EncodeToString(hash)
fmt.Sprintf("%d", id)      ->  strconv.Itoa(id)
fmt.Sprintf("%v", version) ->  strconv.FormatUint(uint64(version), 10)

More in tests.