-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathindex.mjs
57 lines (45 loc) · 1.57 KB
/
index.mjs
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
53
54
55
56
57
/**
* @see https://github.com/stylelint/stylelint/blob/8fefd145f86b74f182286550675881c47b164fba/lib/formatters/githubFormatter.mjs
*
* @license MIT https://github.com/stylelint/stylelint/blob/main/LICENSE
*/
import preprocessWarnings from './preprocess-warnings.mjs';
/**
* @see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
*
* @type {import('stylelint').Formatter}
*/
export default function githubFormatter(results, returnValue) {
const title = 'Stylelint problem';
const metadata = returnValue.ruleMetadata;
const lines = results.flatMap((result) => {
const { source, warnings } = preprocessWarnings(result);
return warnings.map(({ line, column, endLine, endColumn, text, severity, rule }) => {
const msg = buildMessage(text, metadata[rule]);
return endLine === undefined
? `::${severity} file=${source},line=${line},col=${column},title=${title}::${msg}`
: `::${severity} file=${source},line=${line},col=${column},endLine=${endLine},endColumn=${endColumn},title=${title}::${msg}`;
});
});
lines.push('');
return lines.join('\n');
}
/**
* @param {string} msg
* @param {Partial<import('stylelint').RuleMeta> | undefined} metadata
* @returns {string}
*/
function buildMessage(msg, metadata) {
if (!metadata) {
return msg;
}
const url = metadata.url ? ` - ${metadata.url}` : '';
let additional = [
metadata.fixable ? 'maybe fixable' : '',
metadata.deprecated ? 'deprecated' : '',
]
.filter(Boolean)
.join(', ');
additional = additional ? ` [${additional}]` : '';
return `${msg}${additional}${url}`;
}