GitXplorerGitXplorer
c

perfsprint

public
27 stars
4 forks
5 issues

Commits

List of commits on branch main.
Unverified
d9131b0576a8df56c5343595a0b761419a14c760

analyzer: refactor value type of neededPackages map

aalexandear committed 2 months ago
Unverified
a34cbe326a6b6cf93780d771650ba390a3298f48

chore: refactor Diagnostic declaration

mmmorel-35 committed 2 months ago
Unverified
f7c1bb995dbbe6e2b2ccd8064035ef2ec14f4b2a

analyzer: remove redundant if stmts

aalexandear committed 2 months ago
Verified
33099e0796ba7f5bca54f1c9c53b05c20f460f32

clean up ci (#35)

mmmorel-35 committed 2 months ago
Unverified
7f3ce4e8ba59949fd6a4282804a42e3e539cd267

ci: update actions and golangci-lint

aalexandear committed 2 months ago
Unverified
e84fb820eee9ef7e89fc8c6587ddad875ba36c72

docs: update installation instructions to use go install

mmaxwelbm committed 3 months 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.