mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +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
|
@ -209,8 +209,17 @@ pub struct CheckArgs {
|
|||
#[arg(long, help_heading = "Miscellaneous")]
|
||||
pub stdin_filename: Option<PathBuf>,
|
||||
/// 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,
|
||||
/// 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.
|
||||
#[arg(
|
||||
long,
|
||||
|
@ -334,6 +343,7 @@ impl CheckArgs {
|
|||
config: self.config,
|
||||
diff: self.diff,
|
||||
exit_zero: self.exit_zero,
|
||||
exit_non_zero_on_fix: self.exit_non_zero_on_fix,
|
||||
files: self.files,
|
||||
isolated: self.isolated,
|
||||
no_cache: self.no_cache,
|
||||
|
@ -390,6 +400,7 @@ pub struct Arguments {
|
|||
pub config: Option<PathBuf>,
|
||||
pub diff: bool,
|
||||
pub exit_zero: bool,
|
||||
pub exit_non_zero_on_fix: bool,
|
||||
pub files: Vec<PathBuf>,
|
||||
pub isolated: bool,
|
||||
pub no_cache: bool,
|
||||
|
|
|
@ -78,7 +78,6 @@ quoting the executed command, along with the relevant file contents and `pyproje
|
|||
Command::GenerateShellCompletion { shell } => {
|
||||
shell.generate(&mut Args::command(), &mut io::stdout());
|
||||
}
|
||||
|
||||
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 {
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
} else if !diagnostics.messages.is_empty() {
|
||||
return Ok(ExitCode::FAILURE);
|
||||
} else if cli.exit_non_zero_on_fix {
|
||||
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