stylelint-formatter-codeclimate
Version:
A CodeClimate compatible formatter for Stylelint
48 lines (47 loc) • 1.28 kB
JavaScript
import { createHash } from 'node:crypto';
const severityMap = {
error: 'major',
warning: 'minor',
};
const createItem = (path, line, column, rule, description, severity) => {
const parts = [
path,
line,
column,
rule,
];
return {
categories: [
'Style',
],
check_name: rule,
description,
fingerprint: createHash('sha256').update(parts.join('::')).digest('hex'),
location: {
lines: {
begin: line,
end: line,
},
path,
},
severity,
type: 'issue',
};
};
export const formatter = (results) => {
const items = [];
results.forEach(({ source, warnings, parseErrors }) => {
if (warnings) {
warnings.forEach(({ line, column, rule, text, severity }) => {
items.push(createItem(source, line, column, rule, text, severityMap[severity]));
});
}
if (parseErrors) {
parseErrors.forEach(({ line, column, text }) => {
items.push(createItem(source, line, column, 'parse-error', text, 'blocker'));
});
}
});
return JSON.stringify(items);
};
export default formatter;