Skip to content

Commit 69c302c

Browse files
committed
Merge branch 'development' of github.com:thoth-tech/ThothTech-Documentation-Website into development
2 parents 14ca22e + 0dd418e commit 69c302c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

annotate_vale.cjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const warningsFile = '/site/.vale/temp/vale-warnings.json';
5+
6+
// Load Vale JSON output
7+
const data = JSON.parse(fs.readFileSync(warningsFile, 'utf8'));
8+
9+
for (const filePath in data) {
10+
const issues = data[filePath];
11+
12+
// Sort highest to lowest line number so inserts don't shift later lines
13+
issues.sort((a, b) => b.Line - a.Line);
14+
15+
const absPath = path.resolve(filePath);
16+
17+
if (!fs.existsSync(absPath)) {
18+
console.error(`File not found: ${absPath}`);
19+
continue;
20+
}
21+
22+
let lines = fs.readFileSync(absPath, 'utf8').split('\n');
23+
24+
issues.forEach(issue => {
25+
const line = issue.Line;
26+
const check = issue.Check;
27+
const msg = issue.Message;
28+
29+
const comment = `<!-- Vale(${check}): ${msg} -->`;
30+
31+
// Insert comment above the offending line (line numbers are 1-based)
32+
lines.splice(line - 1, 0, comment);
33+
});
34+
35+
fs.writeFileSync(absPath, lines.join('\n'));
36+
console.log(`Annotated: ${filePath}`);
37+
}
38+
39+
console.log("Done!");

0 commit comments

Comments
 (0)