Mark `--add-noqa` as incompatible with `--fix` (#2513)

This commit is contained in:
Charlie Marsh 2023-02-02 23:43:05 -05:00 committed by GitHub
parent 7e9b9cc7b3
commit a30c77e752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View File

@ -237,6 +237,7 @@ pub struct CheckArgs {
conflicts_with = "statistics",
conflicts_with = "stdin_filename",
conflicts_with = "watch",
conflicts_with = "fix",
)]
pub add_noqa: bool,
/// See the files Ruff will be run against with the current settings.

View File

@ -160,9 +160,12 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitCode> {
}
if cli.add_noqa {
if !matches!(autofix, fix::FixMode::None) {
warn_user_once!("--fix is incompatible with --add-noqa.");
}
let modifications = commands::add_noqa(&cli.files, &pyproject_strategy, &overrides)?;
if modifications > 0 && log_level >= LogLevel::Default {
println!("Added {modifications} noqa directives.");
eprintln!("Added {modifications} noqa directives.");
}
return Ok(ExitCode::SUCCESS);
}
@ -171,7 +174,7 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitCode> {
if cli.watch {
if !matches!(autofix, fix::FixMode::None) {
warn_user_once!("--fix is not enabled in watch mode.");
warn_user_once!("--fix is unsupported in watch mode.");
}
if format != SerializationFormat::Text {
warn_user_once!("--format 'text' is used in watch mode.");

View File

@ -196,7 +196,6 @@ fn add_noqa_inner(
output.push_str(line_ending);
}
Directive::Codes(_, start_byte, _, existing) => {
println!("existing: {:?}", existing);
// Reconstruct the line based on the preserved rule codes.
// This enables us to tally the number of edits.
let mut formatted = String::with_capacity(line.len());