-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgluaLintEx.js
More file actions
74 lines (65 loc) · 1.99 KB
/
Copy pathgluaLintEx.js
File metadata and controls
74 lines (65 loc) · 1.99 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { readFileSync } = require('fs');
const { normalize } = require('path');
const { spawnSync } = require('child_process');
const warningsAreErrors = true;
let errorCount = 0, warningCount = 0;
const gLuaLintRes = spawnSync('glualint', ['.']);
if (gLuaLintRes.status === null) {
errorCount++;
console.error('Interrupted');
process.exit(1);
}
if (gLuaLintRes.status === 0) {
process.exit(0);
}
if (gLuaLintRes.status !== 1) {
errorCount++;
process.exit(gLuaLintRes.status);
}
const errRegExp = /^(.+): \[(Warning|Error)\] line (\d+), column (\d+) - line (\d+), column (\d+): (.+)$/;
const output = gLuaLintRes.stdout.toString().trim().split(/\r?\n/).filter(l => !!l).map(l => l.match(errRegExp)).map(m => ({
file: normalize(m[1]),
type: m[2].toLowerCase(),
lineStart: parseInt(m[3], 10),
columnStart: parseInt(m[4], 10),
lineEnd: parseInt(m[5], 10),
columnEnd: parseInt(m[6], 10),
message: m[7],
}));
const fileCache = {};
for (const o of output) {
fileCache[o.file] = readFileSync(o.file, 'utf8').split(/\r?\n/);
}
const reportErrors = output.filter(o => {
const file = fileCache[o.file]
if (file[0].includes('--glualint:ignore-file')) {
return false;
}
if (file[o.lineStart - 2].includes('--glualint:ignore-next-line')) {
return false;
}
return true;
});
for (const r of reportErrors) {
switch (r.type) {
case 'warning':
if (warningsAreErrors) {
errorCount++;
r.type = 'error';
break;
}
warningCount++;
break;
case 'error':
errorCount++;
break;
}
if (process.env.CI) {
console.log(`::${r.type} file=${r.file},line=${r.lineStart},col=${r.columnStart}::${r.message}`);
}
console.log(`${r.type} ${r.file}:${r.lineStart}:${r.columnStart}-${r.lineEnd}:${r.columnEnd} ${r.message}`);
}
if (errorCount > 0 || warningCount > 0) {
process.exit(1);
}
process.exit(0);