Skip to the content.

Git hooks (Husky + lint-staged)

Local quality gates for this monorepo:

Hook When What runs
pre-commit git commit lint-staged: Prettier write (restaged) + Nx-scoped ESLint --fix on staged files via scripts/lint-staged-nx.mjs
pre-push git push npm test (utilities + media-player build/test, then @tgmc/web Vitest)

Lint always includes Prettier, then Nx ESLint:

Script Prettier ESLint
npm run lint prettier -wl . (format) nx run-many -t lint (all packages with lint)
npm run lint:affected prettier -wl . (format) nx affected -t lint
npm run lint:staged / pre-commit prettier --write on staged files scripts/lint-staged-nx.mjs (Nx affected projects → ESLint --fix on staged paths)

Nx lint covers every project that defines a lint target (inferred via @nx/eslint): @tgmc/web, @tgmc/nuxt-layer-base, @tgmc/nuxt-layer-ui, @tgmc/utilities, @tgmc/media-player, @tgmc/web-e2e.

Prettier does not execute on GitHub. eslint-plugin-prettier stays in the ESLint config; when GITHUB_ACTIONS=true, prettier/prettier is set to off so CI does not run Prettier. Formatting is enforced by husky/lint-staged and npm run format locally.

Line endings (LF only)

All text files use LF (\n), never CRLF:

Layer Setting
Prettier "endOfLine": "lf" in .prettierrc
EditorConfig end_of_line = lf in .editorconfig
Git .gitattributes → * text=auto eol=lf

On Windows, set the local clone (not global) so Git does not rewrite checkouts to CRLF:

git config core.autocrlf false
git config core.eol lf

If Prettier/ESLint report Delete ␍, renormalize once: git add --renormalize . then commit the line-ending-only changes (or run npm run format on the affected paths).

Setup

Hooks install automatically via the root prepare script (node scripts/husky-prepare.mjs) after local npm install.

GitHub Actions / CI: Husky must not install or run. Defense in depth:

  1. scripts/husky-prepare.mjs skips when CI, GITHUB_ACTIONS, or HUSKY=0 is set (Actions always provides GITHUB_ACTIONS=true).
  2. Workflows that run npm ci / npm install or git commit set HUSKY: '0' so hook scripts under .husky/ exit immediately if invoked.
  3. Policy coverage: scripts/cicd-workflow-policy.test.mjs + scripts/husky-prepare.test.mjs.
npm install
# equivalent: npm run prepare

Skip hooks for a single local command when needed:

HUSKY=0 git commit -m "..."
HUSKY=0 git push

Manual runs

# Same as pre-commit (against currently staged files)
npm run lint:staged

# Prettier (whole repo) + lint all Nx packages with a lint target
npm run lint

# Prettier (whole repo) + lint projects affected by the working tree
npm run lint:affected

# Format only
npm run format

# Same as pre-push
npm test

Config

Husky 9 hook format

Root depends on husky ^9.1.7. Hook files are plain shell commands — do not keep the v8 bootstrap:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

Those lines print a deprecation warning on every run and will fail in Husky v10. Current hooks:

File Body
.husky/pre-commit npx lint-staged
.husky/pre-push npm test

prepare already runs husky (not deprecated husky install) via scripts/husky-prepare.mjs.

Windows worktrees and the test cache

npm test uses a Node launcher on Windows and Unix, so it does not depend on which bash is first on PATH. It defaults NX_CACHE_DIRECTORY and NX_SOCKET_DIR to the current checkout’s .nx/cache and .nx/sock paths, preserving explicit overrides. Nx otherwise shares its main worktree cache using a Windows extended path (\\?\E:\...), which can fail in a worktree on another drive with EISDIR: illegal operation on a directory, lstat 'E:' while loading the Nx Cloud client. The local path keeps both Nx caching and the pre-push tests enabled. Regression coverage lives in scripts/test-web.test.js. The launcher runs Vitest targets with NODE_ENV=test even if the local .env sets a development value.