mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00

## 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.
70 lines
1.9 KiB
Rust
70 lines
1.9 KiB
Rust
//! This module should probably not exist in this shape or form.
|
|
use crate::codes::Rule;
|
|
use crate::registry::Linter;
|
|
|
|
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)]
|
|
pub struct UpstreamCategoryAndPrefix {
|
|
pub category: &'static str,
|
|
pub prefix: &'static str,
|
|
}
|
|
|
|
const C: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
category: "Convention",
|
|
prefix: "C",
|
|
};
|
|
|
|
const E: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
category: "Error",
|
|
prefix: "E",
|
|
};
|
|
|
|
const R: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
category: "Refactor",
|
|
prefix: "R",
|
|
};
|
|
|
|
const W: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
|
|
category: "Warning",
|
|
prefix: "W",
|
|
};
|
|
|
|
impl Rule {
|
|
pub fn upstream_category(&self, linter: &Linter) -> Option<UpstreamCategoryAndPrefix> {
|
|
let code = linter.code_for_rule(*self).unwrap();
|
|
match linter {
|
|
Linter::Pycodestyle => {
|
|
if code.starts_with('E') {
|
|
Some(E)
|
|
} else if code.starts_with('W') {
|
|
Some(W)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
Linter::Pylint => {
|
|
if code.starts_with('C') {
|
|
Some(C)
|
|
} else if code.starts_with('E') {
|
|
Some(E)
|
|
} else if code.starts_with('R') {
|
|
Some(R)
|
|
} else if code.starts_with('W') {
|
|
Some(W)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Linter {
|
|
pub const fn upstream_categories(&self) -> Option<&'static [UpstreamCategoryAndPrefix]> {
|
|
match self {
|
|
Linter::Pycodestyle => Some(&[E, W]),
|
|
Linter::Pylint => Some(&[C, E, R, W]),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|