mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-02 01:20:52 -04:00
fix: combination of --fix and --path-prefix (#3700)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
076f6b911d
commit
d92b38cc3e
4 changed files with 70 additions and 20 deletions
test
|
@ -14,7 +14,9 @@ import (
|
|||
// value: "1"
|
||||
const envKeepTempFiles = "GL_KEEP_TEMP_FILES"
|
||||
|
||||
func TestFix(t *testing.T) {
|
||||
func setupTestFix(t *testing.T) []string {
|
||||
t.Helper()
|
||||
|
||||
testshared.SkipOnWindows(t)
|
||||
|
||||
tmpDir := filepath.Join(testdataDir, "fix.tmp")
|
||||
|
@ -33,7 +35,11 @@ func TestFix(t *testing.T) {
|
|||
|
||||
testshared.InstallGolangciLint(t)
|
||||
|
||||
sources := findSources(t, tmpDir, "in", "*.go")
|
||||
return findSources(t, tmpDir, "in", "*.go")
|
||||
}
|
||||
|
||||
func TestFix(t *testing.T) {
|
||||
sources := setupTestFix(t)
|
||||
|
||||
for _, input := range sources {
|
||||
input := input
|
||||
|
@ -47,13 +53,49 @@ func TestFix(t *testing.T) {
|
|||
}
|
||||
|
||||
testshared.NewRunnerBuilder(t).
|
||||
WithArgs(
|
||||
"--disable-all",
|
||||
WithArgs("--disable-all",
|
||||
"--print-issued-lines=false",
|
||||
"--print-linter-name=false",
|
||||
"--out-format=line-number",
|
||||
"--fix",
|
||||
).
|
||||
"--fix").
|
||||
WithRunContext(rc).
|
||||
WithTargetPath(input).
|
||||
Runner().
|
||||
Run().
|
||||
ExpectExitCode(rc.ExitCode)
|
||||
|
||||
output, err := os.ReadFile(input)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedOutput, err := os.ReadFile(filepath.Join(testdataDir, "fix", "out", filepath.Base(input)))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, string(expectedOutput), string(output))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFix_pathPrefix(t *testing.T) {
|
||||
sources := setupTestFix(t)
|
||||
|
||||
for _, input := range sources {
|
||||
input := input
|
||||
t.Run(filepath.Base(input), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rc := testshared.ParseTestDirectives(t, input)
|
||||
if rc == nil {
|
||||
t.Logf("Skipped: %s", input)
|
||||
return
|
||||
}
|
||||
|
||||
testshared.NewRunnerBuilder(t).
|
||||
WithArgs("--disable-all",
|
||||
"--print-issued-lines=false",
|
||||
"--print-linter-name=false",
|
||||
"--out-format=line-number",
|
||||
"--fix",
|
||||
"--path-prefix=foobar/").
|
||||
WithRunContext(rc).
|
||||
WithTargetPath(input).
|
||||
Runner().
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue