Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 474fdaf

Browse files
authoredFeb 11, 2025··
go1.24 support (#5224)
1 parent e21ee9a commit 474fdaf

File tree

31 files changed

+94
-261
lines changed

31 files changed

+94
-261
lines changed
 

‎.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
# ex:
1717
# - 1.18beta1 -> 1.18.0-beta.1
1818
# - 1.18rc1 -> 1.18.0-rc.1
19-
GO_VERSION: '1.23'
19+
GO_VERSION: '1.24'
2020
NODE_VERSION: '20.x'
2121
CGO_ENABLED: 0
2222
steps:

‎.github/workflows/post-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
# ex:
1010
# - 1.18beta1 -> 1.18.0-beta.1
1111
# - 1.18rc1 -> 1.18.0-rc.1
12-
GO_VERSION: "1.23"
12+
GO_VERSION: '1.24'
1313

1414
jobs:
1515
update-gha-assets:

‎.github/workflows/pr-documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# ex:
1414
# - 1.18beta1 -> 1.18.0-beta.1
1515
# - 1.18rc1 -> 1.18.0-rc.1
16-
GO_VERSION: '1.23'
16+
GO_VERSION: '1.24'
1717
NODE_VERSION: '20.x'
1818
CGO_ENABLED: 0
1919

‎.github/workflows/pr.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
# ex:
1212
# - 1.18beta1 -> 1.18.0-beta.1
1313
# - 1.18rc1 -> 1.18.0-rc.1
14-
GO_VERSION: '1.23'
14+
GO_VERSION: '1.24'
1515

1616
jobs:
1717
# Check if there is any dirty change for go mod tidy
@@ -40,7 +40,9 @@ jobs:
4040
# ex:
4141
# - 1.18beta1 -> 1.18.0-beta.1
4242
# - 1.18rc1 -> 1.18.0-rc.1
43-
go-version: ${{ env.GO_VERSION }}
43+
# TODO(ldez) must be changed after the first release of golangci-lint with go1.24
44+
# go-version: ${{ env.GO_VERSION }}
45+
go-version: '1.23'
4446
- name: lint
4547
uses: golangci/golangci-lint-action@v6.3.2
4648
with:
@@ -76,8 +78,8 @@ jobs:
7678
- ubuntu-latest
7779
- ubuntu-24.04-arm
7880
golang:
79-
- '1.22'
8081
- '1.23'
82+
- '1.24'
8183
runs-on: ${{ matrix.os }}
8284
steps:
8385
- uses: actions/checkout@v4

‎.github/workflows/tag.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
# ex:
1313
# - 1.18beta1 -> 1.18.0-beta.1
1414
# - 1.18rc1 -> 1.18.0-rc.1
15-
GO_VERSION: '1.23'
15+
GO_VERSION: '1.24'
1616
CHOCOLATEY_VERSION: 2.2.0
1717
steps:
1818
# temporary workaround for an error in free disk space action

‎.golangci.next.reference.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ linters:
3131
- errchkjson
3232
- errname
3333
- errorlint
34-
- execinquery
3534
- exhaustive
3635
- exhaustruct
37-
- exportloopref
3836
- exptostd
3937
- fatcontext
4038
- forbidigo
@@ -149,10 +147,8 @@ linters:
149147
- errchkjson
150148
- errname
151149
- errorlint
152-
- execinquery
153150
- exhaustive
154151
- exhaustruct
155-
- exportloopref
156152
- exptostd
157153
- fatcontext
158154
- forbidigo
@@ -241,7 +237,9 @@ linters:
241237
- wsl
242238
- zerologlint
243239
- deadcode # Deprecated
240+
- execinquery # Deprecated
244241
- exhaustivestruct # Deprecated
242+
- exportloopref # Deprecated
245243
- golint # Deprecated
246244
- gomnd # Deprecated
247245
- ifshort # Deprecated

‎docs/src/docs/welcome/install.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,15 @@ docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:{.LatestVersion
134134

135135
### Install from Sources
136136

137-
Such `go install`/`go get` or "tools pattern" installations aren't guaranteed to work.
137+
Such `go install`/`go get`, "tools pattern", and `tool` command/directives installations aren't guaranteed to work.
138138

139139
We recommend using binary installation.
140140

141141
Those installations aren't recommended because of the following points:
142142

143143
1. Those installations are compiling golangci-lint locally, the Go version used to build will depend on your local Go version.
144144
2. Some users use `-u` flag for `go get`, which upgrades our dependencies. Resulting binary was not tested and is not guaranteed to work.
145-
3. When using "tools pattern", the dependencies of a tool can modify the dependencies of another. Resulting binary was not tested and is not guaranteed to work.
145+
3. When using "tools pattern" or and `tool` command/directives, the dependencies of a tool can modify the dependencies of another or your project. Resulting binary was not tested and is not guaranteed to work.
146146
4. We've encountered issues with Go modules hashes due to unexpected recreation of dependency tags.
147147
5. `go.mod` replacement directives don't apply transitively. It means a user will be using patched version of `golangci-lint` if we use such replacements.
148148
6. It allows installation from main branch which can't be considered stable.

‎go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/golangci/golangci-lint
22

3-
go 1.22.1
3+
go 1.23.0
44

55
require (
66
4d63.com/gocheckcompilerdirectives v1.2.1
@@ -63,7 +63,6 @@ require (
6363
github.com/kkHAIKE/contextcheck v1.1.5
6464
github.com/kulti/thelper v0.6.3
6565
github.com/kunwardeep/paralleltest v1.0.10
66-
github.com/kyoh86/exportloopref v0.1.11
6766
github.com/lasiar/canonicalheader v1.1.2
6867
github.com/ldez/exptostd v0.4.1
6968
github.com/ldez/gomoddirectives v0.6.1
@@ -126,7 +125,6 @@ require (
126125
go-simpler.org/musttag v0.13.0
127126
go-simpler.org/sloglint v0.9.0
128127
go.uber.org/automaxprocs v1.6.0
129-
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
130128
golang.org/x/mod v0.23.0
131129
golang.org/x/sys v0.30.0
132130
golang.org/x/tools v0.30.0
@@ -196,6 +194,7 @@ require (
196194
go.uber.org/atomic v1.7.0 // indirect
197195
go.uber.org/multierr v1.6.0 // indirect
198196
go.uber.org/zap v1.24.0 // indirect
197+
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
199198
golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect
200199
golang.org/x/sync v0.11.0 // indirect
201200
golang.org/x/text v0.21.0 // indirect

‎go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/cache/cache.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"encoding/hex"
77
"errors"
88
"fmt"
9+
"maps"
910
"runtime"
1011
"slices"
1112
"strings"
1213
"sync"
1314

14-
"golang.org/x/exp/maps"
1515
"golang.org/x/tools/go/packages"
1616

1717
"github.com/golangci/golangci-lint/internal/go/cache"
@@ -178,9 +178,7 @@ func (c *Cache) computePkgHash(pkg *packages.Package) (hashResults, error) {
178178
curSum := key.Sum()
179179
hashRes[HashModeNeedOnlySelf] = hex.EncodeToString(curSum[:])
180180

181-
imps := maps.Values(pkg.Imports)
182-
183-
slices.SortFunc(imps, func(a, b *packages.Package) int {
181+
imps := slices.SortedFunc(maps.Values(pkg.Imports), func(a, b *packages.Package) int {
184182
return strings.Compare(a.PkgPath, b.PkgPath)
185183
})
186184

‎jsonschema/golangci.next.jsonschema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@
351351
"errorlint",
352352
"exhaustive",
353353
"exhaustruct",
354-
"exportloopref",
355354
"exptostd",
356355
"fatcontext",
357356
"forbidigo",

‎pkg/commands/run.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"fmt"
99
"io"
1010
"log"
11+
"maps"
1112
"os"
1213
"path/filepath"
1314
"runtime"
1415
"runtime/pprof"
1516
"runtime/trace"
16-
"sort"
17+
"slices"
1718
"strconv"
1819
"strings"
1920
"time"
@@ -24,7 +25,6 @@ import (
2425
"github.com/spf13/pflag"
2526
"github.com/spf13/viper"
2627
"go.uber.org/automaxprocs/maxprocs"
27-
"golang.org/x/exp/maps"
2828
"gopkg.in/yaml.v3"
2929

3030
"github.com/golangci/golangci-lint/internal/cache"
@@ -452,8 +452,7 @@ func (c *runCommand) printStats(issues []result.Issue) {
452452

453453
c.cmd.Printf("%d issues:\n", len(issues))
454454

455-
keys := maps.Keys(stats)
456-
sort.Strings(keys)
455+
keys := slices.Sorted(maps.Keys(stats))
457456

458457
for _, key := range keys {
459458
c.cmd.Printf("* %s: %d\n", key, stats[key])

‎pkg/goanalysis/runner.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"encoding/gob"
99
"fmt"
1010
"go/token"
11+
"maps"
1112
"runtime"
12-
"sort"
13+
"slices"
1314
"sync"
1415

15-
"golang.org/x/exp/maps"
1616
"golang.org/x/tools/go/analysis"
1717
"golang.org/x/tools/go/packages"
1818

@@ -159,8 +159,8 @@ func (r *runner) buildActionFactDeps(act *action, a *analysis.Analyzer, pkg *pac
159159
act.objectFacts = make(map[objectFactKey]analysis.Fact)
160160
act.packageFacts = make(map[packageFactKey]analysis.Fact)
161161

162-
paths := maps.Keys(pkg.Imports)
163-
sort.Strings(paths) // for determinism
162+
paths := slices.Sorted(maps.Keys(pkg.Imports)) // for determinism
163+
164164
for _, path := range paths {
165165
dep := r.makeAction(a, pkg.Imports[path], initialPkgs, actions, actAlloc)
166166
act.Deps = append(act.Deps, dep)
@@ -209,7 +209,7 @@ func (r *runner) prepareAnalysis(pkgs []*packages.Package,
209209
}
210210
}
211211

212-
allActions = maps.Values(actions)
212+
allActions = slices.Collect(maps.Values(actions))
213213

214214
debugf("Built %d actions", len(actions))
215215

‎pkg/golinters/exportloopref/exportloopref.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎pkg/golinters/exportloopref/exportloopref_integration_test.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎pkg/golinters/exportloopref/testdata/exportloopref.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎pkg/golinters/exportloopref/testdata/exportloopref_cgo.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎pkg/golinters/gocritic/gocritic.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import (
55
"fmt"
66
"go/ast"
77
"go/types"
8+
"maps"
89
"reflect"
910
"runtime"
1011
"slices"
11-
"sort"
1212
"strings"
1313
"sync"
1414

1515
"github.com/go-critic/go-critic/checkers"
1616
gocriticlinter "github.com/go-critic/go-critic/linter"
1717
_ "github.com/quasilyte/go-ruleguard/dsl"
18-
"golang.org/x/exp/maps"
1918
"golang.org/x/tools/go/analysis"
2019

2120
"github.com/golangci/golangci-lint/pkg/config"
@@ -168,8 +167,7 @@ func (w *goCriticWrapper) configureCheckerInfo(
168167
info.Name, k)
169168
}
170169

171-
supportedKeys := maps.Keys(info.Params)
172-
sort.Strings(supportedKeys)
170+
supportedKeys := slices.Sorted(maps.Keys(info.Params))
173171

174172
return fmt.Errorf("checker %s config param %s doesn't exist, all existing: %s",
175173
info.Name, k, supportedKeys)
@@ -270,8 +268,7 @@ func newSettingsWrapper(settings *config.GoCriticSettings, logger logutils.Log)
270268
}
271269
}
272270

273-
allTagsSorted := maps.Keys(allChecksByTag)
274-
sort.Strings(allTagsSorted)
271+
allTagsSorted := slices.Sorted(maps.Keys(allChecksByTag))
275272

276273
return &settingsWrapper{
277274
GoCriticSettings: settings,
@@ -558,8 +555,7 @@ func debugChecksListf(checks []string, format string, args ...any) {
558555
return
559556
}
560557

561-
v := slices.Clone(checks)
562-
slices.Sort(v)
558+
v := slices.Sorted(slices.Values(checks))
563559

564560
debugf("%s checks (%d): %s", fmt.Sprintf(format, args...), len(checks), strings.Join(v, ", "))
565561
}

‎pkg/golinters/gocritic/gocritic_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gocritic
22

33
import (
4+
"maps"
45
"slices"
56
"strings"
67
"testing"
@@ -9,7 +10,6 @@ import (
910
gocriticlinter "github.com/go-critic/go-critic/linter"
1011
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
12-
"golang.org/x/exp/maps"
1313

1414
"github.com/golangci/golangci-lint/pkg/config"
1515
"github.com/golangci/golangci-lint/pkg/logutils"
@@ -40,7 +40,7 @@ func Test_settingsWrapper_InferEnabledChecks(t *testing.T) {
4040
t.Logf("enabled by default checks:\n%s", strings.Join(enabledByDefaultChecks, "\n"))
4141

4242
insert := func(in []string, toInsert ...string) []string {
43-
return append(slices.Clone(in), toInsert...)
43+
return slices.Concat(in, toInsert)
4444
}
4545

4646
remove := func(in []string, toRemove ...string) []string {
@@ -54,9 +54,7 @@ func Test_settingsWrapper_InferEnabledChecks(t *testing.T) {
5454
}
5555

5656
uniq := func(in []string) []string {
57-
result := slices.Clone(in)
58-
slices.Sort(result)
59-
return slices.Compact(result)
57+
return slices.Compact(slices.Sorted(slices.Values(in)))
6058
}
6159

6260
cases := []struct {
@@ -269,7 +267,7 @@ func Test_settingsWrapper_InferEnabledChecks(t *testing.T) {
269267
wr := newSettingsWrapper(tt.sett, lg)
270268

271269
wr.InferEnabledChecks()
272-
assert.ElementsMatch(t, tt.expectedEnabledChecks, maps.Keys(wr.inferredEnabledChecks))
270+
assert.ElementsMatch(t, tt.expectedEnabledChecks, slices.Collect(maps.Keys(wr.inferredEnabledChecks)))
273271
assert.NoError(t, wr.Validate())
274272
})
275273
}

‎pkg/golinters/govet/testdata/govet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func GovetComposites() error {
12-
return &os.PathError{"first", "path", os.ErrNotExist} // want "composites: io/fs\\.PathError struct literal uses unkeyed fields"
12+
return &os.PathError{"first", "path", os.ErrNotExist} // want "composites: (os|io/fs)\\.PathError struct literal uses unkeyed fields"
1313
}
1414

1515
func GovetShadow(f io.Reader, buf []byte) (err error) {

‎pkg/golinters/thelper/thelper.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package thelper
22

33
import (
4+
"maps"
5+
"slices"
46
"strings"
57

68
"github.com/kulti/thelper/pkg/analyzer"
7-
"golang.org/x/exp/maps"
89
"golang.org/x/tools/go/analysis"
910

1011
"github.com/golangci/golangci-lint/pkg/config"
@@ -44,7 +45,7 @@ func New(settings *config.ThelperSettings) *goanalysis.Linter {
4445
internal.LinterLogger.Fatalf("thelper: at least one option must be enabled")
4546
}
4647

47-
args := maps.Keys(opts)
48+
args := slices.Collect(maps.Keys(opts))
4849

4950
cfg := map[string]map[string]any{
5051
a.Name: {

‎pkg/golinters/usetesting/testdata/usetesting_go124.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Test_osMkdirTemp(t *testing.T) {
2626
}
2727

2828
func Test_osSetenv(t *testing.T) {
29-
os.Setenv("", "")
29+
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
3030
}
3131

3232
func Test_osTempDir(t *testing.T) {

‎pkg/lint/linter/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ func IsGoLowerThanGo122() func(cfg *config.Config) error {
167167
return isGoLowerThanGo("1.22")
168168
}
169169

170-
func IsGoLowerThanGo124() func(cfg *config.Config) error {
171-
return isGoLowerThanGo("1.24")
172-
}
173-
174170
func isGoLowerThanGo(v string) func(cfg *config.Config) error {
175171
return func(cfg *config.Config) error {
176172
if cfg == nil || config.IsGoGreaterThanOrEqual(cfg.Run.Go, v) {

‎pkg/lint/lintersdb/builder_linter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/golangci/golangci-lint/pkg/golinters/errorlint"
2626
"github.com/golangci/golangci-lint/pkg/golinters/exhaustive"
2727
"github.com/golangci/golangci-lint/pkg/golinters/exhaustruct"
28-
"github.com/golangci/golangci-lint/pkg/golinters/exportloopref"
2928
"github.com/golangci/golangci-lint/pkg/golinters/exptostd"
3029
"github.com/golangci/golangci-lint/pkg/golinters/fatcontext"
3130
"github.com/golangci/golangci-lint/pkg/golinters/forbidigo"
@@ -278,12 +277,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
278277
WithLoadForGoAnalysis().
279278
WithURL("https://github.com/GaijinEntertainment/go-exhaustruct"),
280279

281-
linter.NewConfig(exportloopref.New()).
280+
linter.NewConfig(linter.NewNoopDeprecated("exportloopref", cfg, linter.DeprecationError)).
282281
WithSince("v1.28.0").
283282
WithPresets(linter.PresetBugs).
284283
WithLoadForGoAnalysis().
285284
WithURL("https://github.com/kyoh86/exportloopref").
286-
DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"),
285+
DeprecatedError("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"),
287286

288287
linter.NewConfig(exptostd.New()).
289288
WithSince("v1.63.0").

‎pkg/lint/lintersdb/manager.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package lintersdb
22

33
import (
44
"fmt"
5+
"maps"
56
"os"
67
"slices"
78
"sort"
8-
9-
"golang.org/x/exp/maps"
9+
"strings"
1010

1111
"github.com/golangci/golangci-lint/pkg/config"
1212
"github.com/golangci/golangci-lint/pkg/goanalysis"
@@ -109,24 +109,25 @@ func (m *Manager) GetOptimizedLinters() ([]*linter.Config, error) {
109109

110110
m.combineGoAnalysisLinters(resultLintersSet)
111111

112-
resultLinters := maps.Values(resultLintersSet)
113-
114112
// Make order of execution of linters (go/analysis metalinter and unused) stable.
115-
sort.Slice(resultLinters, func(i, j int) bool {
116-
a, b := resultLinters[i], resultLinters[j]
117-
113+
resultLinters := slices.SortedFunc(maps.Values(resultLintersSet), func(a *linter.Config, b *linter.Config) int {
118114
if b.Name() == linter.LastLinter {
119-
return true
115+
return -1
120116
}
121117

122118
if a.Name() == linter.LastLinter {
123-
return false
119+
return 1
124120
}
125121

126122
if a.DoesChangeTypes != b.DoesChangeTypes {
127-
return b.DoesChangeTypes // move type-changing linters to the end to optimize speed
123+
// move type-changing linters to the end to optimize speed
124+
if b.DoesChangeTypes {
125+
return -1
126+
}
127+
return 1
128128
}
129-
return a.Name() < b.Name()
129+
130+
return strings.Compare(a.Name(), b.Name())
130131
})
131132

132133
return resultLinters, nil

‎pkg/printers/checkstyle.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/xml"
55
"fmt"
66
"io"
7-
"sort"
7+
"maps"
8+
"slices"
9+
"strings"
810

911
"github.com/go-xmlfmt/xmlfmt"
10-
"golang.org/x/exp/maps"
1112

1213
"github.com/golangci/golangci-lint/pkg/logutils"
1314
"github.com/golangci/golangci-lint/pkg/result"
@@ -70,10 +71,8 @@ func (p *Checkstyle) Print(issues []result.Issue) error {
7071
p.log.Infof("%v", err)
7172
}
7273

73-
out.Files = maps.Values(files)
74-
75-
sort.Slice(out.Files, func(i, j int) bool {
76-
return out.Files[i].Name < out.Files[j].Name
74+
out.Files = slices.SortedFunc(maps.Values(files), func(a *checkstyleFile, b *checkstyleFile) int {
75+
return strings.Compare(a.Name, b.Name)
7776
})
7877

7978
data, err := xml.Marshal(&out)

‎pkg/printers/junitxml.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"encoding/xml"
55
"fmt"
66
"io"
7-
"sort"
7+
"maps"
8+
"slices"
89
"strings"
910

10-
"golang.org/x/exp/maps"
11-
1211
"github.com/golangci/golangci-lint/pkg/result"
1312
)
1413

@@ -60,10 +59,9 @@ func (p JUnitXML) Print(issues []result.Issue) error {
6059
}
6160

6261
var res testSuitesXML
63-
res.TestSuites = maps.Values(suites)
6462

65-
sort.Slice(res.TestSuites, func(i, j int) bool {
66-
return res.TestSuites[i].Suite < res.TestSuites[j].Suite
63+
res.TestSuites = slices.SortedFunc(maps.Values(suites), func(a testSuiteXML, b testSuiteXML) int {
64+
return strings.Compare(a.Suite, b.Suite)
6765
})
6866

6967
enc := xml.NewEncoder(p.w)

‎pkg/result/processors/fixer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ package processors
99
import (
1010
"errors"
1111
"fmt"
12+
"maps"
1213
"os"
1314
"slices"
1415

15-
"golang.org/x/exp/maps"
16-
1716
"github.com/golangci/golangci-lint/internal/x/tools/diff"
1817
"github.com/golangci/golangci-lint/pkg/config"
1918
"github.com/golangci/golangci-lint/pkg/fsutils"
@@ -126,7 +125,7 @@ func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) {
126125
for path, linterToEdits := range editsByLinter {
127126
excludedLinters := make(map[string]struct{})
128127

129-
linters := maps.Keys(linterToEdits)
128+
linters := slices.Collect(maps.Keys(linterToEdits))
130129

131130
// Does any linter create conflicting edits?
132131
for _, linter := range linters {

‎pkg/result/processors/nolint_filter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"go/ast"
55
"go/parser"
66
"go/token"
7+
"maps"
78
"regexp"
9+
"slices"
810
"sort"
911
"strings"
1012

11-
"golang.org/x/exp/maps"
12-
1313
"github.com/golangci/golangci-lint/pkg/golinters/nolintlint"
1414
"github.com/golangci/golangci-lint/pkg/lint/linter"
1515
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
@@ -102,8 +102,7 @@ func (p *NolintFilter) Finish() {
102102
return
103103
}
104104

105-
unknownLinters := maps.Keys(p.unknownLintersSet)
106-
sort.Strings(unknownLinters)
105+
unknownLinters := slices.Sorted(maps.Keys(p.unknownLintersSet))
107106

108107
p.log.Warnf("Found unknown linters in //nolint directives: %s", strings.Join(unknownLinters, ", "))
109108
}

‎scripts/website/copy_jsonschema/main.go

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"path/filepath"
9-
"strings"
109

1110
hcversion "github.com/hashicorp/go-version"
1211

@@ -28,25 +27,21 @@ func copySchemas() error {
2827
return fmt.Errorf("remove dir: %w", err)
2928
}
3029

31-
err = os.MkdirAll(dstDir, os.ModePerm)
30+
err = os.CopyFS(dstDir, os.DirFS("jsonschema"))
3231
if err != nil {
33-
return fmt.Errorf("make dir: %w", err)
32+
return fmt.Errorf("copy FS: %w", err)
3433
}
3534

36-
// The key is the destination file.
37-
// The value is the source file.
38-
files := map[string]string{}
39-
40-
entries, err := os.ReadDir("jsonschema")
35+
err = copyLatestSchema()
4136
if err != nil {
42-
return fmt.Errorf("read dir: %w", err)
37+
return fmt.Errorf("copy files: %w", err)
4338
}
4439

45-
for _, entry := range entries {
46-
if strings.HasSuffix(entry.Name(), ".jsonschema.json") {
47-
files[entry.Name()] = entry.Name()
48-
}
49-
}
40+
return nil
41+
}
42+
43+
func copyLatestSchema() error {
44+
src := filepath.FromSlash("jsonschema/golangci.jsonschema.json")
5045

5146
latest, err := github.GetLatestVersion()
5247
if err != nil {
@@ -58,20 +53,11 @@ func copySchemas() error {
5853
return fmt.Errorf("parse version: %w", err)
5954
}
6055

61-
versioned := fmt.Sprintf("golangci.v%d.%d.jsonschema.json", version.Segments()[0], version.Segments()[1])
62-
files[versioned] = "golangci.jsonschema.json"
63-
64-
for dst, src := range files {
65-
err := copyFile(filepath.Join("jsonschema", src), filepath.Join(dstDir, dst))
66-
if err != nil {
67-
return fmt.Errorf("copy files: %w", err)
68-
}
56+
files := []string{
57+
fmt.Sprintf("golangci.v%d.jsonschema.json", version.Segments()[0]),
58+
fmt.Sprintf("golangci.v%d.%d.jsonschema.json", version.Segments()[0], version.Segments()[1]),
6959
}
7060

71-
return nil
72-
}
73-
74-
func copyFile(src, dst string) error {
7561
source, err := os.Open(src)
7662
if err != nil {
7763
return fmt.Errorf("open file %s: %w", src, err)
@@ -84,6 +70,17 @@ func copyFile(src, dst string) error {
8470
return fmt.Errorf("file %s not found: %w", src, err)
8571
}
8672

73+
for _, dst := range files {
74+
err = copyFile(dst, source, info)
75+
if err != nil {
76+
return fmt.Errorf("copy file %s to %s: %w", src, dst, err)
77+
}
78+
}
79+
80+
return nil
81+
}
82+
83+
func copyFile(dst string, source io.Reader, info os.FileInfo) error {
8784
destination, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())
8885
if err != nil {
8986
return fmt.Errorf("create file %s: %w", dst, err)
@@ -93,7 +90,7 @@ func copyFile(src, dst string) error {
9390

9491
_, err = io.Copy(destination, source)
9592
if err != nil {
96-
return fmt.Errorf("copy file %s to %s: %w", src, dst, err)
93+
return err
9794
}
9895

9996
return nil

‎scripts/website/expand_templates/thanks.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package main
22

33
import (
44
"fmt"
5-
"sort"
5+
"maps"
6+
"slices"
67
"strings"
78

8-
"golang.org/x/exp/maps"
9-
109
"github.com/golangci/golangci-lint/pkg/config"
1110
"github.com/golangci/golangci-lint/pkg/lint/linter"
1211
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
@@ -69,9 +68,8 @@ func getThanksList() string {
6968
}
7069
}
7170

72-
authors := maps.Keys(addedAuthors)
73-
sort.Slice(authors, func(i, j int) bool {
74-
return strings.ToLower(authors[i]) < strings.ToLower(authors[j])
71+
authors := slices.SortedFunc(maps.Keys(addedAuthors), func(a string, b string) int {
72+
return strings.Compare(strings.ToLower(a), strings.ToLower(b))
7573
})
7674

7775
lines := []string{

0 commit comments

Comments
 (0)
Please sign in to comment.