Skip to content

Commit

Permalink
linter: add gostrconv
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Oct 19, 2023
1 parent 904cec8 commit 40d37cd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ linters:
- nosnakecase
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
Expand Down Expand Up @@ -2420,6 +2421,7 @@ linters:
- nosnakecase
- nosprintfhostport
- paralleltest
- perfsprint
- prealloc
- predeclared
- promlinter
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/breml/errchkjson v0.3.6
github.com/butuzov/ireturn v0.2.1
github.com/butuzov/mirror v1.1.0
github.com/catenacyber/perfsprint v0.2.0
github.com/charithe/durationcheck v0.0.10
github.com/curioswitch/go-reassign v0.2.0
github.com/daixiang0/gci v0.11.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/golinters/perfsprint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package golinters

import (
"github.com/catenacyber/perfsprint/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewGoStrconv() *goanalysis.Linter {
return goanalysis.NewLinter(
"perfsprint",
"Checks usages of `fmt.Sprintf` which have faster alternatives.",
[]*analysis.Analyzer{analyzer.Analyzer},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle, linter.PresetTest).
WithURL("https://github.com/kunwardeep/paralleltest"),

linter.NewConfig(golinters.NewPerfSprint()).
WithSince("v1.54.2").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/catenacyber/perfsprint"),

linter.NewConfig(golinters.NewPreAlloc(preallocCfg)).
WithSince("v1.19.0").
WithPresets(linter.PresetPerformance).
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/perfsprint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//golangcitest:args -Eperfsprint
package testdata

import "fmt"

func SprintfCouldBeStrconv() {
fmt.Sprintf("%d", 42) // want "Sprintf can be replaced with faster strconv.Itoa"
}

0 comments on commit 40d37cd

Please sign in to comment.