dev: improve and clean fix_test (#2457)
This commit is contained in:
parent
3a6417c45e
commit
e41f428ded
@ -9,6 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||
"github.com/golangci/golangci-lint/test/testshared"
|
||||
)
|
||||
|
||||
@ -52,7 +53,19 @@ func TestFix(t *testing.T) {
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
require.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
|
||||
var runResult *testshared.RunResult
|
||||
if rc.configPath != "" {
|
||||
args = append(args, "-c", rc.configPath)
|
||||
runResult = testshared.NewLintRunner(t).RunCommand("run", args...)
|
||||
} else {
|
||||
runResult = testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...)
|
||||
}
|
||||
|
||||
// nolintlint test uses non existing linters (bob, alice)
|
||||
if rc.expectedLinter != "nolintlint" {
|
||||
runResult.ExpectExitCode(exitcodes.Success)
|
||||
}
|
||||
|
||||
output, err := os.ReadFile(input)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
8
test/testdata/configs/gocritic-fix.yml
vendored
Normal file
8
test/testdata/configs/gocritic-fix.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
linters-settings:
|
||||
gocritic:
|
||||
enabled-checks:
|
||||
- ruleguard
|
||||
settings:
|
||||
ruleguard:
|
||||
rules: 'ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go'
|
||||
|
5
test/testdata/fix/in/gocritic.go
vendored
5
test/testdata/fix/in/gocritic.go
vendored
@ -1,6 +1,5 @@
|
||||
//args: -Egocritic
|
||||
//config: linters-settings.gocritic.enabled-checks=ruleguard
|
||||
//config: linters-settings.gocritic.settings.ruleguard.rules=ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go
|
||||
// args: -Egocritic
|
||||
// config_path: testdata/configs/gocritic-fix.yml
|
||||
package p
|
||||
|
||||
import (
|
||||
|
8
test/testdata/fix/in/unused.go
vendored
8
test/testdata/fix/in/unused.go
vendored
@ -1,8 +0,0 @@
|
||||
//args: -Eunused
|
||||
package p
|
||||
|
||||
type (
|
||||
unused struct{}
|
||||
)
|
||||
|
||||
func X() {}
|
5
test/testdata/fix/out/gocritic.go
vendored
5
test/testdata/fix/out/gocritic.go
vendored
@ -1,6 +1,5 @@
|
||||
//args: -Egocritic
|
||||
//config: linters-settings.gocritic.enabled-checks=ruleguard
|
||||
//config: linters-settings.gocritic.settings.ruleguard.rules=ruleguard/rangeExprCopy.go,ruleguard/strings_simplify.go
|
||||
// args: -Egocritic
|
||||
// config_path: testdata/configs/gocritic-fix.yml
|
||||
package p
|
||||
|
||||
import (
|
||||
|
8
test/testdata/fix/out/unused.go
vendored
8
test/testdata/fix/out/unused.go
vendored
@ -1,8 +0,0 @@
|
||||
//args: -Eunused
|
||||
package p
|
||||
|
||||
type (
|
||||
unused struct{}
|
||||
)
|
||||
|
||||
func X() {}
|
Loading…
x
Reference in New Issue
Block a user