mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Filter off-by-default RUF014 out of schema (#5832)
**Summary** Previously, `RUF014` would be part of ruff.schema.json depending on whether or not the `unreachable-code` feature was active. This caused problems for contributors who got unrelated RUF014 changes when updating the schema without the feature active. An alternative would be to always add `RUF014`. **Test plan** `cargo dev generate-all` and `cargo run --bin ruff_dev --features unreachable-code -- generate-all` now have the same effect.
This commit is contained in:
parent
598549d24e
commit
a459d8ffc7
4 changed files with 29 additions and 18 deletions
|
@ -782,7 +782,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Ruff, "011") => (RuleGroup::Unspecified, rules::ruff::rules::StaticKeyDictComprehension),
|
||||
(Ruff, "012") => (RuleGroup::Unspecified, rules::ruff::rules::MutableClassDefault),
|
||||
(Ruff, "013") => (RuleGroup::Unspecified, rules::ruff::rules::ImplicitOptional),
|
||||
#[cfg(feature = "unreachable-code")]
|
||||
#[cfg(feature = "unreachable-code")] // When removing this feature gate, also update rules_selector.rs
|
||||
(Ruff, "014") => (RuleGroup::Nursery, rules::ruff::rules::UnreachableCode),
|
||||
(Ruff, "015") => (RuleGroup::Unspecified, rules::ruff::rules::UnnecessaryIterableAllocationForFirstElement),
|
||||
(Ruff, "016") => (RuleGroup::Unspecified, rules::ruff::rules::InvalidIndexType),
|
||||
|
|
|
@ -249,6 +249,9 @@ mod schema {
|
|||
(!prefix.is_empty()).then(|| prefix.to_string())
|
||||
})),
|
||||
)
|
||||
// Filter out rule gated behind `#[cfg(feature = "unreachable-code")]`, which is
|
||||
// off-by-default
|
||||
.filter(|prefix| prefix != "RUF014")
|
||||
.sorted()
|
||||
.map(Value::String)
|
||||
.collect(),
|
||||
|
@ -342,7 +345,15 @@ mod clap_completion {
|
|||
let prefix = l.common_prefix();
|
||||
(!prefix.is_empty()).then(|| PossibleValue::new(prefix).help(l.name()))
|
||||
})
|
||||
.chain(RuleCodePrefix::iter().map(|p| {
|
||||
.chain(
|
||||
RuleCodePrefix::iter()
|
||||
// Filter out rule gated behind `#[cfg(feature = "unreachable-code")]`, which is
|
||||
// off-by-default
|
||||
.filter(|p| {
|
||||
format!("{}{}", p.linter().common_prefix(), p.short_code())
|
||||
!= "RUF014"
|
||||
})
|
||||
.map(|p| {
|
||||
let prefix = p.linter().common_prefix();
|
||||
let code = p.short_code();
|
||||
|
||||
|
@ -359,7 +370,8 @@ mod clap_completion {
|
|||
} else {
|
||||
value
|
||||
}
|
||||
})),
|
||||
}),
|
||||
),
|
||||
),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ mod tests {
|
|||
|
||||
use super::{main, Args};
|
||||
|
||||
#[cfg_attr(not(feature = "unreachable-code"), test)]
|
||||
#[test]
|
||||
fn test_generate_json_schema() -> Result<()> {
|
||||
let mode = if env::var("RUFF_UPDATE_SCHEMA").as_deref() == Ok("1") {
|
||||
Mode::Write
|
||||
|
|
1
ruff.schema.json
generated
1
ruff.schema.json
generated
|
@ -2409,7 +2409,6 @@
|
|||
"RUF011",
|
||||
"RUF012",
|
||||
"RUF013",
|
||||
"RUF014",
|
||||
"RUF015",
|
||||
"RUF016",
|
||||
"RUF1",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue