Skip to content

Commit cc5a232

Browse files
committed
linter: add gostrconv
1 parent d92b38c commit cc5a232

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ require (
2222
github.com/breml/bidichk v0.2.4
2323
github.com/breml/errchkjson v0.3.1
2424
github.com/butuzov/ireturn v0.1.1
25+
github.com/catenacyber/gostrconv v0.1.0
2526
github.com/charithe/durationcheck v0.0.10
2627
github.com/curioswitch/go-reassign v0.2.0
2728
github.com/daixiang0/gci v0.10.1

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/gostrconv.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/gostrconv/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+
"gostrconv",
13+
"Checks that fmt.Sprintf can be can be replaced with a faster strconv function.",
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
@@ -544,6 +544,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
544544
WithPresets(linter.PresetStyle).
545545
WithURL("https://github.com/jirfag/go-printf-func-name"),
546546

547+
linter.NewConfig(golinters.NewGoStrconv()).
548+
WithSince("v1.52.0").
549+
WithPresets(linter.PresetStyle).
550+
WithURL("https://github.com/catenacyber/gostrconv"),
551+
547552
linter.NewConfig(golinters.NewGosec(gosecCfg)).
548553
WithSince("v1.0.0").
549554
WithLoadForGoAnalysis().

test/testdata/gostrconv.go

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

0 commit comments

Comments
 (0)