From 3ad17b79a666c431d899ef850750182d5edd63e4 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 4 Nov 2022 01:41:03 +0530 Subject: [PATCH 1/4] CSpell format --- .lintstagedrc.json | 3 +- bin/checkCSpell.sh | 5 ++ cSpell.json | 127 ++++++++++++++++---------------- packages/mermaid/src/Diagram.ts | 2 +- 4 files changed, 71 insertions(+), 66 deletions(-) create mode 100755 bin/checkCSpell.sh diff --git a/.lintstagedrc.json b/.lintstagedrc.json index c43f5f89fe..17b627b379 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,3 +1,4 @@ { - "!(docs/**/*)*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"] + "!(docs/**/*)*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"], + "cSpell.json": ["./bin/checkCSpell.sh"] } diff --git a/bin/checkCSpell.sh b/bin/checkCSpell.sh new file mode 100755 index 0000000000..bacc2bb93d --- /dev/null +++ b/bin/checkCSpell.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +jq ".words|=(. | map(ascii_downcase) | sort | unique)" cSpell.json > cSpell.temp.json +npx prettier --write cSpell.temp.json +mv cSpell.temp.json cSpell.json \ No newline at end of file diff --git a/cSpell.json b/cSpell.json index b6bf26fa46..873de93e71 100644 --- a/cSpell.json +++ b/cSpell.json @@ -2,84 +2,83 @@ "version": "0.2", "language": "en", "words": [ + "acyclicer", + "adamiecki", + "alois", + "antiscript", + "applitools", + "asciidoctor", + "ashish", + "astah", + "bbox", + "bilkent", + "bisheng", "blockquotes", + "brolin", + "codedoc", + "colour", + "cpettitt", "customizability", - "Gantt", + "cuzon", + "cytoscape", + "dagre", + "descr", + "docsify", + "docsy", + "doku", + "dompurify", + "edgechromium", + "faber", + "flatmap", + "gantt", + "gitea", + "gitgraph", + "graphlib", + "grav", + "greywolf", + "inkdrop", + "jaoude", "jison", - "mermiad", - "mindmap", - "Mindmaps", - "mitigations", - "sandboxed", - "shiki", - "verdana", - "Visio" - ], - "ignoreWords": [ - "Alois", - "Klink", + "kaufmann", + "klemm", + "klink", "knsv", - "Knut", - "Matthieu", - "Sidharth", - "Sveidqvist", - "Vinod", - "Faber", - "Orlandoni", - "Klemm", - "Mindaugas", - "Laganeckas", - "Cuzon", - "Yash", - "Adamiecki", - "applitools", - "Asciidoctor", - "Astah", - "Bisheng", - "codedoc", - "Docsy", - "Doku", - "Gitea", - "Gitgraph", - "Grav", - "Inkdrop", - "Jaoude", + "knut", + "laganeckas", + "lucida", + "matthieu", "mdbook", "mermerd", + "mindaugas", + "mindmap", + "mindmaps", + "mitigations", "mkdocs", + "orlandoni", "phpbb", - "Plantuml", - "Playfair's", - "Podlite", + "plantuml", + "playfair", + "podlite", + "ranksep", "redmine", + "sandboxed", + "setupgraphviewbox", + "shiki", + "sidharth", "sphinxcontrib", - "Tuleap", - "dagre", - "vitepress", - "docsify", - "colour", - "graphlib", - "acyclicer", - "ranksep", - "descr", + "statediagram", "substate", - "Ashish", - "bbox", + "sveidqvist", "techn", - "cytoscape", - "Lucida", - "Bilkent", - "cpettitt", - "antiscript", "ts-nocheck", - "setupGraphViewbox", - "flatmap", - "Kaufmann", + "tuleap", + "verdana", "viewports", - "edgechromium", - "statediagram", - "Brolin", - "Greywolf" + "vinod", + "visio", + "vitepress", + "xlink", + "yash" ], "patterns": [ { diff --git a/packages/mermaid/src/Diagram.ts b/packages/mermaid/src/Diagram.ts index d6c226cdee..f0adf33a4f 100644 --- a/packages/mermaid/src/Diagram.ts +++ b/packages/mermaid/src/Diagram.ts @@ -55,7 +55,7 @@ export class Diagram { } handleError(error: unknown, parseError?: ParseErrorFunction) { - // Is this the correct way to access mermiad's parseError() + // Is this the correct way to access mermaid's parseError() // method ? (or global.mermaid.parseError()) ? if (parseError === undefined) { From e7369acaea111e24c43f30b367ae7e1513870283 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 4 Nov 2022 02:05:50 +0530 Subject: [PATCH 2/4] jq -> node --- .lintstagedrc.json | 2 +- bin/checkCSpell.sh | 5 ----- bin/checkCSpell.ts | 17 +++++++++++++++++ cSpell.json | 23 ++++------------------- packages/mermaid/src/docs.mts | 9 +-------- 5 files changed, 23 insertions(+), 33 deletions(-) delete mode 100755 bin/checkCSpell.sh create mode 100644 bin/checkCSpell.ts diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 17b627b379..e626b461c7 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,4 +1,4 @@ { "!(docs/**/*)*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"], - "cSpell.json": ["./bin/checkCSpell.sh"] + "cSpell.json": ["ts-node-esm bin/checkCSpell.ts"] } diff --git a/bin/checkCSpell.sh b/bin/checkCSpell.sh deleted file mode 100755 index bacc2bb93d..0000000000 --- a/bin/checkCSpell.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -jq ".words|=(. | map(ascii_downcase) | sort | unique)" cSpell.json > cSpell.temp.json -npx prettier --write cSpell.temp.json -mv cSpell.temp.json cSpell.json \ No newline at end of file diff --git a/bin/checkCSpell.ts b/bin/checkCSpell.ts new file mode 100644 index 0000000000..3616d39e09 --- /dev/null +++ b/bin/checkCSpell.ts @@ -0,0 +1,17 @@ +import { readFileSync, writeFileSync } from 'node:fs'; +import prettier from 'prettier'; + +const filepath = './cSpell.json'; +const cSpell: { words: string[] } = JSON.parse(readFileSync(filepath, 'utf8')); + +cSpell.words = [...new Set(cSpell.words.map((word) => word.toLowerCase()))]; +cSpell.words.sort((a, b) => a.localeCompare(b)); + +const prettierConfig = prettier.resolveConfig.sync(filepath) ?? {}; +writeFileSync( + filepath, + prettier.format(JSON.stringify(cSpell), { + ...prettierConfig, + filepath, + }) +); diff --git a/cSpell.json b/cSpell.json index 873de93e71..e31a77fc00 100644 --- a/cSpell.json +++ b/cSpell.json @@ -81,11 +81,7 @@ "yash" ], "patterns": [ - { - "name": "Markdown links", - "pattern": "\\((.*)\\)", - "description": "" - }, + { "name": "Markdown links", "pattern": "\\((.*)\\)", "description": "" }, { "name": "Markdown code blocks", "pattern": "/^(\\s*`{3,}).*[\\s\\S]*?^\\1/gmx", @@ -96,25 +92,14 @@ "pattern": "\\`([^\\`\\r\\n]+?)\\`", "description": "https://stackoverflow.com/questions/41274241/how-to-capture-inline-markdown-code-but-not-a-markdown-code-fence-with-regex" }, - { - "name": "Link contents", - "pattern": "\\", - "description": "" - }, - { - "name": "Snippet references", - "pattern": "-- snippet:(.*)", - "description": "" - }, + { "name": "Link contents", "pattern": "\\", "description": "" }, + { "name": "Snippet references", "pattern": "-- snippet:(.*)", "description": "" }, { "name": "Snippet references 2", "pattern": "\\<\\[sample:(.*)", "description": "another kind of snippet reference" }, - { - "name": "Multi-line code blocks", - "pattern": "/^\\s*```[\\s\\S]*?^\\s*```/gm" - }, + { "name": "Multi-line code blocks", "pattern": "/^\\s*```[\\s\\S]*?^\\s*```/gm" }, { "name": "HTML Tags", "pattern": "<[^>]*>", diff --git a/packages/mermaid/src/docs.mts b/packages/mermaid/src/docs.mts index 96f5e9024c..5d7175a866 100644 --- a/packages/mermaid/src/docs.mts +++ b/packages/mermaid/src/docs.mts @@ -61,14 +61,7 @@ const LOGMSG_COPIED = `, and copied to ${FINAL_DOCS_DIR}`; const WARN_DOCSDIR_DOESNT_MATCH = `Changed files were transformed in ${SOURCE_DOCS_DIR} but do not match the files in ${FINAL_DOCS_DIR}. Please run 'pnpm --filter mermaid run docs:build' after making changes to ${SOURCE_DOCS_DIR} to update the ${FINAL_DOCS_DIR} directory with the transformed files.`; -// TODO: Read from .prettierrc? -const prettierConfig: prettier.Config = { - useTabs: false, - tabWidth: 2, - endOfLine: 'auto', - printWidth: 100, - singleQuote: true, -}; +const prettierConfig = prettier.resolveConfig.sync('.') ?? {}; let filesWereTransformed = false; From daa85b4279ac62de19ecea5c3c3c84f20e648900 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Fri, 4 Nov 2022 02:09:14 +0530 Subject: [PATCH 3/4] rename file --- .lintstagedrc.json | 2 +- bin/{checkCSpell.ts => fixCSpell.ts} | 0 package.json | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename bin/{checkCSpell.ts => fixCSpell.ts} (100%) diff --git a/.lintstagedrc.json b/.lintstagedrc.json index e626b461c7..10899e59d6 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,4 +1,4 @@ { "!(docs/**/*)*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"], - "cSpell.json": ["ts-node-esm bin/checkCSpell.ts"] + "cSpell.json": ["ts-node-esm bin/fixCSpell.ts"] } diff --git a/bin/checkCSpell.ts b/bin/fixCSpell.ts similarity index 100% rename from bin/checkCSpell.ts rename to bin/fixCSpell.ts diff --git a/package.json b/package.json index 15bfcbada6..20c8acba42 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dev": "concurrently \"pnpm build:vite --watch\" \"ts-node-esm .vite/server.ts\"", "release": "pnpm build", "lint": "eslint --cache --ignore-path .gitignore . && pnpm --filter mermaid run lint:jison && prettier --check .", - "lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write .", + "lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write . && ts-node-esm bin/fixCSpell.ts", "cypress": "cypress run", "cypress:open": "cypress open", "e2e": "start-server-and-test dev http://localhost:9000/ cypress", From 1304e8b00b8d7e2731460257d0ea69c7ccaafe43 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Mon, 7 Nov 2022 14:06:35 +0530 Subject: [PATCH 4/4] chore: Move from bin to scripts. --- .lintstagedrc.json | 2 +- package.json | 2 +- {bin => scripts}/fixCSpell.ts | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) rename {bin => scripts}/fixCSpell.ts (76%) diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 10899e59d6..863473f2ad 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,4 +1,4 @@ { "!(docs/**/*)*.{ts,js,json,html,md,mts}": ["eslint --fix", "prettier --write"], - "cSpell.json": ["ts-node-esm bin/fixCSpell.ts"] + "cSpell.json": ["ts-node-esm scripts/fixCSpell.ts"] } diff --git a/package.json b/package.json index 20c8acba42..0881fa3f2e 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "dev": "concurrently \"pnpm build:vite --watch\" \"ts-node-esm .vite/server.ts\"", "release": "pnpm build", "lint": "eslint --cache --ignore-path .gitignore . && pnpm --filter mermaid run lint:jison && prettier --check .", - "lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write . && ts-node-esm bin/fixCSpell.ts", + "lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write . && ts-node-esm scripts/fixCSpell.ts", "cypress": "cypress run", "cypress:open": "cypress open", "e2e": "start-server-and-test dev http://localhost:9000/ cypress", diff --git a/bin/fixCSpell.ts b/scripts/fixCSpell.ts similarity index 76% rename from bin/fixCSpell.ts rename to scripts/fixCSpell.ts index 3616d39e09..1d15e21940 100644 --- a/bin/fixCSpell.ts +++ b/scripts/fixCSpell.ts @@ -1,3 +1,10 @@ +/** + * Sorts all the `words` in the cSpell.json file. + * + * Run from the same folder as the `cSpell.json` file + * (i.e. the root of the Mermaid project). + */ + import { readFileSync, writeFileSync } from 'node:fs'; import prettier from 'prettier';