mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Fix pylint upstream categories not showing in docs (#10441)
## Summary
The upstream category check here
fd26b29986/crates/ruff_linter/src/upstream_categories.rs (L54-L65)
was not working because the code is actually "E0001" not "PLE0001", I
changed it so it will detect the upstream category correctly.
I also sorted the upstream categories alphabetically, so that the
document generation will be deterministic.
## Test Plan
I compared the diff before and after the change.
This commit is contained in:
parent
fd26b29986
commit
dc021dd4d2
2 changed files with 31 additions and 27 deletions
|
@ -180,8 +180,22 @@ pub(crate) fn generate() -> String {
|
||||||
.map(|rule| (rule.upstream_category(&linter), rule))
|
.map(|rule| (rule.upstream_category(&linter), rule))
|
||||||
.into_group_map();
|
.into_group_map();
|
||||||
|
|
||||||
|
let mut rules_by_upstream_category: Vec<_> = rules_by_upstream_category.iter().collect();
|
||||||
|
|
||||||
|
// Sort the upstream categories alphabetically by prefix.
|
||||||
|
rules_by_upstream_category.sort_by(|(a, _), (b, _)| {
|
||||||
|
a.as_ref()
|
||||||
|
.map(|category| category.prefix)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.cmp(
|
||||||
|
b.as_ref()
|
||||||
|
.map(|category| category.prefix)
|
||||||
|
.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
if rules_by_upstream_category.len() > 1 {
|
if rules_by_upstream_category.len() > 1 {
|
||||||
for (opt, rules) in &rules_by_upstream_category {
|
for (opt, rules) in rules_by_upstream_category {
|
||||||
if opt.is_some() {
|
if opt.is_some() {
|
||||||
let UpstreamCategoryAndPrefix { category, prefix } = opt.unwrap();
|
let UpstreamCategoryAndPrefix { category, prefix } = opt.unwrap();
|
||||||
table_out.push_str(&format!("#### {category} ({prefix})"));
|
table_out.push_str(&format!("#### {category} ({prefix})"));
|
||||||
|
|
|
@ -8,24 +8,9 @@ pub struct UpstreamCategoryAndPrefix {
|
||||||
pub prefix: &'static str,
|
pub prefix: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PLC: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
const C: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
||||||
category: "Convention",
|
category: "Convention",
|
||||||
prefix: "PLC",
|
prefix: "C",
|
||||||
};
|
|
||||||
|
|
||||||
const PLE: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
||||||
category: "Error",
|
|
||||||
prefix: "PLE",
|
|
||||||
};
|
|
||||||
|
|
||||||
const PLR: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
||||||
category: "Refactor",
|
|
||||||
prefix: "PLR",
|
|
||||||
};
|
|
||||||
|
|
||||||
const PLW: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
||||||
category: "Warning",
|
|
||||||
prefix: "PLW",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
||||||
|
@ -33,6 +18,11 @@ const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
||||||
prefix: "E",
|
prefix: "E",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const R: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
||||||
|
category: "Refactor",
|
||||||
|
prefix: "R",
|
||||||
|
};
|
||||||
|
|
||||||
const W: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
const W: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
||||||
category: "Warning",
|
category: "Warning",
|
||||||
prefix: "W",
|
prefix: "W",
|
||||||
|
@ -52,14 +42,14 @@ impl Rule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Linter::Pylint => {
|
Linter::Pylint => {
|
||||||
if code.starts_with("PLC") {
|
if code.starts_with('C') {
|
||||||
Some(PLC)
|
Some(C)
|
||||||
} else if code.starts_with("PLE") {
|
} else if code.starts_with('E') {
|
||||||
Some(PLE)
|
Some(E)
|
||||||
} else if code.starts_with("PLR") {
|
} else if code.starts_with('R') {
|
||||||
Some(PLR)
|
Some(R)
|
||||||
} else if code.starts_with("PLW") {
|
} else if code.starts_with('W') {
|
||||||
Some(PLW)
|
Some(W)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -73,7 +63,7 @@ impl Linter {
|
||||||
pub const fn upstream_categories(&self) -> Option<&'static [UpstreamCategoryAndPrefix]> {
|
pub const fn upstream_categories(&self) -> Option<&'static [UpstreamCategoryAndPrefix]> {
|
||||||
match self {
|
match self {
|
||||||
Linter::Pycodestyle => Some(&[E, W]),
|
Linter::Pycodestyle => Some(&[E, W]),
|
||||||
Linter::Pylint => Some(&[PLC, PLE, PLR, PLW]),
|
Linter::Pylint => Some(&[C, E, R, W]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue