File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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!" ) ;
You can’t perform that action at this time.
0 commit comments