-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
40 lines (31 loc) · 834 Bytes
/
index.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
40
'use strict';
const path = require('path');
const jsYaml = require('js-yaml');
const indentString = require('indent-string');
module.exports = results => {
let ret = 'TAP version 13\n';
let total = 0;
for (const result of results) {
const messages = result.messages;
if (messages.length === 0) {
ret += `ok ${++total} ` + path.relative(process.cwd(), result.filePath) + '\n';
continue;
}
ret += messages.map(el => {
let severity = 'warning';
if (el.fatal || el.severity === 2) {
severity = 'error';
}
const block = '---\n' + jsYaml.safeDump({
message: el.message,
severity,
file: result.filePath,
line: el.line || 0,
name: el.ruleId
}) + '...';
return `not ok ${++total}\n${indentString(block, 2)}`;
}).join('\n') + '\n';
}
ret += `1..${total}`;
return ret;
};