mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Add rule removal infrastructure (#9691)
Similar to https://github.com/astral-sh/ruff/pull/9689 — retains removed rules for better error messages and documentation but removed rules _cannot_ be used in any context. Removes PLR1706 as a useful test case and something we want to accomplish in #9680 anyway. The rule was in preview so we do not need to deprecate it first. Closes https://github.com/astral-sh/ruff/issues/9007 ## Test plan <img width="1110" alt="Rules table" src="ac9fa682
-623c-44aa-8e51-d8ab0d308355"> <img width="1110" alt="Rule page" src="05850b2d
-7ca5-49bb-8df8-bb931bab25cd">
This commit is contained in:
parent
a0ef087e73
commit
e0bc08a758
13 changed files with 127 additions and 411 deletions
|
@ -213,6 +213,8 @@ impl RuleSelector {
|
|||
|| (preview_enabled && (matches!(self, RuleSelector::Rule { .. }) || !preview_require_explicit))
|
||||
// Deprecated rules are excluded in preview mode unless explicitly selected
|
||||
|| (rule.is_deprecated() && (!preview_enabled || matches!(self, RuleSelector::Rule { .. })))
|
||||
// Removed rules are included if explicitly selected but will error downstream
|
||||
|| (rule.is_removed() && matches!(self, RuleSelector::Rule { .. }))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -247,6 +249,8 @@ pub struct PreviewOptions {
|
|||
|
||||
#[cfg(feature = "schemars")]
|
||||
mod schema {
|
||||
use std::str::FromStr;
|
||||
|
||||
use itertools::Itertools;
|
||||
use schemars::JsonSchema;
|
||||
use schemars::_serde_json::Value;
|
||||
|
@ -290,6 +294,16 @@ mod schema {
|
|||
(!prefix.is_empty()).then(|| prefix.to_string())
|
||||
})),
|
||||
)
|
||||
.filter(|p| {
|
||||
// Exclude any prefixes where all of the rules are removed
|
||||
if let Ok(Self::Rule { prefix, .. } | Self::Prefix { prefix, .. }) =
|
||||
RuleSelector::from_str(p)
|
||||
{
|
||||
!prefix.rules().all(|rule| rule.is_removed())
|
||||
} else {
|
||||
true
|
||||
}
|
||||
})
|
||||
.sorted()
|
||||
.map(Value::String)
|
||||
.collect(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue