mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-16 14:18:29 +00:00
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
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import path from 'path';
|
|
import fs from 'fs';
|
|
import process from 'process';
|
|
import { spawn } from 'child_process';
|
|
|
|
// 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', '--show-suggestions'], {
|
|
stdio: ['pipe', 'pipe', 'inherit'],
|
|
});
|
|
cspell.stdin.write(fileList.join('\n'));
|
|
cspell.stdin.end();
|
|
|
|
cspell.stdout.on('data', (data) => {
|
|
console.log(data.toString());
|
|
data
|
|
.toString()
|
|
.split('\n')
|
|
.forEach((line: string) => {
|
|
const match = line.match(regex);
|
|
if (match) {
|
|
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}`,
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
cspell.on('exit', process.exit);
|