Skip to content

Commit 104e116

Browse files
romanrostislavovichxferra
authored andcommitted
Implement reporter for csslint engine (#282)
1 parent a57e5b3 commit 104e116

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

engine/csslint/pipe.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://repometric.github.io/linterhub/schema/extr.json",
3+
"id": "csslint",
4+
"name": "csslint",
5+
"pipeline": [
6+
{
7+
"cmd": "csslint",
8+
"success": 1,
9+
"engine": true,
10+
"args": {
11+
"--format":"compact"
12+
}
13+
},
14+
{
15+
"cmd": "node",
16+
"args": "{{hub}}/{{engine}}/reporter.js",
17+
"success": 2
18+
}
19+
],
20+
"environment": {
21+
"masks": false,
22+
"version": "v1.0.5"
23+
}
24+
}

engine/csslint/reporter.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)