diff --git a/scripts/lintFilenames.mts b/scripts/lintFilenames.mts index 912068be3..9398286d5 100644 --- a/scripts/lintFilenames.mts +++ b/scripts/lintFilenames.mts @@ -3,12 +3,17 @@ import fs from 'fs'; import process from 'process'; import { spawn } from 'child_process'; -const regex = /(?[^:]+):(?\d+):(?\d+)\s-\s+(?.+)/; +// cspell reports stdin entries without a file name, e.g. +// `:1:7 - Unknown word (arow) Suggestions: [alow, arrow]` +const regex = + /(?[^:]*):(?\d+):(?\d+)\s-\s+(?.+?)(?:\s+Suggestions:\s+\[(?[^\]]*)\])?$/; 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}`, + ); } }); });