feat: add intrange linter (#4378)

This commit is contained in:
Clifton Kaznocha 2024-02-15 15:03:11 -08:00 committed by GitHub
parent 76cfe46b3d
commit b96ff83e0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 0 deletions

View File

@ -2538,6 +2538,7 @@ linters:
- ineffassign
- interfacebloat
- interfacer
- intrange
- ireturn
- lll
- loggercheck
@ -2659,6 +2660,7 @@ linters:
- ineffassign
- interfacebloat
- interfacer
- intrange
- ireturn
- lll
- loggercheck

1
go.mod
View File

@ -29,6 +29,7 @@ require (
github.com/butuzov/mirror v1.1.0
github.com/catenacyber/perfsprint v0.7.0
github.com/charithe/durationcheck v0.0.10
github.com/ckaznocha/intrange v0.1.0
github.com/curioswitch/go-reassign v0.2.0
github.com/daixiang0/gci v0.12.1
github.com/denis-tingaikin/go-header v0.4.3

2
go.sum generated
View File

@ -115,6 +115,8 @@ github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+U
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/ckaznocha/intrange v0.1.0 h1:ZiGBhvrdsKpoEfzh9CjBfDSZof6QB0ORY5tXasUtiew=
github.com/ckaznocha/intrange v0.1.0/go.mod h1:Vwa9Ekex2BrEQMg6zlrWwbs/FtYw7eS5838Q7UjK7TQ=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=

19
pkg/golinters/intrange.go Normal file
View File

@ -0,0 +1,19 @@
package golinters
import (
"github.com/ckaznocha/intrange"
"golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)
func NewIntrange() *goanalysis.Linter {
a := intrange.Analyzer
return goanalysis.NewLinter(
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeSyntax)
}

View File

@ -608,6 +608,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithURL("https://github.com/mvdan/interfacer").
Deprecated("The repository of the linter has been archived by the owner.", "v1.38.0", ""),
linter.NewConfig(golinters.NewIntrange()).
WithSince("v1.57.0").
WithURL("https://github.com/ckaznocha/intrange"),
linter.NewConfig(golinters.NewIreturn(ireturnCfg)).
WithSince("v1.43.0").
WithPresets(linter.PresetStyle).

19
test/testdata/intrange.go vendored Normal file
View File

@ -0,0 +1,19 @@
//golangcitest:args -Eintrange
package testdata
import "math"
func CheckIntrange() {
for i := 0; i < 10; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
}
for i := uint8(0); i < math.MaxInt8; i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
}
for i := 0; i < 10; i += 2 {
}
for i := 0; i < 10; i++ {
i += 1
}
}