Skip to content

Commit f7fba37

Browse files
authored
dev: replace golangcitest:config by golangcitest:config_path (#3099)
1 parent 9da04f5 commit f7fba37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+126
-118
lines changed

test/fix_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
"gopkg.in/yaml.v3"
1110

1211
"github.com/golangci/golangci-lint/pkg/exitcodes"
1312
"github.com/golangci/golangci-lint/test/testshared"
@@ -56,15 +55,12 @@ func TestFix(t *testing.T) {
5655

5756
args = append(args, rc.args...)
5857

59-
cfg, err := yaml.Marshal(rc.config)
60-
require.NoError(t, err)
61-
6258
var runResult *testshared.RunResult
6359
if rc.configPath != "" {
6460
args = append(args, "-c", rc.configPath)
6561
runResult = testshared.NewLintRunner(t).RunCommand("run", args...)
6662
} else {
67-
runResult = testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
63+
runResult = testshared.NewLintRunner(t).RunWithYamlConfig("", args...)
6864
}
6965

7066
// nolintlint test uses non existing linters (bob, alice)

test/linters_test.go

+7-77
Original file line numberDiff line numberDiff line change
@@ -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-
197177
func 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

242213
type 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-
272219
func 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
279226
func 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
}

test/testdata/configs/cyclop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
cyclop:
3+
max-complexity: 15

test/testdata/configs/dupl.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
dupl:
3+
threshold: 20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
errcheck:
3+
check-blank: true
4+
exclude: testdata/errcheck/exclude.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
errcheck:
3+
check-blank: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
errcheck:
3+
check-type-assertions: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
forbidigo:
3+
exclude-godoc-examples: false
4+

test/testdata/configs/funlen.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
funlen:
3+
lines: 20
4+
statements: 10

test/testdata/configs/gocognit.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gocognit:
3+
min-complexity: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
goconst:
3+
ignore-calls: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
goconst:
3+
ignore-tests: false
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
goconst:
3+
ignore-tests: true

test/testdata/configs/gocyclo.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gocyclo:
3+
min-complexity: 20

test/testdata/configs/godox.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
linters-settings:
2+
godox:
3+
keywords:
4+
- FIXME
5+
- TODO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gofmt:
3+
simplify: false

test/testdata/configs/gofumpt-fix.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gofumpt:
3+
extra-rules: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
gofumpt:
3+
extra-rules: true

test/testdata/configs/goimports.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
goimports:
3+
local-prefixes: github.com/golangci/golangci-lint

test/testdata/configs/govet.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
govet:
3+
enable: fieldalignment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
govet:
3+
enable: ifaceassert

test/testdata/configs/lll.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
lll:
3+
tab-width: 4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
makezero:
3+
always: true

test/testdata/configs/nestif.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
nestif:
3+
min-complexity: 1

test/testdata/configs/nolintlint.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
nolintlint:
3+
require-explanation: true
4+
require-specific: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
nolintlint:
3+
allow-unused: false
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
whitespace:
3+
multi-if: true
4+
multi-func: true

test/testdata/configs/wsl.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
wsl:
3+
allow-cuddle-declarations: false

test/testdata/cyclop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Ecyclop
2-
//golangcitest:config linters-settings.cyclop.max-complexity=15
2+
//golangcitest:config_path testdata/configs/cyclop.yml
33
package testdata
44

55
func cyclopComplexFunc(s string) { // ERROR "calculated cyclomatic complexity for function cyclopComplexFunc is 22, max is 15"

test/testdata/dupl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Edupl
2-
//golangcitest:config linters-settings.dupl.threshold=20
2+
//golangcitest:config_path testdata/configs/dupl.yml
33
package testdata
44

55
type DuplLogger struct{}

test/testdata/errcheck_exclude.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//golangcitest:args -Eerrcheck
2-
//golangcitest:config linters-settings.errcheck.check-blank=true
3-
//golangcitest:config linters-settings.errcheck.exclude=testdata/errcheck/exclude.txt
2+
//golangcitest:config_path testdata/configs/errcheck_exclude.yml
43
package testdata
54

65
import (

test/testdata/errcheck_ignore_default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Eerrcheck
2-
//golangcitest:config linters-settings.errcheck.check-blank=true
2+
//golangcitest:config_path testdata/configs/errcheck_ignore_default.yml
33
package testdata
44

55
import (

test/testdata/errcheck_type_assertions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Eerrcheck
2-
//golangcitest:config linters-settings.errcheck.check-type-assertions=true
2+
//golangcitest:config_path testdata/configs/errcheck_type_assertions.yml
33
package testdata
44

55
func ErrorTypeAssertion(filter map[string]interface{}) bool {

test/testdata/fix/in/gofumpt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Egofumpt
2-
//golangcitest:config linters-settings.gofumpt.extra-rules=true
2+
//golangcitest:config_path testdata/configs/gofumpt-fix.yml
33
package p
44

55
import "fmt"

test/testdata/fix/in/whitespace.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//golangcitest:args -Ewhitespace
2-
//golangcitest:config linters-settings.whitespace.multi-if=true
3-
//golangcitest:config linters-settings.whitespace.multi-func=true
2+
//golangcitest:config_path testdata/configs/whitespace-fix.yml
43
package p
54

65
import "fmt"

test/testdata/fix/out/gofumpt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Egofumpt
2-
//golangcitest:config linters-settings.gofumpt.extra-rules=true
2+
//golangcitest:config_path testdata/configs/gofumpt-fix.yml
33
package p
44

55
import "fmt"

test/testdata/fix/out/whitespace.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//golangcitest:args -Ewhitespace
2-
//golangcitest:config linters-settings.whitespace.multi-if=true
3-
//golangcitest:config linters-settings.whitespace.multi-func=true
2+
//golangcitest:config_path testdata/configs/whitespace-fix.yml
43
package p
54

65
import "fmt"

test/testdata/forbidigo_include_godoc_examples_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Eforbidigo
2-
//golangcitest:config linters-settings.forbidigo.exclude-godoc-examples=false
2+
//golangcitest:config_path testdata/configs/forbidigo_include_godoc_examples.yml
33
package testdata
44

55
import "fmt"

test/testdata/funlen.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//golangcitest:args -Efunlen
2-
//golangcitest:config linters-settings.funlen.lines=20
3-
//golangcitest:config linters-settings.funlen.statements=10
2+
//golangcitest:config_path testdata/configs/funlen.yml
43
package testdata
54

65
func TooManyLines() { // ERROR `Function 'TooManyLines' is too long \(22 > 20\)`

test/testdata/gocognit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Egocognit
2-
//golangcitest:config linters-settings.gocognit.min-complexity=2
2+
//golangcitest:config_path testdata/configs/gocognit.yml
33
package testdata
44

55
func GoCognit_CC4_GetWords(number int) string { // ERROR "cognitive complexity 4 of func .* is high .*"

test/testdata/goconst_calls_enabled.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//golangcitest:args -Egoconst
2-
//golangcitest:config linters-settings.goconst.ignore-calls=false
2+
//golangcitest:config_path testdata/configs/goconst_calls_enabled.yml
33
package testdata
44

55
import "fmt"

0 commit comments

Comments
 (0)