Skip to content

Commit

Permalink
feat: add intrange linter (#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckaznocha committed Feb 15, 2024
1 parent 76cfe46 commit b96ff83
Show file tree
Hide file tree
Showing 6 changed files with 47 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 @@ -2538,6 +2538,7 @@ linters:
- ineffassign
- interfacebloat
- interfacer
- intrange
- ireturn
- lll
- loggercheck
Expand Down Expand Up @@ -2659,6 +2660,7 @@ linters:
- ineffassign
- interfacebloat
- interfacer
- intrange
- ireturn
- lll
- loggercheck
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

19 changes: 19 additions & 0 deletions pkg/golinters/intrange.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
19 changes: 19 additions & 0 deletions test/testdata/intrange.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit b96ff83

Please sign in to comment.