fix(scripts): show cspell suggestions in filename lint annotations

cspell reports stdin entries with an empty file name, so the previous regex
never matched and no ::error annotations were emitted. Allow the empty file
name and include cspell's suggestions in the annotation message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WWiYD36q9Zg9sRvGLHn4q3
This commit is contained in:
Claude
2026-10-09 08:49:41 +00:00
parent 692baa141d
commit 5010b289f3
+12 -4
View File
@@ -3,12 +3,17 @@ import fs from 'fs';
import process from 'process';
import { spawn } from 'child_process';
const regex = /(?<file>[^:]+):(?<line>\d+):(?<column>\d+)\s-\s+(?<message>.+)/;
// cspell reports stdin entries without a file name, e.g.
// `:1:7 - Unknown word (arow) Suggestions: [alow, arrow]`
const regex =
/(?<file>[^:]*):(?<line>\d+):(?<column>\d+)\s-\s+(?<message>.+?)(?:\s+Suggestions:\s+\[(?<suggestions>[^\]]*)\])?$/;
const fileList = process.env.CHANGED_FILES
? (process.env.CHANGED_FILES || '').split(' ')
: fs.readdirSync('./icons').map((fileName) => path.join('./icons', fileName));
const cspell = spawn('npx', ['cspell', 'stdin'], { stdio: ['pipe', 'pipe', 'inherit'] });
const cspell = spawn('npx', ['cspell', 'stdin', '--show-suggestions'], {
stdio: ['pipe', 'pipe', 'inherit'],
});
cspell.stdin.write(fileList.join('\n'));
cspell.stdin.end();
@@ -20,8 +25,11 @@ cspell.stdout.on('data', (data) => {
.forEach((line: string) => {
const match = line.match(regex);
if (match) {
const { line, message } = match.groups ?? {};
console.log(`::error file=${fileList[Number(line) - 1]},line=1,column=1::${message}`);
const { line, message, suggestions } = match.groups ?? {};
const hint = suggestions ? ` Did you mean: ${suggestions}?` : '';
console.log(
`::error file=${fileList[Number(line) - 1]},line=1,column=1::${message}.${hint}`,
);
}
});
});