forked from astral-sh/ruff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upstream_categories.rs
70 lines (63 loc) · 1.86 KB
/
upstream_categories.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! 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,
}
}
}