Skip to content

feat: add intrange linter #4378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}