forked from IBM/tekton-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
29 lines (25 loc) · 864 Bytes
/
utils.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
const chalk = require('chalk');
const formatLine = (problem) => {
const level = problem.level === 'error' ? `${chalk.red(problem.level)} ` : chalk.yellow(problem.level);
if (problem.loc) {
return `${level} (${problem.loc.startLine},${problem.loc.startColumn},${problem.loc.endLine},${problem.loc.endColumn}): ${problem.message}`;
}
return `${level}: ${problem.message}`;
};
const logProblems = (problems) => {
const groupByFile = problems.reduce((group, problem) => {
group[problem.path] = (group[problem.path] || []).concat(problem);
return group;
}, {});
for (const [file, fileProblems] of Object.entries(groupByFile)) {
console.log(`${chalk.bold(file)}:`);
for (const problem of fileProblems) {
console.log(formatLine(problem));
}
console.log('\n');
}
};
module.exports = {
logProblems,
formatLine,
};