mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Add --exit-non-zero-on-fix
(#2668)
This commit is contained in:
parent
cb4a221905
commit
75fad989f4
3 changed files with 22 additions and 4 deletions
|
@ -475,6 +475,8 @@ Miscellaneous:
|
||||||
The name of the file when passing it through stdin
|
The name of the file when passing it through stdin
|
||||||
-e, --exit-zero
|
-e, --exit-zero
|
||||||
Exit with status code "0", even upon detecting lint violations
|
Exit with status code "0", even upon detecting lint violations
|
||||||
|
--exit-non-zero-on-fix
|
||||||
|
Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain
|
||||||
|
|
||||||
Log levels:
|
Log levels:
|
||||||
-v, --verbose Enable verbose logging
|
-v, --verbose Enable verbose logging
|
||||||
|
|
|
@ -209,8 +209,17 @@ pub struct CheckArgs {
|
||||||
#[arg(long, help_heading = "Miscellaneous")]
|
#[arg(long, help_heading = "Miscellaneous")]
|
||||||
pub stdin_filename: Option<PathBuf>,
|
pub stdin_filename: Option<PathBuf>,
|
||||||
/// Exit with status code "0", even upon detecting lint violations.
|
/// Exit with status code "0", even upon detecting lint violations.
|
||||||
#[arg(short, long, help_heading = "Miscellaneous")]
|
#[arg(
|
||||||
|
short,
|
||||||
|
long,
|
||||||
|
help_heading = "Miscellaneous",
|
||||||
|
conflicts_with = "exit_non_zero_on_fix"
|
||||||
|
)]
|
||||||
pub exit_zero: bool,
|
pub exit_zero: bool,
|
||||||
|
/// Exit with a non-zero status code if any files were modified via
|
||||||
|
/// autofix, even if no lint violations remain.
|
||||||
|
#[arg(long, help_heading = "Miscellaneous", conflicts_with = "exit_zero")]
|
||||||
|
pub exit_non_zero_on_fix: bool,
|
||||||
/// Does nothing and will be removed in the future.
|
/// Does nothing and will be removed in the future.
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
|
@ -334,6 +343,7 @@ impl CheckArgs {
|
||||||
config: self.config,
|
config: self.config,
|
||||||
diff: self.diff,
|
diff: self.diff,
|
||||||
exit_zero: self.exit_zero,
|
exit_zero: self.exit_zero,
|
||||||
|
exit_non_zero_on_fix: self.exit_non_zero_on_fix,
|
||||||
files: self.files,
|
files: self.files,
|
||||||
isolated: self.isolated,
|
isolated: self.isolated,
|
||||||
no_cache: self.no_cache,
|
no_cache: self.no_cache,
|
||||||
|
@ -390,6 +400,7 @@ pub struct Arguments {
|
||||||
pub config: Option<PathBuf>,
|
pub config: Option<PathBuf>,
|
||||||
pub diff: bool,
|
pub diff: bool,
|
||||||
pub exit_zero: bool,
|
pub exit_zero: bool,
|
||||||
|
pub exit_non_zero_on_fix: bool,
|
||||||
pub files: Vec<PathBuf>,
|
pub files: Vec<PathBuf>,
|
||||||
pub isolated: bool,
|
pub isolated: bool,
|
||||||
pub no_cache: bool,
|
pub no_cache: bool,
|
||||||
|
|
|
@ -78,7 +78,6 @@ quoting the executed command, along with the relevant file contents and `pyproje
|
||||||
Command::GenerateShellCompletion { shell } => {
|
Command::GenerateShellCompletion { shell } => {
|
||||||
shell.generate(&mut Args::command(), &mut io::stdout());
|
shell.generate(&mut Args::command(), &mut io::stdout());
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::Check(args) => return check(args, log_level),
|
Command::Check(args) => return check(args, log_level),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,8 +265,14 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitCode> {
|
||||||
if diagnostics.fixed > 0 {
|
if diagnostics.fixed > 0 {
|
||||||
return Ok(ExitCode::FAILURE);
|
return Ok(ExitCode::FAILURE);
|
||||||
}
|
}
|
||||||
} else if !diagnostics.messages.is_empty() {
|
} else if cli.exit_non_zero_on_fix {
|
||||||
return Ok(ExitCode::FAILURE);
|
if diagnostics.fixed > 0 || !diagnostics.messages.is_empty() {
|
||||||
|
return Ok(ExitCode::FAILURE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !diagnostics.messages.is_empty() {
|
||||||
|
return Ok(ExitCode::FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue