Skip to content

Commit 1495ecc

Browse files
committed
chore: use new language elements
1 parent 6c966ef commit 1495ecc

File tree

7 files changed

+44
-63
lines changed

7 files changed

+44
-63
lines changed

pkg/commands/internal/migrate/versionone/output.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ type OutputFormat struct {
2424
type OutputFormats []OutputFormat
2525

2626
func (p *OutputFormats) UnmarshalText(text []byte) error {
27-
formats := strings.Split(string(text), ",")
28-
29-
for _, item := range formats {
27+
for item := range strings.SplitSeq(string(text), ",") {
3028
format, path, _ := strings.Cut(item, ":")
3129

3230
*p = append(*p, OutputFormat{

pkg/goutil/version.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ func CleanRuntimeVersion() (string, error) {
6060
}
6161

6262
func cleanRuntimeVersion(rv string) (string, error) {
63-
parts := strings.Fields(rv)
64-
65-
for _, part := range parts {
63+
for part := range strings.FieldsSeq(rv) {
6664
// Allow to handle:
6765
// - GOEXPERIMENT -> "go1.23.0 X:boringcrypto"
6866
// - devel -> "devel go1.24-e705a2d Wed Aug 7 01:16:42 2024 +0000 linux/amd64"

pkg/logutils/logutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func getEnabledDebugs() map[string]bool {
9494
return ret
9595
}
9696

97-
for _, tag := range strings.Split(debugVar, ",") {
97+
for tag := range strings.SplitSeq(debugVar, ",") {
9898
ret[tag] = true
9999
}
100100

pkg/result/processors/nolint_filter.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,12 @@ func (p *NolintFilter) extractInlineRangeFromComment(text string, g ast.Node, fs
227227
return buildRange(nil) // ignore all linters
228228
}
229229

230+
text = strings.Split(text, "//")[0] // allow another comment after this comment
231+
230232
// ignore specific linters
231233
var linters []string
232-
text = strings.Split(text, "//")[0] // allow another comment after this comment
233-
linterItems := strings.Split(strings.TrimPrefix(text, "nolint:"), ",")
234-
for _, item := range linterItems {
234+
235+
for item := range strings.SplitSeq(strings.TrimPrefix(text, "nolint:"), ",") {
235236
linterName := strings.ToLower(strings.TrimSpace(item))
236237
if linterName == "all" {
237238
p.unknownLintersSet = map[string]bool{}

scripts/gen_github_action_config/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,9 @@ func parseVersion(s string) (*version, error) {
219219
return nil, fmt.Errorf("version %q should start with %q", s, vPrefix)
220220
}
221221

222-
parts := strings.Split(strings.TrimPrefix(s, vPrefix), ".")
223-
224222
var nums []int
225-
for _, part := range parts {
223+
224+
for part := range strings.SplitSeq(strings.TrimPrefix(s, vPrefix), ".") {
226225
num, err := strconv.Atoi(part)
227226
if err != nil {
228227
return nil, fmt.Errorf("failed to parse version %q: %w", s, err)

test/bench/bench_test.go

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,6 @@ type metrics struct {
3535
}
3636

3737
func Benchmark_linters(b *testing.B) {
38-
savedWD, err := os.Getwd()
39-
require.NoError(b, err)
40-
41-
b.Cleanup(func() {
42-
// Restore WD to avoid side effects when during all the benchmarks.
43-
err = os.Chdir(savedWD)
44-
require.NoError(b, err)
45-
})
46-
4738
installGolangCILint(b)
4839

4940
repos := getAllRepositories(b)
@@ -65,8 +56,7 @@ func Benchmark_linters(b *testing.B) {
6556
b.Run(repo.name, func(b *testing.B) {
6657
_ = exec.Command(binName, "cache", "clean").Run()
6758

68-
err = os.Chdir(repo.dir)
69-
require.NoErrorf(b, err, "can't chdir to %s", repo.dir)
59+
b.Chdir(repo.dir)
7060

7161
lc := countGoLines(b)
7262

@@ -83,15 +73,6 @@ func Benchmark_linters(b *testing.B) {
8373
}
8474

8575
func Benchmark_golangciLint(b *testing.B) {
86-
savedWD, err := os.Getwd()
87-
require.NoError(b, err)
88-
89-
b.Cleanup(func() {
90-
// Restore WD to avoid side effects when during all the benchmarks.
91-
err = os.Chdir(savedWD)
92-
require.NoError(b, err)
93-
})
94-
9576
installGolangCILint(b)
9677

9778
_ = exec.Command(binName, "cache", "clean").Run()
@@ -114,8 +95,7 @@ func Benchmark_golangciLint(b *testing.B) {
11495

11596
for _, c := range cases {
11697
b.Run(c.name, func(b *testing.B) {
117-
err = os.Chdir(c.dir)
118-
require.NoErrorf(b, err, "can't chdir to %s", c.dir)
98+
b.Chdir(c.dir)
11999

120100
lc := countGoLines(b)
121101

@@ -142,26 +122,26 @@ func getAllRepositories(tb testing.TB) []repo {
142122
name: "golangci/golangci-lint",
143123
dir: cloneGithubProject(tb, benchRoot, "golangci", "golangci-lint"),
144124
},
145-
{
146-
name: "goreleaser/goreleaser",
147-
dir: cloneGithubProject(tb, benchRoot, "goreleaser", "goreleaser"),
148-
},
149-
{
150-
name: "gohugoio/hugo",
151-
dir: cloneGithubProject(tb, benchRoot, "gohugoio", "hugo"),
152-
},
153-
{
154-
name: "pact-foundation/pact-go", // CGO inside
155-
dir: cloneGithubProject(tb, benchRoot, "pact-foundation", "pact-go"),
156-
},
157-
{
158-
name: "kubernetes/kubernetes",
159-
dir: cloneGithubProject(tb, benchRoot, "kubernetes", "kubernetes"),
160-
},
161-
{
162-
name: "moby/buildkit",
163-
dir: cloneGithubProject(tb, benchRoot, "moby", "buildkit"),
164-
},
125+
// {
126+
// name: "goreleaser/goreleaser",
127+
// dir: cloneGithubProject(tb, benchRoot, "goreleaser", "goreleaser"),
128+
// },
129+
// {
130+
// name: "gohugoio/hugo",
131+
// dir: cloneGithubProject(tb, benchRoot, "gohugoio", "hugo"),
132+
// },
133+
// {
134+
// name: "pact-foundation/pact-go", // CGO inside
135+
// dir: cloneGithubProject(tb, benchRoot, "pact-foundation", "pact-go"),
136+
// },
137+
// {
138+
// name: "kubernetes/kubernetes",
139+
// dir: cloneGithubProject(tb, benchRoot, "kubernetes", "kubernetes"),
140+
// },
141+
// {
142+
// name: "moby/buildkit",
143+
// dir: cloneGithubProject(tb, benchRoot, "moby", "buildkit"),
144+
// },
165145
{
166146
name: "go source code",
167147
dir: filepath.Join(build.Default.GOROOT, "src"),
@@ -392,7 +372,14 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
392372
tb.Helper()
393373

394374
// add linter names here if needed.
395-
var excluded []string
375+
excluded := []string{
376+
"gci", // Formatter
377+
"gofmt", // Formatter
378+
"gofumpt", // Formatter
379+
"goimports", // Formatter
380+
"golines", // Formatter
381+
"swaggo", // Formatter
382+
}
396383

397384
linters, err := lintersdb.NewLinterBuilder().Build(config.NewDefault())
398385
require.NoError(tb, err)
@@ -403,6 +390,10 @@ func getLinterNames(tb testing.TB, fastOnly bool) []string {
403390
continue
404391
}
405392

393+
if lc.Internal {
394+
continue
395+
}
396+
406397
if fastOnly && lc.IsSlowLinter() {
407398
continue
408399
}

test/testshared/integration/run.go

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

33
import (
4-
"os"
54
"os/exec"
65
"path/filepath"
76
"slices"
@@ -32,12 +31,7 @@ func RunTestSourcesFromDir(t *testing.T, dir string) {
3231

3332
binPath := testshared.InstallGolangciLint(t)
3433

35-
cwd, err := os.Getwd()
36-
require.NoError(t, err)
37-
t.Cleanup(func() { _ = os.Chdir(cwd) })
38-
39-
err = os.Chdir(dir)
40-
require.NoError(t, err)
34+
t.Chdir(dir)
4135

4236
log := logutils.NewStderrLog(logutils.DebugKeyTest)
4337
log.SetLevel(logutils.LogLevelInfo)

0 commit comments

Comments
 (0)