@@ -23,7 +23,7 @@ func inSlice(s []string, v string) bool {
23
23
func getEnabledByDefaultFastLintersExcept (except ... string ) []string {
24
24
m := lintersdb .NewManager (nil , nil )
25
25
ebdl := m .GetAllEnabledByDefaultLinters ()
26
- ret := []string {}
26
+ var ret []string
27
27
for _ , lc := range ebdl {
28
28
if lc .IsSlowLinter () {
29
29
continue
@@ -52,7 +52,7 @@ func getAllFastLintersWith(with ...string) []string {
52
52
53
53
func getEnabledByDefaultLinters () []string {
54
54
ebdl := lintersdb .NewManager (nil , nil ).GetAllEnabledByDefaultLinters ()
55
- ret := []string {}
55
+ var ret []string
56
56
for _ , lc := range ebdl {
57
57
ret = append (ret , lc .Name ())
58
58
}
@@ -76,23 +76,21 @@ func getEnabledByDefaultFastLintersWith(with ...string) []string {
76
76
77
77
//nolint:funlen
78
78
func TestEnabledLinters (t * testing.T ) {
79
- type tc struct {
79
+ cases := [] struct {
80
80
name string
81
81
cfg string
82
- el []string
83
- args string
82
+ enabledLinters []string
83
+ args [] string
84
84
noImplicitFast bool
85
- }
86
-
87
- cases := []tc {
85
+ }{
88
86
{
89
87
name : "disable govet in config" ,
90
88
cfg : `
91
89
linters:
92
90
disable:
93
91
- govet
94
92
` ,
95
- el : getEnabledByDefaultFastLintersExcept ("govet" ),
93
+ enabledLinters : getEnabledByDefaultFastLintersExcept ("govet" ),
96
94
},
97
95
{
98
96
name : "enable golint in config" ,
@@ -101,30 +99,30 @@ func TestEnabledLinters(t *testing.T) {
101
99
enable:
102
100
- golint
103
101
` ,
104
- el : getEnabledByDefaultFastLintersWith ("golint" ),
102
+ enabledLinters : getEnabledByDefaultFastLintersWith ("golint" ),
105
103
},
106
104
{
107
- name : "disable govet in cmd" ,
108
- args : "-Dgovet" ,
109
- el : getEnabledByDefaultFastLintersExcept ("govet" ),
105
+ name : "disable govet in cmd" ,
106
+ args : [] string { "-Dgovet" } ,
107
+ enabledLinters : getEnabledByDefaultFastLintersExcept ("govet" ),
110
108
},
111
109
{
112
110
name : "enable gofmt in cmd and enable golint in config" ,
113
- args : "-Egofmt" ,
111
+ args : [] string { "-Egofmt" } ,
114
112
cfg : `
115
113
linters:
116
114
enable:
117
115
- golint
118
116
` ,
119
- el : getEnabledByDefaultFastLintersWith ("golint" , "gofmt" ),
117
+ enabledLinters : getEnabledByDefaultFastLintersWith ("golint" , "gofmt" ),
120
118
},
121
119
{
122
120
name : "fast option in config" ,
123
121
cfg : `
124
122
linters:
125
123
fast: true
126
124
` ,
127
- el : getEnabledByDefaultFastLintersWith (),
125
+ enabledLinters : getEnabledByDefaultFastLintersWith (),
128
126
noImplicitFast : true ,
129
127
},
130
128
{
@@ -133,13 +131,13 @@ func TestEnabledLinters(t *testing.T) {
133
131
linters:
134
132
fast: false
135
133
` ,
136
- el : getEnabledByDefaultLinters (),
134
+ enabledLinters : getEnabledByDefaultLinters (),
137
135
noImplicitFast : true ,
138
136
},
139
137
{
140
138
name : "set fast option in command-line" ,
141
- args : "--fast" ,
142
- el : getEnabledByDefaultFastLintersWith (),
139
+ args : [] string { "--fast" } ,
140
+ enabledLinters : getEnabledByDefaultFastLintersWith (),
143
141
noImplicitFast : true ,
144
142
},
145
143
{
@@ -148,8 +146,8 @@ func TestEnabledLinters(t *testing.T) {
148
146
linters:
149
147
fast: false
150
148
` ,
151
- args : "--fast" ,
152
- el : getEnabledByDefaultFastLintersWith (),
149
+ args : [] string { "--fast" } ,
150
+ enabledLinters : getEnabledByDefaultFastLintersWith (),
153
151
noImplicitFast : true ,
154
152
},
155
153
{
@@ -158,36 +156,42 @@ func TestEnabledLinters(t *testing.T) {
158
156
linters:
159
157
fast: true
160
158
` ,
161
- args : "--fast=false" ,
162
- el : getEnabledByDefaultLinters (),
159
+ args : [] string { "--fast=false" } ,
160
+ enabledLinters : getEnabledByDefaultLinters (),
163
161
noImplicitFast : true ,
164
162
},
165
163
{
166
164
name : "fast option combined with enable and enable-all" ,
167
- args : "--enable-all --fast --enable=unused" ,
168
- el : getAllFastLintersWith ("unused" ),
165
+ args : [] string { "--enable-all" , " --fast" , " --enable=unused"} ,
166
+ enabledLinters : getAllFastLintersWith ("unused" ),
169
167
noImplicitFast : true ,
170
168
},
171
169
}
172
170
173
- runner := testshared .NewLintRunner (t )
171
+ testshared .InstallGolangciLint (t )
172
+
174
173
for _ , c := range cases {
175
174
c := c
176
175
t .Run (c .name , func (t * testing.T ) {
177
176
t .Parallel ()
178
177
179
- runArgs := []string {"--verbose" }
178
+ args := []string {"--verbose" }
180
179
if ! c .noImplicitFast {
181
- runArgs = append (runArgs , "--fast" )
180
+ args = append (args , "--fast" )
182
181
}
183
- if c .args != "" {
184
- runArgs = append (runArgs , strings .Split (c .args , " " )... )
185
- }
186
- r := runner .RunCommandWithYamlConfig (c .cfg , "linters" , runArgs ... )
187
- sort .StringSlice (c .el ).Sort ()
188
182
189
- expectedLine := fmt .Sprintf ("Active %d linters: [%s]" , len (c .el ), strings .Join (c .el , " " ))
190
- r .ExpectOutputContains (expectedLine )
183
+ r := testshared .NewRunnerBuilder (t ).
184
+ WithCommand ("linters" ).
185
+ WithArgs (args ... ).
186
+ WithArgs (c .args ... ).
187
+ WithConfig (c .cfg ).
188
+ Runner ().
189
+ Run ()
190
+
191
+ sort .StringSlice (c .enabledLinters ).Sort ()
192
+
193
+ r .ExpectOutputContains (fmt .Sprintf ("Active %d linters: [%s]" ,
194
+ len (c .enabledLinters ), strings .Join (c .enabledLinters , " " )))
191
195
})
192
196
}
193
197
}
0 commit comments