-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathannotate_vale.cjs
More file actions
39 lines (27 loc) · 1006 Bytes
/
annotate_vale.cjs
File metadata and controls
39 lines (27 loc) · 1006 Bytes
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
const fs = require('fs');
const path = require('path');
const warningsFile = '/site/.vale/temp/vale-warnings.json';
// Load Vale JSON output
const data = JSON.parse(fs.readFileSync(warningsFile, 'utf8'));
for (const filePath in data) {
const issues = data[filePath];
// Sort highest to lowest line number so inserts don't shift later lines
issues.sort((a, b) => b.Line - a.Line);
const absPath = path.resolve(filePath);
if (!fs.existsSync(absPath)) {
console.error(`File not found: ${absPath}`);
continue;
}
let lines = fs.readFileSync(absPath, 'utf8').split('\n');
issues.forEach(issue => {
const line = issue.Line;
const check = issue.Check;
const msg = issue.Message;
const comment = `<!-- Vale(${check}): ${msg} -->`;
// Insert comment above the offending line (line numbers are 1-based)
lines.splice(line - 1, 0, comment);
});
fs.writeFileSync(absPath, lines.join('\n'));
console.log(`Annotated: ${filePath}`);
}
console.log("Done!");