-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
38 lines (29 loc) · 884 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
module.exports = makeTap
var jsonify = require('standard-json')
var yamlish = require('yamlish')
function makeTap (rawtext, opts) {
opts = opts || { complex: false }
var results = jsonify(rawtext)
var ret = '\nTAP version 13\n'
var total = 0
results.forEach(function (result) {
var messages = result.messages
if (messages.length === 0) {
return
}
ret += messages.map(function (el) {
var testName = 'Linter Rule'
if (el.ruleId) testName += ': ' + el.ruleId
return 'not ok ' + (++total) + ' ' + testName + '\n ---' + yamlish.encode({
message: el.message,
severity: 'error',
file: result.filePath,
line: el.line || 0,
name: el.ruleId
}) + '\n ...\n'
}).join('\n') + '\n'
})
ret += '1..' + total
if (opts.complex) return { output: ret, errors: total }
return ret
}