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 9, 2023
1 parent bce3dfd commit 3e46118
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
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.0
github.com/butuzov/mirror v1.1.0
github.com/catenacyber/gostrconv v0.1.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/gostrconv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package golinters

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

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

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

linter.NewConfig(golinters.NewGoStrconv()).
WithSince("v1.53.0").
WithPresets(linter.PresetStyle).
WithURL("https://github.com/catenacyber/gostrconv"),

linter.NewConfig(golinters.NewGosec(gosecCfg)).
WithSince("v1.0.0").
WithLoadForGoAnalysis().
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/gostrconv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//golangcitest:args -Egostrconv
package testdata

import "fmt"

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

0 comments on commit 3e46118

Please sign in to comment.