Skip to content

Commit 3dd4e89

Browse files
cyphermoxclaude
andauthored
fix: emit lint diff in conventional got→want direction (#230)
ExecDiff ran `diff want got` with labels `--- want` / `+++ got`, so the printed diff described how to turn the correctly-formatted file into the current (unformatted) one. That is the inverse of the convention used by `gofmt -d`, `prettier` and `black --diff`, where the diff goes from the current file to the expected output and can be applied directly as a patch to fix formatting. Swap the operands and labels so the output is `--- got` / `+++ want`: removed lines are the current contents, added lines are the fix. No behavioral change to formatting or lint pass/fail; only the direction and labels of the informational diff. lint_test.go asserts on the returned error only, so existing tests are unaffected. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e8ca656 commit 3dd4e89

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

pkg/yam/diff.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ func ExecDiff(want, got []byte) error {
4040
return fmt.Errorf("unable to execute diff command: %w", err)
4141
}
4242

43+
// Diff from "got" (the current file contents) to "want" (the correctly
44+
// formatted output) so the printed diff reads in the conventional
45+
// direction: removed lines are what's there now, added lines are the fix.
46+
// This matches tools like `gofmt -d`, `prettier` and `black --diff`, and
47+
// means the output can be applied as a patch to format the file.
4348
cmd := exec.Command(
4449
command,
4550
"-U",
4651
"5",
4752
"--label",
48-
"want",
49-
"--label",
5053
"got",
51-
tempWant.Name(),
54+
"--label",
55+
"want",
5256
tempGot.Name(),
57+
tempWant.Name(),
5358
)
5459
cmd.Stdout = handlerOutput
5560
cmd.Stderr = handlerOutput

0 commit comments

Comments
 (0)