From 54b0b9e745cf3bd29d625d14d77a0cb2bf7affe0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:28:15 +0000 Subject: [PATCH 1/3] build(deps): bump golang.org/x/tools from 0.38.0 to 0.39.0 Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.38.0 to 0.39.0. - [Release notes](https://github.com/golang/tools/releases) - [Commits](https://github.com/golang/tools/compare/v0.38.0...v0.39.0) --- updated-dependencies: - dependency-name: golang.org/x/tools dependency-version: 0.39.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 0f2a3a3e2b02..59b1f3a425e8 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5eead0910c82..8bb3d2460788 100644 --- a/go.sum +++ b/go.sum @@ -745,8 +745,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= -golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -896,8 +896,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ= -golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs= +golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ= +golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ= golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM= golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM= From acaeb67b9d6d96ded35cf79e9c402985384654e8 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 14 Nov 2025 16:22:14 +0100 Subject: [PATCH 2/3] chore: update implementation --- .golangci.next.reference.yml | 4 ++++ jsonschema/golangci.next.jsonschema.json | 2 ++ .../modernize/testdata/fix/in/reflecttypefor.go | 2 +- .../modernize/testdata/fix/in/slicescontains.go | 2 +- pkg/golinters/modernize/testdata/fix/out/forvar.go | 9 --------- .../modernize/testdata/fix/out/reflecttypefor.go | 2 +- .../modernize/testdata/fix/out/slicescontains.go | 7 ++----- .../modernize/testdata/fix/out/stditerators.go | 6 +++--- .../modernize/testdata/fix/out/waitgroup.go | 12 ------------ test/testshared/directives.go | 5 ++++- 10 files changed, 18 insertions(+), 33 deletions(-) diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index e17c9358e4d2..b973f866d2a8 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -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](). @@ -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. diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index e2f59663e363..459f5d5775da 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -717,11 +717,13 @@ "minmax", "newexpr", "omitzero", + "plusbuild", "rangeint", "reflecttypefor", "slicescontains", "slicessort", "stditerators", + "stringscut", "stringscutprefix", "stringsseq", "stringsbuilder", diff --git a/pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go b/pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go index 4214ba03f91a..7541d201324a 100644 --- a/pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go +++ b/pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go @@ -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" ) diff --git a/pkg/golinters/modernize/testdata/fix/in/slicescontains.go b/pkg/golinters/modernize/testdata/fix/in/slicescontains.go index 79b9f701d313..4731f04d4be0 100644 --- a/pkg/golinters/modernize/testdata/fix/in/slicescontains.go +++ b/pkg/golinters/modernize/testdata/fix/in/slicescontains.go @@ -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 { diff --git a/pkg/golinters/modernize/testdata/fix/out/forvar.go b/pkg/golinters/modernize/testdata/fix/out/forvar.go index b2837bab10ef..57b1c684924f 100644 --- a/pkg/golinters/modernize/testdata/fix/out/forvar.go +++ b/pkg/golinters/modernize/testdata/fix/out/forvar.go @@ -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 diff --git a/pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go b/pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go index 9791d6841bcf..0203b4148c3b 100644 --- a/pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go +++ b/pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go @@ -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" ) diff --git a/pkg/golinters/modernize/testdata/fix/out/slicescontains.go b/pkg/golinters/modernize/testdata/fix/out/slicescontains.go index 6165ced45014..0fc8f14f9946 100644 --- a/pkg/golinters/modernize/testdata/fix/out/slicescontains.go +++ b/pkg/golinters/modernize/testdata/fix/out/slicescontains.go @@ -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) } diff --git a/pkg/golinters/modernize/testdata/fix/out/stditerators.go b/pkg/golinters/modernize/testdata/fix/out/stditerators.go index 2859b265197d..5e369686ab70 100644 --- a/pkg/golinters/modernize/testdata/fix/out/stditerators.go +++ b/pkg/golinters/modernize/testdata/fix/out/stditerators.go @@ -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) } } { diff --git a/pkg/golinters/modernize/testdata/fix/out/waitgroup.go b/pkg/golinters/modernize/testdata/fix/out/waitgroup.go index 216bd19222c4..ccc3b1cd86e3 100644 --- a/pkg/golinters/modernize/testdata/fix/out/waitgroup.go +++ b/pkg/golinters/modernize/testdata/fix/out/waitgroup.go @@ -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() }) @@ -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() }) @@ -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() @@ -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() }) diff --git a/test/testshared/directives.go b/test/testshared/directives.go index a30c1f18bb29..6b8846ce0ed2 100644 --- a/test/testshared/directives.go +++ b/test/testshared/directives.go @@ -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 } From 3984aaddb229ec39bf6f8e4233732acbbd1f493c Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 15 Nov 2025 00:50:16 +0100 Subject: [PATCH 3/3] fix: contextcheck --- pkg/golinters/contextcheck/contextcheck.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/golinters/contextcheck/contextcheck.go b/pkg/golinters/contextcheck/contextcheck.go index 88c71d2d3eb2..b01df7d98917 100644 --- a/pkg/golinters/contextcheck/contextcheck.go +++ b/pkg/golinters/contextcheck/contextcheck.go @@ -2,6 +2,8 @@ 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" @@ -9,6 +11,11 @@ import ( 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).