Skip to content

Commit b71cc37

Browse files
Change --fix-only exit semantics to mirror --fix (#4146)
1 parent 7171281 commit b71cc37

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

BREAKING_CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Breaking Changes
22

3+
## 0.0.265
4+
5+
### `--fix-only` now exits with a zero exit code, unless `--exit-non-zero-on-fix` is specified ([#4146](https://github.com/charliermarsh/ruff/pull/4146))
6+
7+
Previously, `--fix-only` would exit with a non-zero exit code if any fixes were applied. This
8+
behavior was inconsistent with `--fix`, and further, meant that `--exit-non-zero-on-fix` was
9+
effectively ignored when `--fix-only` was specified.
10+
11+
Now, `--fix-only` will exit with a zero exit code, unless `--exit-non-zero-on-fix` is specified,
12+
in which case it will exit with a non-zero exit code if any fixes were applied.
13+
314
## 0.0.260
415

516
### Fixes are now represented as a list of edits ([#3709](https://github.com/charliermarsh/ruff/pull/3709))

crates/ruff_cli/src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,33 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
278278
}
279279

280280
if !cli.exit_zero {
281-
if cli.diff || fix_only {
281+
if cli.diff {
282+
// If we're printing a diff, we always want to exit non-zero if there are
283+
// any fixable violations (since we've printed the diff, but not applied the
284+
// fixes).
282285
if !diagnostics.fixed.is_empty() {
283286
return Ok(ExitStatus::Failure);
284287
}
285-
} else if cli.exit_non_zero_on_fix {
286-
if !diagnostics.fixed.is_empty() || !diagnostics.messages.is_empty() {
287-
return Ok(ExitStatus::Failure);
288+
} else if fix_only {
289+
// If we're only fixing, we want to exit zero (since we've fixed all fixable
290+
// violations), unless we're explicitly asked to exit non-zero on fix.
291+
if cli.exit_non_zero_on_fix {
292+
if !diagnostics.fixed.is_empty() {
293+
return Ok(ExitStatus::Failure);
294+
}
288295
}
289296
} else {
290-
if !diagnostics.messages.is_empty() {
291-
return Ok(ExitStatus::Failure);
297+
// If we're running the linter (not just fixing), we want to exit non-zero if
298+
// there are any violations, unless we're explicitly asked to exit zero on
299+
// fix.
300+
if cli.exit_non_zero_on_fix {
301+
if !diagnostics.fixed.is_empty() || !diagnostics.messages.is_empty() {
302+
return Ok(ExitStatus::Failure);
303+
}
304+
} else {
305+
if !diagnostics.messages.is_empty() {
306+
return Ok(ExitStatus::Failure);
307+
}
292308
}
293309
}
294310
}

0 commit comments

Comments
 (0)