Skip to content

Commit

Permalink
Error if the NURSERY selector is used with preview
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jan 29, 2024
1 parent 04000a4 commit 55d2633
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 3 additions & 6 deletions crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,12 @@ fn nursery_group_selector_preview_enabled() {
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.
ruff failed
Cause: The `NURSERY` selector is deprecated and cannot be used with preview mode enabled.
"###);
}

Expand Down
20 changes: 9 additions & 11 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,13 +860,10 @@ impl LintConfiguration {
for (kind, selector) in selection.selectors_by_kind() {
#[allow(deprecated)]
if matches!(selector, RuleSelector::Nursery) {
let suggestion = if preview.mode.is_disabled() {
" Use the `--preview` flag instead."
} else {
// We have no suggested alternative since there is intentionally no "PREVIEW" selector
""
};
warn_user_once!("The `NURSERY` selector has been deprecated.{suggestion}");
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.");
};

// Only warn for the following selectors if used to enable rules
Expand Down Expand Up @@ -1638,7 +1635,8 @@ mod tests {
let expected = RuleSet::from_rules(NURSERY_RULES);
assert_eq!(actual, expected);

let actual = resolve_rules(
// When preview is enabled, use of NURSERY is banned
assert!(resolve_rules(
[RuleSelection {
select: Some(vec![RuleSelector::Nursery]),
..RuleSelection::default()
Expand All @@ -1647,9 +1645,9 @@ mod tests {
mode: PreviewMode::Enabled,
..PreviewOptions::default()
}),
)?;
let expected = RuleSet::from_rules(NURSERY_RULES);
assert_eq!(actual, expected);
)
.is_err());

Ok(())
}

Expand Down

0 comments on commit 55d2633

Please sign in to comment.