-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
upstream_categories.rs
80 lines (71 loc) · 2.11 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
71
72
73
74
75
76
77
78
79
80
//! 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 PLC: UpstreamCategoryAndPrefix = UpstreamCategoryAndPrefix {
category: "Convention",
prefix: "PLC",
};
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 {
category: "Error",
prefix: "E",
};
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("PLC") {
Some(PLC)
} else if code.starts_with("PLE") {
Some(PLE)
} else if code.starts_with("PLR") {
Some(PLR)
} else if code.starts_with("PLW") {
Some(PLW)
} else {
None
}
}
_ => None,
}
}
}
impl Linter {
pub const fn upstream_categories(&self) -> Option<&'static [UpstreamCategoryAndPrefix]> {
match self {
Linter::Pycodestyle => Some(&[E, W]),
Linter::Pylint => Some(&[PLC, PLE, PLR, PLW]),
_ => None,
}
}
}