From b3e509b7d4548a7f440b0cabbb1459e1ab0c3ff2 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sun, 5 Feb 2023 19:25:57 +0000 Subject: [PATCH 1/2] build(lint): cache eslint with strategy content Cache eslint using `--cache-strategy content` instead of the default `--cache-strategy metadata`. By default, `eslint` uses the file metadata (e.g. modification time) to detect when the cache should be invalidated. However, this is not efficient with `git`, since git constantly changes the modification time, e.g. running `git switch main && git switch original-branch` would not change the file contents, but would change the file mtimes and force eslint to re-lint everything. Using the file contents is slower (~3% for me), but more resilient. See https://eslint.org/docs/latest/use/command-line-interface#--cache-strategy --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f6130fa47..e7cb9bdf0 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "build": "pnpm run -r clean && concurrently \"pnpm build:vite\" \"pnpm build:types\"", "dev": "concurrently \"pnpm build:vite --watch\" \"ts-node-esm .vite/server.ts\"", "release": "pnpm build", - "lint": "eslint --cache --ignore-path .gitignore . && pnpm lint:jison && prettier --cache --check .", + "lint": "eslint --cache --cache-strategy content --ignore-path .gitignore . && pnpm lint:jison && prettier --cache --check .", "lint:fix": "eslint --fix --ignore-path .gitignore . && prettier --write . && ts-node-esm scripts/fixCSpell.ts", "lint:jison": "ts-node-esm ./scripts/jison/lint.mts", "cypress": "cypress run", From 98b21483528b528bd011d7a3a116d633239045c8 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sun, 5 Feb 2023 19:01:01 +0000 Subject: [PATCH 2/2] build(pre-commit): cache eslint in pre-commit Run eslint with `--cache` to speed up pre-commit scripts. This was added to the `pnpm run lint` script in b7f9495a (build: add eslint --cache file, 2022-08-27) and doesn't seem to be causing any issues. I haven't enabled `--cache` for `prettier` since as of prettier 2.8.0, their cache invalidation doesn't yet work with prettier plugins. --- .lintstagedrc.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.lintstagedrc.mjs b/.lintstagedrc.mjs index ff1d8c107..ac2623093 100644 --- a/.lintstagedrc.mjs +++ b/.lintstagedrc.mjs @@ -1,5 +1,11 @@ export default { - '!(docs/**/*)*.{ts,js,json,html,md,mts}': ['eslint --fix', 'prettier --write'], + '!(docs/**/*)*.{ts,js,json,html,md,mts}': [ + 'eslint --cache --cache-strategy content --fix', + // don't cache prettier yet, since we use `prettier-plugin-jsdoc`, + // and prettier doesn't invalidate cache on plugin updates" + // https://prettier.io/docs/en/cli.html#--cache + 'prettier --write', + ], 'cSpell.json': ['ts-node-esm scripts/fixCSpell.ts'], '**/*.jison': ['pnpm -w run lint:jison'], };