Skip to content

Commit

Permalink
Speed up commit hooks (#287)
Browse files Browse the repository at this point in the history
* Speed up commit hooks

- Use lint-staged to only run prettier / eslint on changed files
- Use vitest's `--changed` flag to only run tests affected by changed files
  • Loading branch information
mbeckem committed Feb 27, 2024
1 parent db79cb6 commit 15d24fa
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 11 deletions.
13 changes: 6 additions & 7 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ fi

. "$(dirname -- "$0")/_/husky.sh"

echo '--- checking for consistent dependencies across packages'
echo '--- checking for consistent dependencies across packages ---'
pnpm lint-shared-versions

echo '--- run prettier ---'
pnpm prettier-check

echo '--- run linting --- '
pnpm lint
echo '--- check code style ---'
pnpm exec lint-staged

echo '--- run typescript check ---'
pnpm check-types

echo '--- run tests ---'
CI=1 pnpm test run # CI=1 disallows `.only` in tests
# CI=1 disallows `.only` in tests
# --changed only runs the tests affected by changed files
CI=1 pnpm exec vitest run --changed --passWithNoTests
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}": ["prettier --write --ignore-path .eslintignore", "eslint"],
"*.{md,json}": ["prettier --write --ignore-path .eslintignore"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build-docs": "typedoc",
"build-license-report": "node --loader ts-node/esm --no-warnings=ExperimentalWarning ./support/create-license-report.ts ",
"preview": "vite preview",
"lint": "eslint ./src ./support --ext .js,.ts,.jsx,.tsx,.mjs,.mts,.cjs,.cts --cache --cache-location ./node_modules/.cache/.eslintcache",
"lint": "eslint ./src ./support --ext .js,.ts,.jsx,.tsx,.mjs,.mts,.cjs,.cts",
"eslint": "pnpm run lint",
"prettier-check": "pnpm prettier:common -c",
"prettier": "pnpm prettier:common -w",
Expand Down Expand Up @@ -117,6 +117,7 @@
"husky": "^8.0.3",
"js-yaml": "^4.1.0",
"jsdom": "^22.1.0",
"lint-staged": "^15.2.2",
"prettier": "^3.1.1",
"resize-observer-polyfill": "^1.5.1",
"rimraf": "^5.0.5",
Expand Down
Loading

0 comments on commit 15d24fa

Please sign in to comment.