@@ -23,7 +23,7 @@ func inSlice(s []string, v string) bool {
2323func getEnabledByDefaultFastLintersExcept (except ... string ) []string {
2424 m := lintersdb .NewManager (nil , nil )
2525 ebdl := m .GetAllEnabledByDefaultLinters ()
26- ret := []string {}
26+ var ret []string
2727 for _ , lc := range ebdl {
2828 if lc .IsSlowLinter () {
2929 continue
@@ -52,7 +52,7 @@ func getAllFastLintersWith(with ...string) []string {
5252
5353func getEnabledByDefaultLinters () []string {
5454 ebdl := lintersdb .NewManager (nil , nil ).GetAllEnabledByDefaultLinters ()
55- ret := []string {}
55+ var ret []string
5656 for _ , lc := range ebdl {
5757 ret = append (ret , lc .Name ())
5858 }
@@ -76,23 +76,21 @@ func getEnabledByDefaultFastLintersWith(with ...string) []string {
7676
7777//nolint:funlen
7878func TestEnabledLinters (t * testing.T ) {
79- type tc struct {
79+ cases := [] struct {
8080 name string
8181 cfg string
82- el []string
83- args string
82+ enabledLinters []string
83+ args [] string
8484 noImplicitFast bool
85- }
86-
87- cases := []tc {
85+ }{
8886 {
8987 name : "disable govet in config" ,
9088 cfg : `
9189 linters:
9290 disable:
9391 - govet
9492 ` ,
95- el : getEnabledByDefaultFastLintersExcept ("govet" ),
93+ enabledLinters : getEnabledByDefaultFastLintersExcept ("govet" ),
9694 },
9795 {
9896 name : "enable golint in config" ,
@@ -101,30 +99,30 @@ func TestEnabledLinters(t *testing.T) {
10199 enable:
102100 - golint
103101 ` ,
104- el : getEnabledByDefaultFastLintersWith ("golint" ),
102+ enabledLinters : getEnabledByDefaultFastLintersWith ("golint" ),
105103 },
106104 {
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" ),
110108 },
111109 {
112110 name : "enable gofmt in cmd and enable golint in config" ,
113- args : "-Egofmt" ,
111+ args : [] string { "-Egofmt" } ,
114112 cfg : `
115113 linters:
116114 enable:
117115 - golint
118116 ` ,
119- el : getEnabledByDefaultFastLintersWith ("golint" , "gofmt" ),
117+ enabledLinters : getEnabledByDefaultFastLintersWith ("golint" , "gofmt" ),
120118 },
121119 {
122120 name : "fast option in config" ,
123121 cfg : `
124122 linters:
125123 fast: true
126124 ` ,
127- el : getEnabledByDefaultFastLintersWith (),
125+ enabledLinters : getEnabledByDefaultFastLintersWith (),
128126 noImplicitFast : true ,
129127 },
130128 {
@@ -133,13 +131,13 @@ func TestEnabledLinters(t *testing.T) {
133131 linters:
134132 fast: false
135133 ` ,
136- el : getEnabledByDefaultLinters (),
134+ enabledLinters : getEnabledByDefaultLinters (),
137135 noImplicitFast : true ,
138136 },
139137 {
140138 name : "set fast option in command-line" ,
141- args : "--fast" ,
142- el : getEnabledByDefaultFastLintersWith (),
139+ args : [] string { "--fast" } ,
140+ enabledLinters : getEnabledByDefaultFastLintersWith (),
143141 noImplicitFast : true ,
144142 },
145143 {
@@ -148,8 +146,8 @@ func TestEnabledLinters(t *testing.T) {
148146 linters:
149147 fast: false
150148 ` ,
151- args : "--fast" ,
152- el : getEnabledByDefaultFastLintersWith (),
149+ args : [] string { "--fast" } ,
150+ enabledLinters : getEnabledByDefaultFastLintersWith (),
153151 noImplicitFast : true ,
154152 },
155153 {
@@ -158,36 +156,42 @@ func TestEnabledLinters(t *testing.T) {
158156 linters:
159157 fast: true
160158 ` ,
161- args : "--fast=false" ,
162- el : getEnabledByDefaultLinters (),
159+ args : [] string { "--fast=false" } ,
160+ enabledLinters : getEnabledByDefaultLinters (),
163161 noImplicitFast : true ,
164162 },
165163 {
166164 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" ),
169167 noImplicitFast : true ,
170168 },
171169 }
172170
173- runner := testshared .NewLintRunner (t )
171+ testshared .InstallGolangciLint (t )
172+
174173 for _ , c := range cases {
175174 c := c
176175 t .Run (c .name , func (t * testing.T ) {
177176 t .Parallel ()
178177
179- runArgs := []string {"--verbose" }
178+ args := []string {"--verbose" }
180179 if ! c .noImplicitFast {
181- runArgs = append (runArgs , "--fast" )
180+ args = append (args , "--fast" )
182181 }
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 ()
188182
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 , " " )))
191195 })
192196 }
193197}
0 commit comments