@@ -14,7 +14,6 @@ import (
1414
1515 hcversion "github.com/hashicorp/go-version"
1616 "github.com/stretchr/testify/require"
17- "gopkg.in/yaml.v3"
1817
1918 "github.com/golangci/golangci-lint/pkg/exitcodes"
2019 "github.com/golangci/golangci-lint/test/testshared"
@@ -82,7 +81,7 @@ func TestGoimportsLocal(t *testing.T) {
8281
8382 args = append (args , rc .args ... )
8483
85- cfg , err := yaml . Marshal (rc .config )
84+ cfg , err := os . ReadFile (rc .configPath )
8685 require .NoError (t , err )
8786
8887 testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
@@ -175,25 +174,6 @@ func TestFileOutput(t *testing.T) {
175174 require .Contains (t , string (b ), `"Issues":[` )
176175}
177176
178- func saveConfig (t * testing.T , cfg map [string ]interface {}) (cfgPath string , finishFunc func ()) {
179- f , err := os .CreateTemp ("" , "golangci_lint_test" )
180- require .NoError (t , err )
181-
182- cfgPath = f .Name () + ".yml"
183- err = os .Rename (f .Name (), cfgPath )
184- require .NoError (t , err )
185-
186- err = yaml .NewEncoder (f ).Encode (cfg )
187- require .NoError (t , err )
188-
189- return cfgPath , func () {
190- require .NoError (t , f .Close ())
191- if os .Getenv ("GL_KEEP_TEMP_FILES" ) != "1" {
192- require .NoError (t , os .Remove (cfgPath ))
193- }
194- }
195- }
196-
197177func testOneSource (t * testing.T , sourcePath string ) {
198178 args := []string {
199179 "run" ,
@@ -210,25 +190,16 @@ func testOneSource(t *testing.T, sourcePath string) {
210190 t .Skipf ("Skipped: %s" , sourcePath )
211191 }
212192
213- var cfgPath string
214- if rc .config != nil {
215- p , finish := saveConfig (t , rc .config )
216- defer finish ()
217- cfgPath = p
218- } else if rc .configPath != "" {
219- cfgPath = rc .configPath
220- }
221-
222193 for _ , addArg := range []string {"" , "-Etypecheck" } {
223194 caseArgs := append ([]string {}, args ... )
224195 caseArgs = append (caseArgs , rc .args ... )
225196 if addArg != "" {
226197 caseArgs = append (caseArgs , addArg )
227198 }
228- if cfgPath == "" {
199+ if rc . configPath == "" {
229200 caseArgs = append (caseArgs , "--no-config" )
230201 } else {
231- caseArgs = append (caseArgs , "-c" , cfgPath )
202+ caseArgs = append (caseArgs , "-c" , rc . configPath )
232203 }
233204
234205 caseArgs = append (caseArgs , sourcePath )
@@ -241,41 +212,17 @@ func testOneSource(t *testing.T, sourcePath string) {
241212
242213type runContext struct {
243214 args []string
244- config map [string ]interface {}
245215 configPath string
246216 expectedLinter string
247217}
248218
249- func buildConfigFromShortRepr (t * testing.T , repr string , config map [string ]interface {}) {
250- kv := strings .Split (repr , "=" )
251- require .Len (t , kv , 2 , "repr: %s" , repr )
252-
253- keyParts := strings .Split (kv [0 ], "." )
254- require .True (t , len (keyParts ) >= 2 , len (keyParts ))
255-
256- lastObj := config
257- for _ , k := range keyParts [:len (keyParts )- 1 ] {
258- var v map [string ]interface {}
259- if lastObj [k ] == nil {
260- v = map [string ]interface {}{}
261- } else {
262- v = lastObj [k ].(map [string ]interface {})
263- }
264-
265- lastObj [k ] = v
266- lastObj = v
267- }
268-
269- lastObj [keyParts [len (keyParts )- 1 ]] = kv [1 ]
270- }
271-
272219func skipMultilineComment (scanner * bufio.Scanner ) {
273220 for line := scanner .Text (); ! strings .Contains (line , "*/" ) && scanner .Scan (); {
274221 line = scanner .Text ()
275222 }
276223}
277224
278- //nolint:gocyclo,funlen
225+ //nolint:gocyclo
279226func extractRunContextFromComments (t * testing.T , sourcePath string ) * runContext {
280227 f , err := os .Open (sourcePath )
281228 require .NoError (t , err )
@@ -324,14 +271,6 @@ func extractRunContextFromComments(t *testing.T, sourcePath string) *runContext
324271 rc .args = strings .Split (after , " " )
325272 continue
326273
327- case "//golangcitest:config" :
328- require .NotEmpty (t , after )
329- if rc .config == nil {
330- rc .config = map [string ]interface {}{}
331- }
332- buildConfigFromShortRepr (t , after , rc .config )
333- continue
334-
335274 case "//golangcitest:config_path" :
336275 require .NotEmpty (t , after )
337276 rc .configPath = after
@@ -394,10 +333,7 @@ func TestTparallel(t *testing.T) {
394333
395334 args = append (args , rc .args ... )
396335
397- cfg , err := yaml .Marshal (rc .config )
398- require .NoError (t , err )
399-
400- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
336+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).
401337 ExpectHasIssue (
402338 "testdata/tparallel/missing_toplevel_test.go:7:6: TestTopLevel should call t.Parallel on the top level as well as its subtests\n " ,
403339 )
@@ -416,10 +352,7 @@ func TestTparallel(t *testing.T) {
416352
417353 args = append (args , rc .args ... )
418354
419- cfg , err := yaml .Marshal (rc .config )
420- require .NoError (t , err )
421-
422- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).
355+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).
423356 ExpectHasIssue (
424357 "testdata/tparallel/missing_subtest_test.go:7:6: TestSubtests's subtests should call t.Parallel\n " ,
425358 )
@@ -438,9 +371,6 @@ func TestTparallel(t *testing.T) {
438371
439372 args = append (args , rc .args ... )
440373
441- cfg , err := yaml .Marshal (rc .config )
442- require .NoError (t , err )
443-
444- testshared .NewLintRunner (t ).RunWithYamlConfig (string (cfg ), args ... ).ExpectNoIssues ()
374+ testshared .NewLintRunner (t ).RunWithYamlConfig ("" , args ... ).ExpectNoIssues ()
445375 })
446376}
0 commit comments