Warn instead of error when removed rules are used in ignore (#14435)

Closes https://github.com/astral-sh/ruff/issues/13505
This commit is contained in:
Micha Reiser 2024-11-19 08:36:46 +01:00
parent dc05b38165
commit 52f526eb38
5 changed files with 125 additions and 1 deletions

View file

@ -775,6 +775,7 @@ impl LintConfiguration {
let mut redirects = FxHashMap::default();
let mut deprecated_selectors = FxHashSet::default();
let mut removed_selectors = FxHashSet::default();
let mut removed_ignored_rules = FxHashSet::default();
let mut ignored_preview_selectors = FxHashSet::default();
// Track which docstring rules are specifically enabled
@ -926,7 +927,11 @@ impl LintConfiguration {
// Removed rules
if selector.is_exact() {
if selector.all_rules().all(|rule| rule.is_removed()) {
removed_selectors.insert(selector);
if kind.is_disable() {
removed_ignored_rules.insert(selector);
} else {
removed_selectors.insert(selector);
}
}
}
@ -968,6 +973,20 @@ impl LintConfiguration {
}
}
if !removed_ignored_rules.is_empty() {
let mut rules = String::new();
for selection in removed_ignored_rules.iter().sorted() {
let (prefix, code) = selection.prefix_and_code();
rules.push_str("\n - ");
rules.push_str(prefix);
rules.push_str(code);
}
rules.push('\n');
warn_user_once_by_message!(
"The following rules have been removed and ignoring them has no effect:{rules}"
);
}
for (from, target) in redirects.iter().sorted_by_key(|item| item.0) {
// TODO(martin): This belongs into the ruff crate.
warn_user_once_by_id!(