forked from ascendancyy/vue-cli-plugin-stylelint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstylelintError.js
39 lines (35 loc) · 968 Bytes
/
stylelintError.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
39
const chalk = require('chalk');
const TYPE = 'stylelint-error';
exports.transformer = (error) => {
const { originalStack } = error;
const match = originalStack.some(({ fileName }) => (
fileName
&& fileName.indexOf('stylelint-webpack-plugin') > 0
));
if (match) {
return { ...error, type: TYPE };
}
return error;
};
function severityColor(severity) {
switch (severity.toLowerCase()) {
case 'success': return 'green';
case 'info': return 'blue';
case 'note': return 'white';
case 'warning': return 'yellow';
case 'error': return 'red';
default: return 'red';
}
}
exports.formatter = (errors, severity) => {
// eslint-disable-next-line no-param-reassign
errors = errors.filter((e) => e.type === TYPE);
if (errors.length > 0) {
return [
'',
chalk`{bgMagenta.white stylelint } {${severityColor(severity)} ${severity}}`,
...errors.map(({ message }) => message),
];
}
return [];
};