mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Add warnings for nursery and preview rule selection (#7210)
## Summary Adds warnings for cases where: - A selector does not include any rules because preview is disabled - A nursery rule is selected without the preview flag ## Test plan Add integration tests
This commit is contained in:
parent
1373e1c395
commit
ebd1b296fd
2 changed files with 229 additions and 3 deletions
|
@ -27,7 +27,7 @@ use ruff::settings::types::{
|
|||
Version,
|
||||
};
|
||||
use ruff::settings::{defaults, resolve_per_file_ignores, AllSettings, CliSettings, Settings};
|
||||
use ruff::{fs, warn_user_once_by_id, RuleSelector, RUFF_PKG_VERSION};
|
||||
use ruff::{fs, warn_user, warn_user_once, warn_user_once_by_id, RuleSelector, RUFF_PKG_VERSION};
|
||||
use ruff_cache::cache_dir;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use shellexpand;
|
||||
|
@ -460,7 +460,10 @@ impl Configuration {
|
|||
let mut carryover_ignores: Option<&[RuleSelector]> = None;
|
||||
let mut carryover_unfixables: Option<&[RuleSelector]> = None;
|
||||
|
||||
// Store selectors for displaying warnings
|
||||
let mut redirects = FxHashMap::default();
|
||||
let mut deprecated_nursery_selectors = FxHashSet::default();
|
||||
let mut ignored_preview_selectors = FxHashSet::default();
|
||||
|
||||
for selection in &self.rule_selections {
|
||||
// If a selection only specifies extend-select we cannot directly
|
||||
|
@ -571,8 +574,7 @@ impl Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
// We insert redirects into the hashmap so that we
|
||||
// can warn the users about remapped rule codes.
|
||||
// Check for selections that require a warning
|
||||
for selector in selection
|
||||
.select
|
||||
.iter()
|
||||
|
@ -583,6 +585,29 @@ impl Configuration {
|
|||
.chain(selection.unfixable.iter())
|
||||
.chain(selection.extend_fixable.iter())
|
||||
{
|
||||
#[allow(deprecated)]
|
||||
if matches!(selector, RuleSelector::Nursery) {
|
||||
let suggestion = if preview.is_disabled() {
|
||||
"Use the `--preview` flag instead."
|
||||
} else {
|
||||
"Use the `PREVIEW` selector instead."
|
||||
};
|
||||
warn_user_once!("The `NURSERY` selector has been deprecated. {suggestion}");
|
||||
}
|
||||
|
||||
if preview.is_disabled() {
|
||||
if let RuleSelector::Rule { prefix, .. } = selector {
|
||||
if prefix.rules().any(|rule| rule.is_nursery()) {
|
||||
deprecated_nursery_selectors.insert(selector);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the selector is empty because preview mode is disabled
|
||||
if selector.rules(PreviewMode::Disabled).next().is_none() {
|
||||
ignored_preview_selectors.insert(selector);
|
||||
}
|
||||
}
|
||||
|
||||
if let RuleSelector::Prefix {
|
||||
prefix,
|
||||
redirected_from: Some(redirect_from),
|
||||
|
@ -603,6 +628,18 @@ impl Configuration {
|
|||
);
|
||||
}
|
||||
|
||||
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.",);
|
||||
}
|
||||
|
||||
for selection in ignored_preview_selectors {
|
||||
let (prefix, code) = selection.prefix_and_code();
|
||||
warn_user!(
|
||||
"Selection `{prefix}{code}` has no effect because the `--preview` flag was not included.",
|
||||
);
|
||||
}
|
||||
|
||||
let mut rules = RuleTable::empty();
|
||||
|
||||
for rule in select_set {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue