1 | function severity2number(pSeverity) {
|
2 | const SEVERITY2NUMBER = {
|
3 | error: 1,
|
4 | warn: 2,
|
5 | info: 3,
|
6 | ignore: 4,
|
7 | };
|
8 |
|
9 |
|
10 | return SEVERITY2NUMBER[pSeverity] || -1;
|
11 | }
|
12 |
|
13 | function severities(pFirstSeverity, pSecondSeverity) {
|
14 | return Math.sign(
|
15 | severity2number(pFirstSeverity) - severity2number(pSecondSeverity)
|
16 | );
|
17 | }
|
18 |
|
19 | function violations(pFirstViolation, pSecondViolation) {
|
20 | return (
|
21 | severities(pFirstViolation.rule.severity, pSecondViolation.rule.severity) ||
|
22 | pFirstViolation.rule.name.localeCompare(pSecondViolation.rule.name) ||
|
23 | pFirstViolation.from.localeCompare(pSecondViolation.from) ||
|
24 | pFirstViolation.to.localeCompare(pSecondViolation.to)
|
25 | );
|
26 | }
|
27 |
|
28 | function rules(pLeftRule, pRightRule) {
|
29 | return (
|
30 | severities(pLeftRule.severity, pRightRule.severity) ||
|
31 | pLeftRule.name.localeCompare(pRightRule.name)
|
32 | );
|
33 | }
|
34 |
|
35 | module.exports = {
|
36 | severities,
|
37 | violations,
|
38 | rules,
|
39 | };
|