@@ -10,72 +10,11 @@ import (
10
10
"github.com/golangci/golangci-lint/test/testshared"
11
11
)
12
12
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
-
77
13
//nolint:funlen
78
14
func TestEnabledLinters (t * testing.T ) {
15
+ // require to display the message "Active x linters: [x,y]"
16
+ t .Setenv ("GL_TEST_RUN" , "1" )
17
+
79
18
cases := []struct {
80
19
name string
81
20
cfg string
@@ -93,28 +32,28 @@ func TestEnabledLinters(t *testing.T) {
93
32
enabledLinters : getEnabledByDefaultFastLintersExcept ("govet" ),
94
33
},
95
34
{
96
- name : "enable golint in config" ,
35
+ name : "enable revive in config" ,
97
36
cfg : `
98
37
linters:
99
38
enable:
100
- - golint
39
+ - revive
101
40
` ,
102
- enabledLinters : getEnabledByDefaultFastLintersWith ("golint " ),
41
+ enabledLinters : getEnabledByDefaultFastLintersWith ("revive " ),
103
42
},
104
43
{
105
44
name : "disable govet in cmd" ,
106
45
args : []string {"-Dgovet" },
107
46
enabledLinters : getEnabledByDefaultFastLintersExcept ("govet" ),
108
47
},
109
48
{
110
- name : "enable gofmt in cmd and enable golint in config" ,
49
+ name : "enable gofmt in cmd and enable revive in config" ,
111
50
args : []string {"-Egofmt" },
112
51
cfg : `
113
52
linters:
114
53
enable:
115
- - golint
54
+ - revive
116
55
` ,
117
- enabledLinters : getEnabledByDefaultFastLintersWith ("golint " , "gofmt" ),
56
+ enabledLinters : getEnabledByDefaultFastLintersWith ("revive " , "gofmt" ),
118
57
},
119
58
{
120
59
name : "fast option in config" ,
@@ -195,3 +134,67 @@ func TestEnabledLinters(t *testing.T) {
195
134
})
196
135
}
197
136
}
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