From f475a5bd43053379e571d4b2cb76b5fa7d4615ac Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sun, 12 Apr 2020 01:19:00 +0800 Subject: [PATCH] Update spellcheck config and scripts (#8012) Co-authored-by: Georgii Dolzhykov --- cspell.json | 138 ++++++------------ package.json | 2 +- scripts/clean-cspell.js | 49 +++++++ tests_integration/__tests__/early-exit.js | 6 +- .../level3-glob/shouldNotBeFormat.js | 2 +- .../level1-glob/shouldNotBeIgnored.js | 2 +- .../level1/level2/level3/shouldNotBeFormat.js | 2 +- .../shouldNotBeIgnored.js | 2 +- 8 files changed, 106 insertions(+), 97 deletions(-) create mode 100644 scripts/clean-cspell.js diff --git a/cspell.json b/cspell.json index 484e550b6..da1722257 100644 --- a/cspell.json +++ b/cspell.json @@ -8,7 +8,6 @@ "animationend", "ansible", "apos", - "aquibm", "arduner", "arrayify", "Artem", @@ -24,15 +23,14 @@ "autogenerated", "autolink", "autolinks", + "autoload", + "autoloaded", "autoloading", "Azzola", "backport", "backticks", - "bakkot", "behaviour", "Bekkelund", - "belochub", - "benjie", "Bento", "bigint", "binaryish", @@ -41,8 +39,7 @@ "blenda", "blockquote's", "bookmarklet", - "bopomofo", - "brainkim", + "Bopomofo", "Breakell", "Brevik", "bugfix", @@ -55,7 +52,6 @@ "chrzosel", "Clemmons", "cliify", - "cloudflare", "cmds", "codebases", "codeblock", @@ -70,15 +66,15 @@ "cond", "cosmiconfig", "CRLFs", + "crossorigin", "daleroy", "danez", - "dangmai", "Dara", "dashify", - "dcyriller", "declarators", "dedent", "defun", + "deltice", "deopt", "deps", "destructured", @@ -86,10 +82,13 @@ "devs", "docblock", "docblocks", + "doctag", + "Docusaurus's", "Dodds", "Dolzhykov", "dotfile", "dotfiles", + "downlevel", "duailibe", "Duperron", "editorconfig", @@ -97,59 +96,51 @@ "elektronik", "Eneman", "ENOENT", - "ericsakmar", "Ericsburgh", "errored", "Esben", "esbenp", - "eslint's", "eslump", "esproposal", "estree", "esutils", "eval", - "evilebottnawi", "execa", "fbglyph", + "FBID", "Ficarra", "filepath", "Filipe", "finalizer", "Fiorini", - "flxwu", "fnames", "formatprg", "Friedly", + "frobble", "fuzzer", - "gavinjoyce", "Georgii", "gettin", "git's", "gitattributes", "githook", - "gitignore", "gitkeep", - "Gitter", + "gitter", "glimmerjs", "globbing", "globby", "gofmt", - "googlegroups", - "googlemaps", "Gregor", - "hackily", - "haggholm", + "gtag", "Hampus", "hardcoded", "hardline", "hardlines", - "harel", "hashbang", "Hawken", "Hengles", "Hersevoort", + "hljs", "hlsson", - "hongrich", "Horky", "hotpink", "hsla", @@ -160,15 +151,14 @@ "iarna", "ICSS", "idempotence", - "IIFE", + "iife", "IIFEs", "ikatyang", "Ilya", "impltype", "importee", "importmap", - "indentable", - "indexof", + "Indentable", "infc", "instanceof", "Intelli", @@ -176,55 +166,40 @@ "jackyho", "Jakefile", "jakegavin", - "jbrown", "jetbrains", "jlongster", - "jnwng", "Joar", "josephfrazier", - "Joun", - "jounqin", - "jridgewell", - "jscodefmt", "jsesc", "jsfmt", "JSXs", - "junit", - "jwbay", - "kachkaev", "kalmanb", "Karimov", "Kassens", "Kasturi", "Kearney", - "keyof", "Khatri", - "koba", "lcov", "libdef", "linearize", "linebreak", "linebreaks", "literalline", - "literallines", - "lockfile", + "Literallines", "loglevel", "lowercased", "lowercasing", "lydell", "macos", - "malcolmsgroves", "Marek", "Masad", "Matejka", "Mateusz", - "mattiaerre", - "matzkoh", - "MDAST", - "memberish", + "mdast", + "Memberish", "memoized", "Michał", - "microsyntax", + "Microsyntax", "Mikael", "minimise", "miniprettier", @@ -238,23 +213,24 @@ "mousedown", "mouseup", "mprettier", + "msapplication", "multiparser", "Muntean", "nargs", + "navbutton", "neoclide", "neoformat", "neovim", + "netrc", "nicolo", "nnoremap", - "nodir", "noncharacters", "nonenumerable", - "nonspacing", + "Nonspacing", "noopener", "noreferrer", "normalise", "normalised", - "nrvtbfux", "nullability", "nullish", "Nuno", @@ -262,8 +238,6 @@ "octicon", "Okazaki", "Okonetchnikov", - "oneth", - "onurtemizkan", "onwarn", "Oopsy", "overparenthesization", @@ -271,7 +245,6 @@ "packagejson", "Panasenko", "Pangsakulyanont", - "papayawhip", "paren", "parens", "parentless", @@ -279,25 +252,23 @@ "pcss", "Pierzchała", "Pieter", - "pomber", "postprocess", "postprocessor", "precache", "precommit", "prefetch", "preorder", - "Prettier's", + "prettier's", "Prettier’s", "prettierformatsource", "prettiergetsupportinfo", "prettierignore", "prettierrc", - "prettylint", + "probot", "progid", "promisify", "proto", "quasis", - "quux", "Raghuvir", "Rasmus", "Rattray", @@ -307,19 +278,18 @@ "readlines", "rebalance", "rebeccapurple", + "Rects", "recurse", "recurses", "refmt", "regexes", - "reimplement", - "repo", + "Reimplement", "repo's", + "REPONAME", "repos", - "reselect", "rhengles", "ribaudo", - "roadmap", - "rreverser", + "Roadmap", "ruleset", "rulesets", "sandhose", @@ -327,49 +297,37 @@ "sbdchd", "scandir", "schemastore", - "serializer", - "serializers", - "serviceworker", + "Serializers", "setlocal", "setq", - "shellscape", "shellsession", "Shigeaki", - "Shinigami", "Simen", - "simonhaenisch", "singleline", "skratchdot", - "smirea", "socio", "softline", "softlines", "Sorin", - "sosukesuzuki", - "squidfunk", "srcset", "Stachowiak", "staged's", "standalones", "Stankiewicz", - "stringify", - "stubailo", + "starturl", "styleguides", "stylelint", "stylelintrc", + "subfolder", "subvalue", "suchipi", "superset", "supertypes", - "swac", - "systemjs", - "tdeekens", "templating", "tempy", "testname", - "tgriesser", "tidelift", - "tidelift’s", + "Tidelift’s", "tldr", "Tomasek", "Tradeshift", @@ -377,31 +335,26 @@ "TSAs", "tsep", "TSJS", - "Typeahead", + "typeahead", "typecasted", "typecheck", "typeof", - "udbff", - "udfff", "ufffe", "uffff", "Umidbek", "unaries", - "uncheck", + "Uncheck", "uncook", + "unibeautify", "unignore", - "uniqby", "unist", - "unmount", + "Unmount", "unparenthesised", "unparenthesized", "unparseable", "unpause", - "unpkg", - "unrestrict", - "unstage", + "Unrestrict", "unstaged", - "untracked", "valourous", "Vanderwerff", "vanguarding", @@ -414,31 +367,34 @@ "Vue's", "Wadler", "Wadler's", - "warrenseine", "webstorm", "whitespaces", "xargs", "yamafaktory", "Yatharth", - "youtube", - "yuchi", "Zatorski", - "Zeit", - "zimme", "Zosel" ], "ignoreRegExpList": [ "\\n(`{3,})\\w*\\n[\\s\\S]+?\\1", - "\\[@\\w+?\\]", + "\\[(\\*{2})?@\\w+?\\1\\]", "\\[`\\w+`\\]", "ve{2,}r{2,}y", "ve+r+y+long\\w*", "\\/.*?\\/" ], "ignorePaths": [ + "cspell.json", "**/node_modules/**", + "**/yarn.lock", + "{coverage,dist,.cache,.git,.vscode,.DS_Store,tests}/**/*", + "!tests/**/jsfmt.spec.js", + "*.{log,svg,snap}", + "test.*", + "website/data/users.yml", "website/build/**", "website/playground/codeSamples.js", + "website/pages/googlefe164a33bda4034b.html", "website/static/lib/**", "website/static/playground.js" ] diff --git a/package.json b/package.json index 1c8d548c8..2b086417c 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "lint:changelog": "node ./scripts/lint-changelog.js", "lint:prettier": "prettier \"**/*.{md,json,yml,html,css}\" --check", "lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2016 \"dist/!(bin-prettier|index|third-party).js\"", - "lint:spellcheck": "cspell {bin,scripts,src,website}/**/*.js {docs,website/blog,changelog_unreleased}/**/*.md", + "lint:spellcheck": "cspell \"**/*\" \".github/**/*\"", "lint:deps": "node ./scripts/check-deps.js", "build": "node --max-old-space-size=3072 ./scripts/build/build.js", "build-docs": "node ./scripts/build-docs.js" diff --git a/scripts/clean-cspell.js b/scripts/clean-cspell.js new file mode 100644 index 000000000..df3577649 --- /dev/null +++ b/scripts/clean-cspell.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +"use strict"; + +const fs = require("fs"); +const path = require("path"); +const execa = require("execa"); + +const CSPELL_CONFIG_FILE = path.join(__dirname, "../cspell.json"); + +const updateConfig = (config) => + fs.writeFileSync(CSPELL_CONFIG_FILE, JSON.stringify(config, undefined, 4)); + +(async () => { + console.log("Empty words ..."); + const config = JSON.parse(fs.readFileSync(CSPELL_CONFIG_FILE, "utf8")); + updateConfig({ ...config, words: [] }); + + console.log("Running spellcheck with empty words ..."); + try { + await execa("yarn lint:spellcheck"); + } catch ({ stdout }) { + let words = [...stdout.matchAll(/ - Unknown word \((.*?)\)/g)].map( + ([, word]) => word + ); + // Unique + words = [...new Set(words)]; + // Remove upper case word, if lower case one already exists + words = words.filter((word) => { + 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; + } + + console.log("Updating words ..."); + updateConfig(config); + + console.log("Running spellcheck with new words ..."); + const subprocess = execa("yarn lint:spellcheck"); + subprocess.stdout.pipe(process.stdout); + await subprocess; + + console.log("CSpell config file updated."); +})(); diff --git a/tests_integration/__tests__/early-exit.js b/tests_integration/__tests__/early-exit.js index 0e1372fa0..4554d2eef 100644 --- a/tests_integration/__tests__/early-exit.js +++ b/tests_integration/__tests__/early-exit.js @@ -51,7 +51,11 @@ describe("throw error with --help not-found", () => { }); describe("show warning with --help not-found (typo)", () => { - runPrettier("cli", ["--help", "parserr"]).test({ + runPrettier("cli", [ + "--help", + // cspell:disable-next-line + "parserr", + ]).test({ status: 0, }); }); diff --git a/tests_integration/cli/ignore-relative-path/level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js b/tests_integration/cli/ignore-relative-path/level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js index bfb31636f..3bef913c9 100644 --- a/tests_integration/cli/ignore-relative-path/level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js +++ b/tests_integration/cli/ignore-relative-path/level1-glob/level2-glob/level3-glob/shouldNotBeFormat.js @@ -1 +1 @@ -var x = 'this should not be formatterd'; +var x = 'this should not be formatted'; diff --git a/tests_integration/cli/ignore-relative-path/level1-glob/shouldNotBeIgnored.js b/tests_integration/cli/ignore-relative-path/level1-glob/shouldNotBeIgnored.js index 1be88ca76..1d3de6815 100644 --- a/tests_integration/cli/ignore-relative-path/level1-glob/shouldNotBeIgnored.js +++ b/tests_integration/cli/ignore-relative-path/level1-glob/shouldNotBeIgnored.js @@ -1,2 +1,2 @@ -var x = 'this should be formatterd'; +var x = 'this should be formatted'; diff --git a/tests_integration/cli/ignore-relative-path/level1/level2/level3/shouldNotBeFormat.js b/tests_integration/cli/ignore-relative-path/level1/level2/level3/shouldNotBeFormat.js index bfb31636f..3bef913c9 100644 --- a/tests_integration/cli/ignore-relative-path/level1/level2/level3/shouldNotBeFormat.js +++ b/tests_integration/cli/ignore-relative-path/level1/level2/level3/shouldNotBeFormat.js @@ -1 +1 @@ -var x = 'this should not be formatterd'; +var x = 'this should not be formatted'; diff --git a/tests_integration/cli/ignore-relative-path/shouldNotBeIgnored.js b/tests_integration/cli/ignore-relative-path/shouldNotBeIgnored.js index 1be88ca76..1d3de6815 100644 --- a/tests_integration/cli/ignore-relative-path/shouldNotBeIgnored.js +++ b/tests_integration/cli/ignore-relative-path/shouldNotBeIgnored.js @@ -1,2 +1,2 @@ -var x = 'this should be formatterd'; +var x = 'this should be formatted';