UNPKG

972 BJavaScriptView Raw
1function severity2number(pSeverity) {
2 const SEVERITY2NUMBER = {
3 error: 1,
4 warn: 2,
5 info: 3,
6 ignore: 4,
7 };
8
9 // eslint-disable-next-line security/detect-object-injection
10 return SEVERITY2NUMBER[pSeverity] || -1;
11}
12
13function severities(pFirstSeverity, pSecondSeverity) {
14 return Math.sign(
15 severity2number(pFirstSeverity) - severity2number(pSecondSeverity)
16 );
17}
18
19function 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
28function rules(pLeftRule, pRightRule) {
29 return (
30 severities(pLeftRule.severity, pRightRule.severity) ||
31 pLeftRule.name.localeCompare(pRightRule.name)
32 );
33}
34
35module.exports = {
36 severities,
37 violations,
38 rules,
39};