From a30c77e75276ae9b9c3fa2279ab8ce4dbf827655 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 2 Feb 2023 23:43:05 -0500 Subject: [PATCH] Mark `--add-noqa` as incompatible with `--fix` (#2513) --- ruff_cli/src/args.rs | 1 + ruff_cli/src/main.rs | 7 +++++-- src/noqa.rs | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ruff_cli/src/args.rs b/ruff_cli/src/args.rs index 39aad884e5..b37db4e0e3 100644 --- a/ruff_cli/src/args.rs +++ b/ruff_cli/src/args.rs @@ -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. diff --git a/ruff_cli/src/main.rs b/ruff_cli/src/main.rs index 23854c2b20..1c86f7a8de 100644 --- a/ruff_cli/src/main.rs +++ b/ruff_cli/src/main.rs @@ -160,9 +160,12 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result { } 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 { 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."); diff --git a/src/noqa.rs b/src/noqa.rs index ec9512bae8..8f65a1e462 100644 --- a/src/noqa.rs +++ b/src/noqa.rs @@ -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());