From 591a7a152c64ff8ee242d9a252caede82d7a7817 Mon Sep 17 00:00:00 2001 From: Ruben van Eldik <25854734+RubenVanEldik@users.noreply.github.com> Date: Mon, 2 Sep 2024 15:16:06 +0200 Subject: [PATCH] Handle singular case for incompatible rules warning (#13212) Co-authored-by: Micha Reiser --- crates/ruff/src/commands/format.rs | 6 +++++- crates/ruff/tests/format.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index c38da8146f8e4..4ad789d13936c 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -810,7 +810,11 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { .map(|rule| format!("`{}`", rule.noqa_code())) .collect(); rule_names.sort(); - warn_user_once!("The following rules may cause conflicts when used with the formatter: {}. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.", rule_names.join(", ")); + if let [rule] = rule_names.as_slice() { + warn_user_once!("The following rule may cause conflicts when used with the formatter: {rule}. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration."); + } else { + warn_user_once!("The following rules may cause conflicts when used with the formatter: {}. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.", rule_names.join(", ")); + } } // Next, validate settings-specific incompatibilities. diff --git a/crates/ruff/tests/format.rs b/crates/ruff/tests/format.rs index 87f40fedd8a65..ba851e42c24a9 100644 --- a/crates/ruff/tests/format.rs +++ b/crates/ruff/tests/format.rs @@ -785,7 +785,7 @@ if condition: print('Should change quotes') ----- stderr ----- - warning: The following rules may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration. + warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration. "###); Ok(()) }