Skip to content
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
4 changes: 4 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,8 @@ linters:
- newexpr
# Suggest replacing omitempty with omitzero for struct fields.
- omitzero
# Remove obsolete //+build comments.
- plusbuild
# Replace 3-clause for loops with for-range over integers.
- rangeint
# Replace reflect.TypeOf(x) with TypeFor[T]().
Expand All @@ -2147,6 +2149,8 @@ linters:
- slicessort
# Use iterators instead of Len/At-style APIs.
- stditerators
# Replace strings.Index etc. with strings.Cut.
- stringscut
# Replace HasPrefix/TrimPrefix with CutPrefix.
- stringscutprefix
# Replace ranging over Split/Fields with SplitSeq/FieldsSeq.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ require (
golang.org/x/mod v0.30.0
golang.org/x/sync v0.18.0
golang.org/x/sys v0.38.0
golang.org/x/tools v0.38.0
golang.org/x/tools v0.39.0
gopkg.in/yaml.v3 v3.0.1
honnef.co/go/tools v0.6.1
mvdan.cc/gofumpt v0.9.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,13 @@
"minmax",
"newexpr",
"omitzero",
"plusbuild",
"rangeint",
"reflecttypefor",
"slicescontains",
"slicessort",
"stditerators",
"stringscut",
"stringscutprefix",
"stringsseq",
"stringsbuilder",
Expand Down
7 changes: 7 additions & 0 deletions pkg/golinters/contextcheck/contextcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package contextcheck

import (
"github.com/kkHAIKE/contextcheck"
"golang.org/x/tools/go/analysis/passes/ctrlflow"
"golang.org/x/tools/go/analysis/passes/inspect"

"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
"github.com/golangci/golangci-lint/v2/pkg/lint/linter"
)

func New() *goanalysis.Linter {
analyzer := contextcheck.NewAnalyzer(contextcheck.Configuration{})
// TODO(ldez) there is a problem with this linter:
// I think the problem related to facts.
// The BuildSSA pass has been changed inside (0.39.0):
// https://github.com/golang/tools/commit/b74c09864920a69a4d2f6ef0ecb4f9cff226893a
analyzer.Requires = append(analyzer.Requires, ctrlflow.Analyzer, inspect.Analyzer)

return goanalysis.
NewLinterFromAnalyzer(analyzer).
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
_ = reflect.TypeOf((*error)(nil)) // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(io.Reader(nil)) // nope (likely a mistake)
_ = reflect.TypeOf((*io.Reader)(nil)) // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(*new(time.Time)) // nope (false negative of noEffects)
_ = reflect.TypeOf(*new(time.Time)) // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(time.Time{}) // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(time.Duration(0)) // want "reflect.TypeOf call can be simplified using TypeFor"
)
2 changes: 1 addition & 1 deletion pkg/golinters/modernize/testdata/fix/in/slicescontains.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func assignTrueBreak(slice []int, needle int) {
print(found)
}

func assignFalseBreak(slice []int, needle int) { // TODO: treat this specially like booleanTrue
func assignFalseBreak(slice []int, needle int) {
found := true
for _, elem := range slice { // want "Loop can be simplified using slices.Contains"
if elem == needle {
Expand Down
9 changes: 0 additions & 9 deletions pkg/golinters/modernize/testdata/fix/out/forvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,28 @@ package forvar
func _(m map[int]int, s []int) {
// changed
for i := range s {
// want "copying variable is unneeded"
go f(i)
}
for _, v := range s {
// want "copying variable is unneeded"
go f(v)
}
for k, v := range m {
// want "copying variable is unneeded"
// want "copying variable is unneeded"
go f(k)
go f(v)
}
for k, v := range m {
// want "copying variable is unneeded"
// want "copying variable is unneeded"
go f(k)
go f(v)
}
for k, v := range m {
// want "copying variable is unneeded"
go f(k)
go f(v)
}
for k, v := range m {
// want "copying variable is unneeded"
go f(k)
go f(v)
}
for i := range s {
/* hi */ // want "copying variable is unneeded"
go f(i)
}
// nope
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
_ = reflect.TypeFor[*error]() // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(io.Reader(nil)) // nope (likely a mistake)
_ = reflect.TypeFor[*io.Reader]() // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeOf(*new(time.Time)) // nope (false negative of noEffects)
_ = reflect.TypeFor[time.Time]() // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeFor[time.Time]() // want "reflect.TypeOf call can be simplified using TypeFor"
_ = reflect.TypeFor[time.Duration]() // want "reflect.TypeOf call can be simplified using TypeFor"
)
7 changes: 2 additions & 5 deletions pkg/golinters/modernize/testdata/fix/out/slicescontains.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ func assignTrueBreak(slice []int, needle int) {
print(found)
}

func assignFalseBreak(slice []int, needle int) { // TODO: treat this specially like booleanTrue
found := true
if slices.Contains(slice, needle) {
found = false
}
func assignFalseBreak(slice []int, needle int) {
found := !slices.Contains(slice, needle)
print(found)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/golinters/modernize/testdata/fix/out/stditerators.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func _(scope *types.Scope) {
print(child)
}
{
const child = 0 // shadowing of preferred name at def
for child0 := range scope.Children() { // want "NumChildren/Child loop can simplified using Scope.Children iteration"
print(child0)
const child = 0 // shadowing of preferred name at def
for child := range scope.Children() { // want "NumChildren/Child loop can simplified using Scope.Children iteration"
print(child)
}
}
{
Expand Down
12 changes: 0 additions & 12 deletions pkg/golinters/modernize/testdata/fix/out/waitgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ import (
// supported case for pattern 1.
func _() {
var wg sync.WaitGroup
// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
})

// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
})

for range 10 {
// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
})
Expand All @@ -32,17 +29,14 @@ func _() {
// supported case for pattern 2.
func _() {
var wg sync.WaitGroup
// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
})

// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
})

for range 10 {
// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
})
Expand All @@ -52,19 +46,16 @@ func _() {
// this function puts some wrong usages but waitgroup modernizer will still offer fixes.
func _() {
var wg sync.WaitGroup
// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
defer wg.Done()
fmt.Println()
})

// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
wg.Done()
})

// want "Goroutine creation can be simplified using WaitGroup.Go"
wg.Go(func() {
fmt.Println()
wg.Done()
Expand Down Expand Up @@ -156,20 +147,17 @@ type ServerContainer struct {

func _() {
var s Server
// want "Goroutine creation can be simplified using WaitGroup.Go"
s.wg.Go(func() {
print()
})

var sc ServerContainer
// want "Goroutine creation can be simplified using WaitGroup.Go"
sc.serv.wg.Go(func() {
print()
})

var wg sync.WaitGroup
arr := [1]*sync.WaitGroup{&wg}
// want "Goroutine creation can be simplified using WaitGroup.Go"
arr[0].Go(func() {
print()
})
Expand Down
5 changes: 4 additions & 1 deletion test/testshared/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ func evaluateBuildTags(tb testing.TB, line string) bool {
}

func buildTagGoVersion(tag string) bool {
vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(runtime.Version(), "go"))
// `runtime.Version()` returns the go version with extra info. (ex: go1.25.1 X:nodwarf5)
before, _, _ := strings.Cut(runtime.Version(), " ")

vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(before, "go"))
if err != nil {
return false
}
Expand Down
Loading