Skip to content

Commit 3d603f2

Browse files
committed
chore: update implementation
1 parent 54b0b9e commit 3d603f2

File tree

10 files changed

+54
-69
lines changed

10 files changed

+54
-69
lines changed

.golangci.next.reference.yml

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,42 +2121,46 @@ linters:
21212121
# List of analyzers to disable.
21222122
# By default, all analyzers are enabled.
21232123
disable:
2124-
# Replace interface{} with any.
2125-
- any
2126-
# Replace for-range over b.N with b.Loop.
2127-
- bloop
2128-
# Replace []byte(fmt.Sprintf) with fmt.Appendf.
2129-
- fmtappendf
2130-
# Remove redundant re-declaration of loop variables.
2131-
- forvar
2132-
# Replace explicit loops over maps with calls to maps package.
2133-
- mapsloop
2134-
# Replace if/else statements with calls to min or max.
2135-
- minmax
2136-
# Simplify code by using go1.26's new(expr).
2137-
- newexpr
2138-
# Suggest replacing omitempty with omitzero for struct fields.
2139-
- omitzero
2140-
# Replace 3-clause for loops with for-range over integers.
2141-
- rangeint
2142-
# Replace reflect.TypeOf(x) with TypeFor[T]().
2143-
- reflecttypefor
2144-
# Replace loops with slices.Contains or slices.ContainsFunc.
2145-
- slicescontains
2146-
# Replace sort.Slice with slices.Sort for basic types.
2147-
- slicessort
2148-
# Use iterators instead of Len/At-style APIs.
2149-
- stditerators
2150-
# Replace HasPrefix/TrimPrefix with CutPrefix.
2151-
- stringscutprefix
2152-
# Replace ranging over Split/Fields with SplitSeq/FieldsSeq.
2153-
- stringsseq
2154-
# Replace += with strings.Builder.
2155-
- stringsbuilder
2156-
# Replace context.WithCancel with t.Context in tests.
2157-
- testingcontext
2158-
# Replace wg.Add(1)/go/wg.Done() with wg.Go.
2159-
- waitgroup
2124+
# Replace interface{} with any.
2125+
- any
2126+
# Replace for-range over b.N with b.Loop.
2127+
- bloop
2128+
# Replace []byte(fmt.Sprintf) with fmt.Appendf.
2129+
- fmtappendf
2130+
# Remove redundant re-declaration of loop variables.
2131+
- forvar
2132+
# Replace explicit loops over maps with calls to maps package.
2133+
- mapsloop
2134+
# Replace if/else statements with calls to min or max.
2135+
- minmax
2136+
# Simplify code by using go1.26's new(expr).
2137+
- newexpr
2138+
# Suggest replacing omitempty with omitzero for struct fields.
2139+
- omitzero
2140+
# Remove obsolete //+build comments.
2141+
- plusbuild
2142+
# Replace 3-clause for loops with for-range over integers.
2143+
- rangeint
2144+
# Replace reflect.TypeOf(x) with TypeFor[T]().
2145+
- reflecttypefor
2146+
# Replace loops with slices.Contains or slices.ContainsFunc.
2147+
- slicescontains
2148+
# Replace sort.Slice with slices.Sort for basic types.
2149+
- slicessort
2150+
# Use iterators instead of Len/At-style APIs.
2151+
- stditerators
2152+
# Replace strings.Index etc. with strings.Cut.
2153+
- stringscut
2154+
# Replace HasPrefix/TrimPrefix with CutPrefix.
2155+
- stringscutprefix
2156+
# Replace ranging over Split/Fields with SplitSeq/FieldsSeq.
2157+
- stringsseq
2158+
# Replace += with strings.Builder.
2159+
- stringsbuilder
2160+
# Replace context.WithCancel with t.Context in tests.
2161+
- testingcontext
2162+
# Replace wg.Add(1)/go/wg.Done() with wg.Go.
2163+
- waitgroup
21602164

21612165
musttag:
21622166
# A set of custom functions to check in addition to the builtin ones.

jsonschema/golangci.next.jsonschema.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,13 @@
717717
"minmax",
718718
"newexpr",
719719
"omitzero",
720+
"plusbuild",
720721
"rangeint",
721722
"reflecttypefor",
722723
"slicescontains",
723724
"slicessort",
724725
"stditerators",
726+
"stringscut",
725727
"stringscutprefix",
726728
"stringsseq",
727729
"stringsbuilder",

pkg/golinters/modernize/testdata/fix/in/reflecttypefor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
_ = reflect.TypeOf((*error)(nil)) // want "reflect.TypeOf call can be simplified using TypeFor"
1818
_ = reflect.TypeOf(io.Reader(nil)) // nope (likely a mistake)
1919
_ = reflect.TypeOf((*io.Reader)(nil)) // want "reflect.TypeOf call can be simplified using TypeFor"
20-
_ = reflect.TypeOf(*new(time.Time)) // nope (false negative of noEffects)
20+
_ = reflect.TypeOf(*new(time.Time)) // want "reflect.TypeOf call can be simplified using TypeFor"
2121
_ = reflect.TypeOf(time.Time{}) // want "reflect.TypeOf call can be simplified using TypeFor"
2222
_ = reflect.TypeOf(time.Duration(0)) // want "reflect.TypeOf call can be simplified using TypeFor"
2323
)

pkg/golinters/modernize/testdata/fix/in/slicescontains.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func assignTrueBreak(slice []int, needle int) {
5252
print(found)
5353
}
5454

55-
func assignFalseBreak(slice []int, needle int) { // TODO: treat this specially like booleanTrue
55+
func assignFalseBreak(slice []int, needle int) {
5656
found := true
5757
for _, elem := range slice { // want "Loop can be simplified using slices.Contains"
5858
if elem == needle {

pkg/golinters/modernize/testdata/fix/out/forvar.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,28 @@ package forvar
55
func _(m map[int]int, s []int) {
66
// changed
77
for i := range s {
8-
// want "copying variable is unneeded"
98
go f(i)
109
}
1110
for _, v := range s {
12-
// want "copying variable is unneeded"
1311
go f(v)
1412
}
1513
for k, v := range m {
16-
// want "copying variable is unneeded"
17-
// want "copying variable is unneeded"
1814
go f(k)
1915
go f(v)
2016
}
2117
for k, v := range m {
22-
// want "copying variable is unneeded"
23-
// want "copying variable is unneeded"
2418
go f(k)
2519
go f(v)
2620
}
2721
for k, v := range m {
28-
// want "copying variable is unneeded"
2922
go f(k)
3023
go f(v)
3124
}
3225
for k, v := range m {
33-
// want "copying variable is unneeded"
3426
go f(k)
3527
go f(v)
3628
}
3729
for i := range s {
38-
/* hi */ // want "copying variable is unneeded"
3930
go f(i)
4031
}
4132
// nope

pkg/golinters/modernize/testdata/fix/out/reflecttypefor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
_ = reflect.TypeFor[*error]() // want "reflect.TypeOf call can be simplified using TypeFor"
1818
_ = reflect.TypeOf(io.Reader(nil)) // nope (likely a mistake)
1919
_ = reflect.TypeFor[*io.Reader]() // want "reflect.TypeOf call can be simplified using TypeFor"
20-
_ = reflect.TypeOf(*new(time.Time)) // nope (false negative of noEffects)
20+
_ = reflect.TypeFor[time.Time]() // want "reflect.TypeOf call can be simplified using TypeFor"
2121
_ = reflect.TypeFor[time.Time]() // want "reflect.TypeOf call can be simplified using TypeFor"
2222
_ = reflect.TypeFor[time.Duration]() // want "reflect.TypeOf call can be simplified using TypeFor"
2323
)

pkg/golinters/modernize/testdata/fix/out/slicescontains.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ func assignTrueBreak(slice []int, needle int) {
3838
print(found)
3939
}
4040

41-
func assignFalseBreak(slice []int, needle int) { // TODO: treat this specially like booleanTrue
42-
found := true
43-
if slices.Contains(slice, needle) {
44-
found = false
45-
}
41+
func assignFalseBreak(slice []int, needle int) {
42+
found := !slices.Contains(slice, needle)
4643
print(found)
4744
}
4845

pkg/golinters/modernize/testdata/fix/out/stditerators.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func _(scope *types.Scope) {
1515
print(child)
1616
}
1717
{
18-
const child = 0 // shadowing of preferred name at def
19-
for child0 := range scope.Children() { // want "NumChildren/Child loop can simplified using Scope.Children iteration"
20-
print(child0)
18+
const child = 0 // shadowing of preferred name at def
19+
for child := range scope.Children() { // want "NumChildren/Child loop can simplified using Scope.Children iteration"
20+
print(child)
2121
}
2222
}
2323
{

pkg/golinters/modernize/testdata/fix/out/waitgroup.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ import (
1212
// supported case for pattern 1.
1313
func _() {
1414
var wg sync.WaitGroup
15-
// want "Goroutine creation can be simplified using WaitGroup.Go"
1615
wg.Go(func() {
1716
fmt.Println()
1817
})
1918

20-
// want "Goroutine creation can be simplified using WaitGroup.Go"
2119
wg.Go(func() {
2220
})
2321

2422
for range 10 {
25-
// want "Goroutine creation can be simplified using WaitGroup.Go"
2623
wg.Go(func() {
2724
fmt.Println()
2825
})
@@ -32,17 +29,14 @@ func _() {
3229
// supported case for pattern 2.
3330
func _() {
3431
var wg sync.WaitGroup
35-
// want "Goroutine creation can be simplified using WaitGroup.Go"
3632
wg.Go(func() {
3733
fmt.Println()
3834
})
3935

40-
// want "Goroutine creation can be simplified using WaitGroup.Go"
4136
wg.Go(func() {
4237
})
4338

4439
for range 10 {
45-
// want "Goroutine creation can be simplified using WaitGroup.Go"
4640
wg.Go(func() {
4741
fmt.Println()
4842
})
@@ -52,19 +46,16 @@ func _() {
5246
// this function puts some wrong usages but waitgroup modernizer will still offer fixes.
5347
func _() {
5448
var wg sync.WaitGroup
55-
// want "Goroutine creation can be simplified using WaitGroup.Go"
5649
wg.Go(func() {
5750
defer wg.Done()
5851
fmt.Println()
5952
})
6053

61-
// want "Goroutine creation can be simplified using WaitGroup.Go"
6254
wg.Go(func() {
6355
fmt.Println()
6456
wg.Done()
6557
})
6658

67-
// want "Goroutine creation can be simplified using WaitGroup.Go"
6859
wg.Go(func() {
6960
fmt.Println()
7061
wg.Done()
@@ -156,20 +147,17 @@ type ServerContainer struct {
156147

157148
func _() {
158149
var s Server
159-
// want "Goroutine creation can be simplified using WaitGroup.Go"
160150
s.wg.Go(func() {
161151
print()
162152
})
163153

164154
var sc ServerContainer
165-
// want "Goroutine creation can be simplified using WaitGroup.Go"
166155
sc.serv.wg.Go(func() {
167156
print()
168157
})
169158

170159
var wg sync.WaitGroup
171160
arr := [1]*sync.WaitGroup{&wg}
172-
// want "Goroutine creation can be simplified using WaitGroup.Go"
173161
arr[0].Go(func() {
174162
print()
175163
})

test/testshared/directives.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ func evaluateBuildTags(tb testing.TB, line string) bool {
149149
}
150150

151151
func buildTagGoVersion(tag string) bool {
152-
vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(runtime.Version(), "go"))
152+
// `runtime.Version()` returns the go version with extra info. (ex: go1.25.1 X:nodwarf5)
153+
before, _, _ := strings.Cut(runtime.Version(), " ")
154+
155+
vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(before, "go"))
153156
if err != nil {
154157
return false
155158
}

0 commit comments

Comments
 (0)