diff --git a/cspell.json b/cspell.json index 3526c192c..b6d708a89 100644 --- a/cspell.json +++ b/cspell.json @@ -3,7 +3,6 @@ "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", "words": [ "ACMR", - "actionlint", "Alexa", "Amjad", "Andrey", @@ -22,7 +21,6 @@ "autocrlf", "autodetects", "autofix", - "autogenerated", "autolinks", "autoload", "autoloaded", @@ -58,7 +56,6 @@ "codemirror", "codemod", "codemods", - "combinator", "commonmark", "compat", "concating", @@ -79,7 +76,6 @@ "desugared", "devcontainer", "devs", - "docblock", "docblocks", "doctag", "Dodds", @@ -103,14 +99,12 @@ "esproposal", "estree", "esutils", - "eval", "execa", "fbglyph", "Ficarra", "Filipe", "Fiorini", "Fisker", - "fnames", "foldgutter", "formatprg", "Friedly", @@ -125,7 +119,6 @@ "globby", "gofmt", "Gregor", - "gtag", "Hampus", "hardline", "hardlines", @@ -183,9 +176,7 @@ "linearize", "linebreak", "linebreaks", - "linenumbers", "literalline", - "Literallines", "loglevel", "lowercased", "lowercasing", @@ -212,7 +203,6 @@ "mousedown", "mouseup", "mprettier", - "msapplication", "multiparser", "Muntean", "nargs", @@ -285,7 +275,6 @@ "Sapegin", "sbdchd", "scandir", - "schemastore", "Serializers", "setlocal", "setq", @@ -357,10 +346,8 @@ "Weixin", "whitespaces", "wxss", - "xargs", "yamafaktory", "Yatharth", - "youtube", "Zatorski", "Zosel" ], @@ -403,4 +390,4 @@ "website/static/lib/**", "website/static/playground.js" ] -} +} \ No newline at end of file diff --git a/scripts/clean-cspell.mjs b/scripts/clean-cspell.mjs index eaa4ea01a..05c3979c6 100644 --- a/scripts/clean-cspell.mjs +++ b/scripts/clean-cspell.mjs @@ -6,37 +6,40 @@ import execa from "execa"; const CSPELL_CONFIG_FILE = new URL("../cspell.json", import.meta.url); const updateConfig = (config) => fs.writeFile(CSPELL_CONFIG_FILE, JSON.stringify(config, undefined, 4)); -const runSpellcheck = () => execa("yarn", ["lint:spellcheck"]); +const runSpellcheck = (options) => { + const { yarnArgs, args, execaOptions } = { + yarnArgs: [], + args: [], + ...options, + }; + return execa("yarn", [...yarnArgs, "lint:spellcheck", ...args], execaOptions); +}; (async () => { console.log("Empty words ..."); const config = JSON.parse(await fs.readFile(CSPELL_CONFIG_FILE, "utf8")); - const oldWords = config.words; + const original = config.words; await updateConfig({ ...config, words: [] }); console.log("Running spellcheck with empty words ..."); - try { - await runSpellcheck(); - } catch ({ stdout }) { - let words = [...stdout.matchAll(/ - Unknown word \((.*?)\)/g)].map( - ([, word]) => word - ); - // Unique - words = [...new Set(words)]; + const { stdout } = await runSpellcheck({ + yarnArgs: ["--silent"], + args: ["--words-only", "--unique"], + execaOptions: { reject: false }, + }); + + const words = stdout + .split("\n") // Remove upper case word, if lower case one already exists - words = words.filter((word) => { + .filter((word, _, words) => { const lowerCased = word.toLowerCase(); return lowerCased === word || !words.includes(lowerCased); - }); + }) // Compare function from https://github.com/streetsidesoftware/vscode-spell-checker/blob/2fde3bc5c658ee51da5a56580aa1370bf8174070/packages/client/src/settings/CSpellSettings.ts#L78 - words = words.sort((a, b) => - a.toLowerCase().localeCompare(b.toLowerCase()) - ); - config.words = words; - } + .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())); + config.words = words; - const newWords = config.words; - const removed = oldWords.filter((word) => !newWords.includes(word)); + const removed = original.filter((word) => !words.includes(word)); if (removed.length > 0) { console.log( `${removed.length} words removed: \n${removed @@ -44,7 +47,7 @@ const runSpellcheck = () => execa("yarn", ["lint:spellcheck"]); .join("\n")}` ); } - const added = newWords.filter((word) => !oldWords.includes(word)); + const added = words.filter((word) => !original.includes(word)); if (added.length > 0) { console.log( `${added.length} words added: \n${added @@ -57,9 +60,7 @@ const runSpellcheck = () => execa("yarn", ["lint:spellcheck"]); await updateConfig(config); console.log("Running spellcheck with new words ..."); - const subprocess = runSpellcheck(); - subprocess.stdout.pipe(process.stdout); - await subprocess; + await runSpellcheck({ execaOptions: { stdout: "inherit" } }); console.log("CSpell config file updated."); })().catch((error) => {