-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
35 lines (29 loc) · 825 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
module.exports = jsonify
function jsonify (rawtext, opts) {
opts = opts || { noisey: false }
const lines = rawtext.split('\n')
if (lines[lines.length - 1] === '') lines.pop()
const results = []
const resultMap = {}
lines.forEach(function (line) {
const re = /\s*([A-Za-z]:)?([^:]+):([^:]+):([^:]+): (.*?)( \((.*)\))?$/.exec(line)
if (!re) return opts.noisey ? console.error(line) : null
if (re[1] === undefined) re[1] = ''
const filePath = re[1] + re[2]
let result = resultMap[filePath]
if (!result) {
result = resultMap[filePath] = {
filePath: re[1] + re[2],
messages: []
}
results.push(result)
}
result.messages.push({
line: re[3],
column: re[4],
message: re[5].trim(),
ruleId: re[7]
})
})
return results
}