Allow legacy C and T selectors in JSON schema (#3889)

This commit is contained in:
Charlie Marsh 2023-04-05 13:58:36 -04:00 committed by GitHub
parent 7b6e55a2e0
commit e0bccfd2d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 31 deletions

View file

@ -207,36 +207,47 @@ impl JsonSchema for RuleSelector {
Schema::Object(SchemaObject { Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()), instance_type: Some(InstanceType::String.into()),
enum_values: Some( enum_values: Some(
std::iter::once("ALL".to_string()) [
.chain( // Include the non-standard "ALL" selector.
RuleCodePrefix::iter() "ALL".to_string(),
.filter(|p| { // Include the legacy "C" and "T" selectors.
// Once logical lines are active by default, please remove this. "C".to_string(),
// This is here because generate-all output otherwise depends on "T".to_string(),
// the feature sets which makes the test running with // Include some common redirect targets for those legacy selectors.
// `--all-features` fail "C9".to_string(),
!Rule::from_code(&format!( "T1".to_string(),
"{}{}", "T2".to_string(),
p.linter().common_prefix(), ]
p.short_code() .into_iter()
)) .chain(
.unwrap() RuleCodePrefix::iter()
.lint_source() .filter(|p| {
.is_logical_lines() // Once logical lines are active by default, please remove this.
}) // This is here because generate-all output otherwise depends on
.map(|p| { // the feature sets which makes the test running with
let prefix = p.linter().common_prefix(); // `--all-features` fail
let code = p.short_code(); !Rule::from_code(&format!(
format!("{prefix}{code}") "{}{}",
}) p.linter().common_prefix(),
.chain(Linter::iter().filter_map(|l| { p.short_code()
let prefix = l.common_prefix(); ))
(!prefix.is_empty()).then(|| prefix.to_string()) .unwrap()
})) .lint_source()
.sorted(), .is_logical_lines()
) })
.map(Value::String) .map(|p| {
.collect(), let prefix = p.linter().common_prefix();
let code = p.short_code();
format!("{prefix}{code}")
})
.chain(Linter::iter().filter_map(|l| {
let prefix = l.common_prefix();
(!prefix.is_empty()).then(|| prefix.to_string())
})),
)
.sorted()
.map(Value::String)
.collect(),
), ),
..SchemaObject::default() ..SchemaObject::default()
}) })

7
ruff.schema.json generated
View file

@ -1438,13 +1438,13 @@
"RuleSelector": { "RuleSelector": {
"type": "string", "type": "string",
"enum": [ "enum": [
"ALL",
"A", "A",
"A0", "A0",
"A00", "A00",
"A001", "A001",
"A002", "A002",
"A003", "A003",
"ALL",
"ANN", "ANN",
"ANN0", "ANN0",
"ANN00", "ANN00",
@ -1518,6 +1518,7 @@
"BLE0", "BLE0",
"BLE00", "BLE00",
"BLE001", "BLE001",
"C",
"C4", "C4",
"C40", "C40",
"C400", "C400",
@ -1537,6 +1538,7 @@
"C415", "C415",
"C416", "C416",
"C417", "C417",
"C9",
"C90", "C90",
"C901", "C901",
"COM", "COM",
@ -2175,8 +2177,11 @@
"SLF0", "SLF0",
"SLF00", "SLF00",
"SLF001", "SLF001",
"T",
"T1",
"T10", "T10",
"T100", "T100",
"T2",
"T20", "T20",
"T201", "T201",
"T203", "T203",