From 139f70bb790ca038f4dc64ba5775e8f56ed6123a Mon Sep 17 00:00:00 2001 From: Jen Basch Date: Fri, 5 Dec 2025 16:01:09 -0800 Subject: [PATCH] Change `pkl format --write` to exit 0 when formatting violations are found (#1340) --- docs/modules/pkl-cli/pages/index.adoc | 4 ++-- pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/modules/pkl-cli/pages/index.adoc b/docs/modules/pkl-cli/pages/index.adoc index 722db323..bdf7b967 100644 --- a/docs/modules/pkl-cli/pages/index.adoc +++ b/docs/modules/pkl-cli/pages/index.adoc @@ -741,9 +741,9 @@ pkl shell-completion zsh This command formats or checks formatting of Pkl files. + Exit codes: -* 0: No violations found. +* 0: No violations found or files were updated. * 1: An unexpected error happened (ex.: IO error) -* 11: Violations were found. +* 11: Violations were found (when running without `--write`). If the path is a directory, recursively looks for files with a `.pkl` extension, or files named `PklProject`. diff --git a/pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt b/pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt index 64282065..5409413f 100644 --- a/pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt +++ b/pkl-cli/src/main/kotlin/org/pkl/cli/CliFormatterCommand.kt @@ -110,7 +110,6 @@ constructor( val formatted = format(contents) if (contents != formatted) { - status.update(FORMATTING_VIOLATION) if (diffNameOnly || overwrite) { // if `--diff-name-only` or `-w` is specified, only write file names writeLine(pathStr) @@ -118,6 +117,9 @@ constructor( if (overwrite) { path.writeText(formatted, Charsets.UTF_8) + } else { + // only exit on violation for "check" operations, not when overwriting + status.update(FORMATTING_VIOLATION) } }