-
Notifications
You must be signed in to change notification settings - Fork 634
/
rule-helpers.ts
52 lines (39 loc) 路 1.23 KB
/
rule-helpers.ts
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
import * as path from 'path';
import * as d from 'debug';
export const getIncludedHeaders = (headers: object = {}, headerList: Array<string> = []) => {
const result = [];
for (const [key] of Object.entries(headers)) {
if (headerList.includes(key.toLowerCase())) {
result.push(key);
}
}
return result;
};
export const getRuleName = (dirname: string) => {
return path.basename(dirname);
};
export const mergeIgnoreIncludeArrays = (originalArray: Array<string> = [], ignoreArray: Array<string> = [], includeArray: Array<string> = []) => {
let result = originalArray.map((e) => {
return e.toLowerCase();
});
const include = includeArray.map((e) => {
return e.toLowerCase();
});
const ignore = ignoreArray.map((e) => {
return e.toLowerCase();
});
// Add elements specified under 'include'.
include.forEach((e) => {
if (!result.includes(e)) {
result.push(e);
}
});
// Remove elements specified under 'ignore'.
result = result.filter((e) => {
return !ignore.includes(e);
});
return result;
};
export const ruleDebug = (dirname: string) => {
return d(`sonar:rules:${getRuleName(dirname)}`);
};