|
| 1 | + |
| 2 | +const template = module.exports = { |
| 3 | + run: (onFinish) => { |
| 4 | + process.stdin.resume(); |
| 5 | + process.stdin.setEncoding("utf8"); |
| 6 | + |
| 7 | + var lingeringLine = ""; |
| 8 | + var lines = []; |
| 9 | + |
| 10 | + process.stdin.on("data", (chunk) => { |
| 11 | + let linesParsed = chunk.split("\n"); |
| 12 | + linesParsed[0] = lingeringLine + linesParsed[0]; |
| 13 | + lingeringLine = linesParsed.pop(); |
| 14 | + linesParsed.forEach((line) => { |
| 15 | + if (line !== null) { |
| 16 | + lines.push(line); |
| 17 | + } |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + process.stdin.on("end", () => { |
| 22 | + onFinish(lines); |
| 23 | + }); |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +const regex = /(.*): line ([0-9]+), col ([0-9]+), (.*) - (.*) \((.*)\)/g; |
| 28 | + |
| 29 | +const reporter = module.exports = { |
| 30 | + run: (regex, convertMatch) => { |
| 31 | + |
| 32 | + const results = []; |
| 33 | + |
| 34 | + /** |
| 35 | + * Generates standard model form each line |
| 36 | + * @param {*} line Line to parse |
| 37 | + */ |
| 38 | + function processLine(line) { |
| 39 | + const match = new RegExp(regex).exec(line); |
| 40 | + |
| 41 | + if (match === null) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + const objParsed = convertMatch(match); |
| 46 | + |
| 47 | + let obj = results.find((element) => { |
| 48 | + return objParsed.path === element.path; |
| 49 | + }); |
| 50 | + |
| 51 | + if (obj === "undefined") { |
| 52 | + obj = { |
| 53 | + path: objParsed.path, |
| 54 | + messages: [], |
| 55 | + }; |
| 56 | + results.push(obj); |
| 57 | + } |
| 58 | + |
| 59 | + obj.messages.push(objParsed.message); |
| 60 | + } |
| 61 | + |
| 62 | + template.run((lines) => { |
| 63 | + lines.forEach(processLine); |
| 64 | + console.log(JSON.stringify(results)); |
| 65 | + }); |
| 66 | + }, |
| 67 | +}; |
| 68 | + |
| 69 | +reporter.run(regex, (match) => { |
| 70 | + return { |
| 71 | + path: match[1], |
| 72 | + message: { |
| 73 | + message: match[5], |
| 74 | + severity: match[4].toLowerCase(), |
| 75 | + line: match[2], |
| 76 | + lineEnd: match[2], |
| 77 | + column: match[3], |
| 78 | + ruleName: match[6], |
| 79 | + }, |
| 80 | + }; |
| 81 | +}); |
0 commit comments