forked from JetBrains/ring-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jslint-xml.js
38 lines (34 loc) · 1.03 KB
/
jslint-xml.js
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
// eslint-disable-next-line no-control-regex
const xmlEscape = s => (`${s}`).replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/g, c => {
switch (c) {
case '<':
return '<';
case '>':
return '>';
case '&':
return '&';
case '"':
return '"';
case '\'':
return ''';
default:
return `&#${c.charCodeAt(0)};`;
}
});
module.exports = results => {
const files = results.map(file => {
const warnings = file.warnings.map(({column, line, text}) => {
const css = file._postcssResult && file._postcssResult.css;
const lines = css && css.split('\n') || [];
const evidence = lines[line - 1];
return [
`<issue line="${line}"`,
` char="${column}"`,
` evidence="${evidence ? xmlEscape(evidence) : ''}"`,
` reason="${xmlEscape(text)}" />`
].join('');
});
return `<file name="${file.source}">${warnings.join('')}</file>`;
});
return `<?xml version="1.0" encoding="utf-8"?><jslint>${files.join('')}</jslint>`;
};