Skip to content

Commit 139f70b

Browse files
authored
Change pkl format --write to exit 0 when formatting violations are found (#1340)
1 parent 2de1d5b commit 139f70b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/modules/pkl-cli/pages/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,9 @@ pkl shell-completion zsh
741741
This command formats or checks formatting of Pkl files. +
742742
Exit codes:
743743

744-
* 0: No violations found.
744+
* 0: No violations found or files were updated.
745745
* 1: An unexpected error happened (ex.: IO error)
746-
* 11: Violations were found.
746+
* 11: Violations were found (when running without `--write`).
747747

748748
If the path is a directory, recursively looks for files with a `.pkl` extension, or files named `PklProject`.
749749

pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ constructor(
110110

111111
val formatted = format(contents)
112112
if (contents != formatted) {
113-
status.update(FORMATTING_VIOLATION)
114113
if (diffNameOnly || overwrite) {
115114
// if `--diff-name-only` or `-w` is specified, only write file names
116115
writeLine(pathStr)
117116
}
118117

119118
if (overwrite) {
120119
path.writeText(formatted, Charsets.UTF_8)
120+
} else {
121+
// only exit on violation for "check" operations, not when overwriting
122+
status.update(FORMATTING_VIOLATION)
121123
}
122124
}
123125

0 commit comments

Comments
 (0)