Skip to content

Commit c411ec4

Browse files
committed
Clear is better than clever. https://go-proverbs.github.io/
1 parent 1eeea0b commit c411ec4

File tree

3 files changed

+5
-122
lines changed

3 files changed

+5
-122
lines changed

test/run_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ func TestCgoOk(t *testing.T) {
137137
"--enable-all",
138138
"-D",
139139
"nosnakecase",
140+
"--go=1.22", // TODO(ldez) remove this line when we will run go1.23 on the CI. (related to intrange, copyloopvar)
140141
).
141142
WithTargetPath(testdataDir, "cgo").
142-
ForceDisableUnsupportedLinters().
143143
Runner().
144144
Install().
145145
Run().
@@ -355,9 +355,10 @@ func TestLineDirectiveProcessedFiles(t *testing.T) {
355355
func TestUnsafeOk(t *testing.T) {
356356
testshared.NewRunnerBuilder(t).
357357
WithNoConfig().
358-
WithArgs("--enable-all").
358+
WithArgs("--enable-all",
359+
"--go=1.22", // TODO(ldez) remove this line when we will run go1.23 on the CI. (related to intrange, copyloopvar)
360+
).
359361
WithTargetPath(testdataDir, "unsafe").
360-
ForceDisableUnsupportedLinters().
361362
Runner().
362363
Install().
363364
Run().
@@ -515,8 +516,8 @@ func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
515516
testshared.NewRunnerBuilder(t).
516517
WithNoConfig().
517518
WithArgs(test.args...).
519+
WithArgs("--go=1.22"). // TODO(ldez) remove this line when we will run go1.23 on the CI. (related to intrange, copyloopvar)
518520
WithTargetPath(testdataDir, minimalPkg).
519-
ForceDisableUnsupportedLinters().
520521
Runner().
521522
Run().
522523
ExpectExitCode(test.expected...)

test/testshared/runner.go

-71
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import (
44
"os"
55
"os/exec"
66
"path/filepath"
7-
"runtime"
8-
"slices"
97
"strings"
108
"sync"
119
"syscall"
1210
"testing"
1311
"time"
1412

15-
hcversion "github.com/hashicorp/go-version"
1613
"github.com/stretchr/testify/assert"
1714
"github.com/stretchr/testify/require"
1815

@@ -153,14 +150,6 @@ func (b *RunnerBuilder) WithArgs(args ...string) *RunnerBuilder {
153150
return b
154151
}
155152

156-
// ForceDisableUnsupportedLinters temporary method to disable some linters.
157-
// TODO(ldez) remove when we will run go1.23 on the CI.
158-
func (b *RunnerBuilder) ForceDisableUnsupportedLinters() *RunnerBuilder {
159-
b.args = forceDisableUnsupportedLinters(b.args)
160-
161-
return b
162-
}
163-
164153
func (b *RunnerBuilder) WithTargetPath(targets ...string) *RunnerBuilder {
165154
b.target = filepath.Join(targets...)
166155

@@ -369,63 +358,3 @@ func InstallGolangciLint(tb testing.TB) string {
369358

370359
return abs
371360
}
372-
373-
// TODO(ldez) remove when we will run go1.23 on the CI.
374-
func forceDisableUnsupportedLinters(args []string) []string {
375-
result := slices.Clone(args)
376-
377-
if !isGoLessThan("1.22") {
378-
return append(result, "--go=1.22")
379-
}
380-
381-
if len(result) == 0 {
382-
return append(result, "-D", "intrange,copyloopvar")
383-
}
384-
385-
if slices.ContainsFunc(args, func(arg string) bool { return strings.HasSuffix(arg, "-disable-all") }) {
386-
return args
387-
}
388-
389-
var appended bool
390-
391-
for i, arg := range args {
392-
if !strings.HasSuffix(arg, "-D") && !strings.HasSuffix(arg, "-disable") {
393-
continue
394-
}
395-
396-
if len(args) <= i+1 || strings.HasPrefix(args[i+1], "-") {
397-
continue
398-
}
399-
400-
d := strings.Split(args[i+1], ",")
401-
d = append(d, "intrange", "copyloopvar")
402-
403-
result[i+1] = strings.Join(slices.Compact(d), ",")
404-
405-
appended = true
406-
break
407-
}
408-
409-
if !appended {
410-
result = append(result, "-D", "intrange,copyloopvar")
411-
}
412-
413-
return result
414-
}
415-
416-
// TODO(ldez) remove when we will run go1.23 on the CI.
417-
func isGoLessThan(tag string) bool {
418-
vRuntime, err := hcversion.NewVersion(strings.TrimPrefix(runtime.Version(), "go"))
419-
if err != nil {
420-
return false
421-
}
422-
423-
vTag, err := hcversion.NewVersion(strings.TrimPrefix(tag, "go"))
424-
if err != nil {
425-
return false
426-
}
427-
428-
println(vRuntime.LessThanOrEqual(vTag))
429-
430-
return vRuntime.LessThan(vTag)
431-
}

test/testshared/runner_test.go

-47
Original file line numberDiff line numberDiff line change
@@ -217,50 +217,3 @@ func TestRunnerResult_ExpectOutputRegexp(t *testing.T) {
217217
r.ExpectOutputRegexp(`an.+`)
218218
r.ExpectOutputRegexp("an")
219219
}
220-
221-
// TODO(ldez) remove when we will run go1.23 on the CI.
222-
func Test_forceDisableUnsupportedLinters(t *testing.T) {
223-
t.Skip("only for illustration purpose because works only with go1.21")
224-
225-
testCases := []struct {
226-
desc string
227-
args []string
228-
expected []string
229-
}{
230-
{
231-
desc: "no args",
232-
expected: []string{"-D", "intrange,copyloopvar"},
233-
},
234-
{
235-
desc: "simple",
236-
args: []string{"-A", "B", "-E"},
237-
expected: []string{"-A", "B", "-E", "-D", "intrange,copyloopvar"},
238-
},
239-
{
240-
desc: "with existing disable linters",
241-
args: []string{"-D", "a,b"},
242-
expected: []string{"-D", "a,b,intrange,copyloopvar"},
243-
},
244-
{
245-
desc: "complex",
246-
args: []string{"-A", "B", "-D", "a,b", "C", "-E", "F"},
247-
expected: []string{"-A", "B", "-D", "a,b,intrange,copyloopvar", "C", "-E", "F"},
248-
},
249-
{
250-
desc: "disable-all",
251-
args: []string{"-disable-all", "-D", "a,b"},
252-
expected: []string{"-disable-all", "-D", "a,b"},
253-
},
254-
}
255-
256-
for _, test := range testCases {
257-
test := test
258-
t.Run(test.desc, func(t *testing.T) {
259-
t.Parallel()
260-
261-
result := forceDisableUnsupportedLinters(test.args)
262-
263-
assert.Equal(t, test.expected, result)
264-
})
265-
}
266-
}

0 commit comments

Comments
 (0)