From 999b6ef39934d0c942b0fdce5f67e20e3101609d Mon Sep 17 00:00:00 2001 From: Ruben van Eldik Date: Mon, 2 Sep 2024 13:37:34 +0200 Subject: [PATCH 1/5] Handle singular case for incompatible rules warning - Updated the code to call `warn_user_once!` twice, handling both singular and plural cases separately. - Ensures the warning message is grammatically correct when only one incompatible rule is present. --- 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..1ede02047a902 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 rule_names.len() == 1 { + warn_user_once!("The following rule may cause conflicts when used with the formatter: {}. 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.", rule_names.join(", ")); + } 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(()) } From 24f362eb05286e5a288e781aeb756ceddc7761bc Mon Sep 17 00:00:00 2001 From: Ruben van Eldik <25854734+RubenVanEldik@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:46:53 +0200 Subject: [PATCH 2/5] Update crates/ruff/src/commands/format.rs Co-authored-by: Micha Reiser --- crates/ruff/src/commands/format.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index 1ede02047a902..25f2f1397744a 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -810,8 +810,8 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { .map(|rule| format!("`{}`", rule.noqa_code())) .collect(); rule_names.sort(); - if rule_names.len() == 1 { - warn_user_once!("The following rule may cause conflicts when used with the formatter: {}. 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.", 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(", ")); } From 789d8c6f56e7e77451e617e92dfc631649f31619 Mon Sep 17 00:00:00 2001 From: Ruben van Eldik <25854734+RubenVanEldik@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:53:27 +0200 Subject: [PATCH 3/5] Fix a small typo --- crates/ruff/src/commands/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index 25f2f1397744a..6318fde62aa8f 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -810,7 +810,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { .map(|rule| format!("`{}`", rule.noqa_code())) .collect(); rule_names.sort(); - if let [rule] == rule_names.as_slice() { + 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(", ")); From bc4bdd6b70d83ec831b73e4a5de78a1f45589cbd Mon Sep 17 00:00:00 2001 From: Ruben van Eldik <25854734+RubenVanEldik@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:56:46 +0200 Subject: [PATCH 4/5] Fix another small typo --- crates/ruff/src/commands/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index 6318fde62aa8f..addc7a265c17b 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -810,7 +810,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { .map(|rule| format!("`{}`", rule.noqa_code())) .collect(); rule_names.sort(); - if let [rule] = rule_names.as_slice() { + 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(", ")); From a1e573463a9e16c3d8261dea3e4cb3ac5515a4c8 Mon Sep 17 00:00:00 2001 From: Ruben van Eldik Date: Mon, 2 Sep 2024 14:06:30 +0200 Subject: [PATCH 5/5] Change the tabs to spaces --- crates/ruff/src/commands/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruff/src/commands/format.rs b/crates/ruff/src/commands/format.rs index addc7a265c17b..4ad789d13936c 100644 --- a/crates/ruff/src/commands/format.rs +++ b/crates/ruff/src/commands/format.rs @@ -810,7 +810,7 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) { .map(|rule| format!("`{}`", rule.noqa_code())) .collect(); rule_names.sort(); - if let [rule] = rule_names.as_slice() { + 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(", "));