Files
lucide/scripts/lintSpelling.mts
55b9969b82 ci(lint): split lint jobs and annotate Prettier and JSON schema errors in PRs (#4982)
* ci: split lint-code into ESLint, Prettier and JSON Schema jobs with PR annotations

- ESLint: annotations via setup-node's built-in eslint-stylish problem matcher.
- Prettier: new scripts/lintFormat.mts formats unformatted files in memory, diffs
  them and emits line-level `::error` annotations with the expected code.
- JSON Schema: replace ajv-cli with a local ESLint rule (Ajv draft 2020-12) that
  validates icons/categories JSON against their `$schema` and reports at the
  offending property. eslint-plugin-json-schema-validator was not used because it
  runs Ajv in draft-07 mode and ignores `dependentRequired`.

All annotations use workflow commands, so they work on fork PRs with a read-only token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* Improve root value check and property error handling

Enhance error reporting for JSON schema validation.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* style(lint): format jsonSchemaPlugin with Prettier

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* test commit

* fix(lint): annotate syntax errors from Prettier and ESLint in PRs

- ESLint/JSON Schema jobs use a small GitHub formatter that prints `::error`
  workflow commands. setup-node's eslint-stylish matcher skipped parsing errors
  because they have no rule id.
- lintFormat.mts annotates Prettier syntax errors (exit code 2) at their line and
  column instead of only printing stderr, and still checks the other files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* ci(lint): spell check icon and category metadata with cspell annotations

- New "Spelling" job runs scripts/lintSpelling.mts, which turns cspell findings
  into `::error` annotations (with cspell's suggested fix when it has one).
- cspell accepts both US and British English, ignores contributor usernames and
  deprecated `alias.typo` aliases.
- Add existing search tags and domain terms to .cspell/custom-words.txt so the
  current metadata passes.
- Add `lint:spelling` to `pnpm lint` and lint-staged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* fix(lint): pin JSON schemas per file set and drop typo tags

- json-schema/no-invalid now takes the schema from config (icon.schema.json for
  icons, category.schema.json for categories) and reports a `$schema` that
  points elsewhere, so metadata can't opt out of validation.
- Remove the misspelled `frigerator` and `sterisk` tags and their allowlist entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* fix(icons): split joined-word tags into separate words

Tags like `groupchat` and `timemachine` become `group chat` and `time machine`
so they read naturally and pass the spell check without allowlisting. Where the
spaced tag already existed (`smart home`) the joined one is dropped.

cspell now skips all alias names, since they are icon names that can't change
(e.g. the deprecated `palmtree` alias).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FVxEtqNswEDq1N23taZYh8

* Revert

* Try another error

* Revert error

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-10-09 11:30:00 +02:00

58 lines
2.1 KiB
TypeScript

/**
* Spell checks icon and category metadata with cspell and reports every unknown word as a GitHub
* Actions annotation (`::error file=…,line=…`), so it shows up inline in the PR diff.
*
* Words that are correct but unknown to cspell go in `.cspell/custom-words.txt`.
*/
import process from 'process';
import { spawnSync } from 'child_process';
import { fileURLToPath } from 'url';
const PATTERNS = ['icons/*.json', 'categories/*.json'];
// cspell only exports its bin for `import`, so resolve it the ESM way.
const cspellBin = fileURLToPath(import.meta.resolve('cspell/bin.mjs'));
const cspell = spawnSync(
process.execPath,
[cspellBin, '--no-color', '--no-progress', '--no-summary', ...PATTERNS],
{ encoding: 'utf-8', maxBuffer: 64 * 1024 * 1024 },
);
/** Escape data for a workflow command, see https://github.com/actions/toolkit/blob/main/packages/core/src/command.ts */
const escapeData = (value: string) =>
value.replaceAll('%', '%25').replaceAll('\r', '%0D').replaceAll('\n', '%0A');
const escapeProperty = (value: string) =>
escapeData(value).replaceAll(':', '%3A').replaceAll(',', '%2C');
const issue = /^(.+?):(\d+):(\d+) - Unknown word \((.+?)\)(?: fix: \((.+?)\))?/;
let problems = 0;
for (const line of cspell.stdout.split('\n')) {
const match = line.match(issue);
if (!match) continue;
const [, file, lineNumber, column, word, fix] = match;
const suggestion = fix ? ` Did you mean "${fix}"?` : '';
const message = `Unknown word "${word}".${suggestion} Fix the typo or add the word to .cspell/custom-words.txt.`;
console.log(line);
console.log(
`::error file=${escapeProperty(file)},line=${lineNumber},col=${column},endColumn=${Number(column) + word.length},title=cspell::${escapeData(message)}`,
);
problems++;
}
if (cspell.status !== 0 && problems === 0) {
process.stderr.write(cspell.stderr);
console.log(`::error title=cspell::${escapeData(cspell.stderr.trim() || 'cspell failed.')}`);
process.exit(cspell.status ?? 1);
}
if (problems > 0) {
console.log(`\n${problems} spelling issue(s) found.`);
process.exit(1);
}
console.log('No spelling issues found.');