Skip to content

Commit 7c94d73

Browse files
committed
dev: drop golangcitest:config directive
1 parent c2ced0f commit 7c94d73

File tree

3 files changed

+8
-84
lines changed

3 files changed

+8
-84
lines changed

test/fix_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import (
66
"path/filepath"
77
"testing"
88

9-
"github.com/stretchr/testify/require"
10-
"gopkg.in/yaml.v3"
11-
129
"github.com/golangci/golangci-lint/pkg/exitcodes"
1310
"github.com/golangci/golangci-lint/test/testshared"
11+
"github.com/stretchr/testify/require"
1412
)
1513

1614
func TestFix(t *testing.T) {
@@ -56,15 +54,12 @@ func TestFix(t *testing.T) {
5654

5755
args = append(args, rc.args...)
5856

59-
cfg, err := yaml.Marshal(rc.config)
60-
require.NoError(t, err)
61-
6257
var runResult *testshared.RunResult
6358
if rc.configPath != "" {
6459
args = append(args, "-c", rc.configPath)
6560
runResult = testshared.NewLintRunner(t).RunCommand("run", args...)
6661
} else {
67-
runResult = testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
62+
runResult = testshared.NewLintRunner(t).RunWithYamlConfig("", args...)
6863
}
6964

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

test/linters_test.go

+5-75
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"
@@ -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,34 +212,10 @@ 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()
@@ -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/testshared/testshared.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ func (r *LintRunner) RunCommandWithYamlConfig(cfg, command string, args ...strin
153153
defer os.Remove(cfgPath)
154154
}
155155

156-
cfg = strings.TrimSpace(cfg)
157-
cfg = strings.ReplaceAll(cfg, "\t", " ")
156+
cfg = strings.ReplaceAll(strings.TrimSpace(cfg), "\t", " ")
158157

159158
err = os.WriteFile(cfgPath, []byte(cfg), os.ModePerm)
160159
assert.NoError(r.t, err)

0 commit comments

Comments
 (0)