Skip to content

Commit 40d37cd

Browse files
committed
linter: add gostrconv
1 parent 904cec8 commit 40d37cd

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

.golangci.reference.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,7 @@ linters:
23012301
- nosnakecase
23022302
- nosprintfhostport
23032303
- paralleltest
2304+
- perfsprint
23042305
- prealloc
23052306
- predeclared
23062307
- promlinter
@@ -2420,6 +2421,7 @@ linters:
24202421
- nosnakecase
24212422
- nosprintfhostport
24222423
- paralleltest
2424+
- perfsprint
24232425
- prealloc
24242426
- predeclared
24252427
- promlinter

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
github.com/breml/errchkjson v0.3.6
2828
github.com/butuzov/ireturn v0.2.1
2929
github.com/butuzov/mirror v1.1.0
30+
github.com/catenacyber/perfsprint v0.2.0
3031
github.com/charithe/durationcheck v0.0.10
3132
github.com/curioswitch/go-reassign v0.2.0
3233
github.com/daixiang0/gci v0.11.2

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/perfsprint.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package golinters
2+
3+
import (
4+
"github.com/catenacyber/perfsprint/analyzer"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewGoStrconv() *goanalysis.Linter {
11+
return goanalysis.NewLinter(
12+
"perfsprint",
13+
"Checks usages of `fmt.Sprintf` which have faster alternatives.",
14+
[]*analysis.Analyzer{analyzer.Analyzer},
15+
nil,
16+
).WithLoadMode(goanalysis.LoadModeSyntax)
17+
}

pkg/lint/lintersdb/manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
712712
WithPresets(linter.PresetStyle, linter.PresetTest).
713713
WithURL("https://github.com/kunwardeep/paralleltest"),
714714

715+
linter.NewConfig(golinters.NewPerfSprint()).
716+
WithSince("v1.54.2").
717+
WithPresets(linter.PresetStyle).
718+
WithURL("https://github.com/catenacyber/perfsprint"),
719+
715720
linter.NewConfig(golinters.NewPreAlloc(preallocCfg)).
716721
WithSince("v1.19.0").
717722
WithPresets(linter.PresetPerformance).

test/testdata/perfsprint.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//golangcitest:args -Eperfsprint
2+
package testdata
3+
4+
import "fmt"
5+
6+
func SprintfCouldBeStrconv() {
7+
fmt.Sprintf("%d", 42) // want "Sprintf can be replaced with faster strconv.Itoa"
8+
}

0 commit comments

Comments
 (0)