From 7435d3f2abcee6a218a1ecd9d6c681cc171f106e Mon Sep 17 00:00:00 2001 From: Zanie Date: Mon, 29 Jan 2024 12:44:30 -0600 Subject: [PATCH] Error if nursery rules are selected without preview --- crates/ruff/tests/integration_test.rs | 19 +++++------- crates/ruff_workspace/src/configuration.rs | 34 +++++++++++++++++----- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 7aed76fee2df3b..a19b52d464c3c5 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -839,14 +839,12 @@ fn nursery_direct() { assert_cmd_snapshot!(cmd .pass_stdin("I=42\n"), @r###" success: false - exit_code: 1 + exit_code: 2 ----- stdout ----- - -:1:2: E225 [*] Missing whitespace around operator - Found 1 error. - [*] 1 fixable with the `--fix` option. ----- stderr ----- - warning: Selection of nursery rule `E225` without the `--preview` flag is deprecated. + ruff failed + Cause: Selection of unstable rule `E225` without the `--preview` flag is not allowed. "###); } @@ -857,15 +855,12 @@ fn nursery_group_selector() { assert_cmd_snapshot!(cmd .pass_stdin("I=42\n"), @r###" success: false - exit_code: 1 + exit_code: 2 ----- stdout ----- - -:1:1: CPY001 Missing copyright notice at top of file - -:1:2: E225 [*] Missing whitespace around operator - Found 2 errors. - [*] 1 fixable with the `--fix` option. ----- stderr ----- - warning: The `NURSERY` selector has been deprecated. Use the `--preview` flag instead. + ruff failed + Cause: The `NURSERY` selector was removed. Use the `--preview` flag instead. "###); } @@ -883,7 +878,7 @@ fn nursery_group_selector_preview_enabled() { ----- stderr ----- ruff failed - Cause: The `NURSERY` selector is deprecated and cannot be used with preview mode enabled. + Cause: The `NURSERY` selector was removed. Unstable rules should be selected by their respective group or individually. "###); } diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 9cb285a4040b17..2ed9047acb0145 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -863,10 +863,12 @@ impl LintConfiguration { for (kind, selector) in selection.selectors_by_kind() { #[allow(deprecated)] if matches!(selector, RuleSelector::Nursery) { - if preview.mode.is_enabled() { - return Err(anyhow!("The `NURSERY` selector is deprecated and cannot be used with preview mode enabled.")); - } - warn_user_once!("The `NURSERY` selector has been deprecated. Use the `--preview` flag instead."); + let suggestion = if preview.mode.is_disabled() { + " Use the `--preview` flag instead." + } else { + " Unstable rules should be selected individually or by their respective groups." + }; + return Err(anyhow!("The `NURSERY` selector was removed.{suggestion}")); }; // Only warn for the following selectors if used to enable rules @@ -904,9 +906,27 @@ impl LintConfiguration { ); } - for selection in deprecated_nursery_selectors { - let (prefix, code) = selection.prefix_and_code(); - warn_user!("Selection of nursery rule `{prefix}{code}` without the `--preview` flag is deprecated.",); + match deprecated_nursery_selectors + .iter() + .collect::>() + .as_slice() + { + [] => (), + [selection] => { + let (prefix, code) = selection.prefix_and_code(); + return Err(anyhow!("Selection of unstable rule `{prefix}{code}` without the `--preview` flag is not allowed.")); + } + [selections @ ..] => { + let mut message = "Selection of unstable rules without the `--preview` flag is not allowed. Enable preview or remove selection of:".to_string(); + for selection in selections { + let (prefix, code) = selection.prefix_and_code(); + message.push_str("\n\t- "); + message.push_str(prefix); + message.push_str(code) + } + message.push('\n'); + return Err(anyhow!(message)); + } } for selection in ignored_preview_selectors {