Skip to content

Commit 39f401b

Browse files
authored
dev: review and clean linter tests (#3139)
1 parent aba80c7 commit 39f401b

13 files changed

+203
-205
lines changed

Diff for: .golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ issues:
136136
- path: pkg/lint/lintersdb/manager.go
137137
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
138138

139-
140139
run:
141140
timeout: 5m
142141
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.

Diff for: pkg/result/processors/sort_results.go

-6
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ var (
9090

9191
type ByName struct{ next comparator }
9292

93-
//nolint:golint
9493
func (cmp ByName) Next() comparator { return cmp.next }
9594

96-
//nolint:golint
9795
func (cmp ByName) Compare(a, b *result.Issue) compareResult {
9896
var res compareResult
9997

@@ -110,10 +108,8 @@ func (cmp ByName) Compare(a, b *result.Issue) compareResult {
110108

111109
type ByLine struct{ next comparator }
112110

113-
//nolint:golint
114111
func (cmp ByLine) Next() comparator { return cmp.next }
115112

116-
//nolint:golint
117113
func (cmp ByLine) Compare(a, b *result.Issue) compareResult {
118114
var res compareResult
119115

@@ -130,10 +126,8 @@ func (cmp ByLine) Compare(a, b *result.Issue) compareResult {
130126

131127
type ByColumn struct{ next comparator }
132128

133-
//nolint:golint
134129
func (cmp ByColumn) Next() comparator { return cmp.next }
135130

136-
//nolint:golint
137131
func (cmp ByColumn) Compare(a, b *result.Issue) compareResult {
138132
var res compareResult
139133

Diff for: test/enabled_linters_test.go

+73-70
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,11 @@ import (
1010
"github.com/golangci/golangci-lint/test/testshared"
1111
)
1212

13-
func inSlice(s []string, v string) bool {
14-
for _, sv := range s {
15-
if sv == v {
16-
return true
17-
}
18-
}
19-
20-
return false
21-
}
22-
23-
func getEnabledByDefaultFastLintersExcept(except ...string) []string {
24-
m := lintersdb.NewManager(nil, nil)
25-
ebdl := m.GetAllEnabledByDefaultLinters()
26-
var ret []string
27-
for _, lc := range ebdl {
28-
if lc.IsSlowLinter() {
29-
continue
30-
}
31-
32-
if !inSlice(except, lc.Name()) {
33-
ret = append(ret, lc.Name())
34-
}
35-
}
36-
37-
return ret
38-
}
39-
40-
func getAllFastLintersWith(with ...string) []string {
41-
linters := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
42-
ret := append([]string{}, with...)
43-
for _, lc := range linters {
44-
if lc.IsSlowLinter() {
45-
continue
46-
}
47-
ret = append(ret, lc.Name())
48-
}
49-
50-
return ret
51-
}
52-
53-
func getEnabledByDefaultLinters() []string {
54-
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
55-
var ret []string
56-
for _, lc := range ebdl {
57-
ret = append(ret, lc.Name())
58-
}
59-
60-
return ret
61-
}
62-
63-
func getEnabledByDefaultFastLintersWith(with ...string) []string {
64-
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
65-
ret := append([]string{}, with...)
66-
for _, lc := range ebdl {
67-
if lc.IsSlowLinter() {
68-
continue
69-
}
70-
71-
ret = append(ret, lc.Name())
72-
}
73-
74-
return ret
75-
}
76-
7713
//nolint:funlen
7814
func TestEnabledLinters(t *testing.T) {
15+
// require to display the message "Active x linters: [x,y]"
16+
t.Setenv("GL_TEST_RUN", "1")
17+
7918
cases := []struct {
8019
name string
8120
cfg string
@@ -93,28 +32,28 @@ func TestEnabledLinters(t *testing.T) {
9332
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
9433
},
9534
{
96-
name: "enable golint in config",
35+
name: "enable revive in config",
9736
cfg: `
9837
linters:
9938
enable:
100-
- golint
39+
- revive
10140
`,
102-
enabledLinters: getEnabledByDefaultFastLintersWith("golint"),
41+
enabledLinters: getEnabledByDefaultFastLintersWith("revive"),
10342
},
10443
{
10544
name: "disable govet in cmd",
10645
args: []string{"-Dgovet"},
10746
enabledLinters: getEnabledByDefaultFastLintersExcept("govet"),
10847
},
10948
{
110-
name: "enable gofmt in cmd and enable golint in config",
49+
name: "enable gofmt in cmd and enable revive in config",
11150
args: []string{"-Egofmt"},
11251
cfg: `
11352
linters:
11453
enable:
115-
- golint
54+
- revive
11655
`,
117-
enabledLinters: getEnabledByDefaultFastLintersWith("golint", "gofmt"),
56+
enabledLinters: getEnabledByDefaultFastLintersWith("revive", "gofmt"),
11857
},
11958
{
12059
name: "fast option in config",
@@ -195,3 +134,67 @@ func TestEnabledLinters(t *testing.T) {
195134
})
196135
}
197136
}
137+
138+
func inSlice(s []string, v string) bool {
139+
for _, sv := range s {
140+
if sv == v {
141+
return true
142+
}
143+
}
144+
145+
return false
146+
}
147+
148+
func getEnabledByDefaultFastLintersExcept(except ...string) []string {
149+
m := lintersdb.NewManager(nil, nil)
150+
ebdl := m.GetAllEnabledByDefaultLinters()
151+
var ret []string
152+
for _, lc := range ebdl {
153+
if lc.IsSlowLinter() {
154+
continue
155+
}
156+
157+
if !inSlice(except, lc.Name()) {
158+
ret = append(ret, lc.Name())
159+
}
160+
}
161+
162+
return ret
163+
}
164+
165+
func getAllFastLintersWith(with ...string) []string {
166+
linters := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
167+
ret := append([]string{}, with...)
168+
for _, lc := range linters {
169+
if lc.IsSlowLinter() {
170+
continue
171+
}
172+
ret = append(ret, lc.Name())
173+
}
174+
175+
return ret
176+
}
177+
178+
func getEnabledByDefaultLinters() []string {
179+
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
180+
var ret []string
181+
for _, lc := range ebdl {
182+
ret = append(ret, lc.Name())
183+
}
184+
185+
return ret
186+
}
187+
188+
func getEnabledByDefaultFastLintersWith(with ...string) []string {
189+
ebdl := lintersdb.NewManager(nil, nil).GetAllEnabledByDefaultLinters()
190+
ret := append([]string{}, with...)
191+
for _, lc := range ebdl {
192+
if lc.IsSlowLinter() {
193+
continue
194+
}
195+
196+
ret = append(ret, lc.Name())
197+
}
198+
199+
return ret
200+
}

0 commit comments

Comments
 (0)