lefthook and package.json had parallel command definitions for the
same tools (oxlint, oxfmt, cspell). Consolidate by making lefthook
call the npm scripts, with staged files passed via the
LEFTHOOK_FILES env var. The scripts use ${LEFTHOOK_FILES:-<default>}
so they default to the full project when invoked manually and to
the staged-files list when invoked from lefthook.
Changes:
- package.json#check:oxlint: `oxlint ${LEFTHOOK_FILES:-src}`
(lints src/ manually; staged files from lefthook)
- package.json#check:oxfmt: `oxfmt --check ${LEFTHOOK_FILES:-src}`
- package.json#check:cspell: `cspell lint ${LEFTHOOK_FILES:-.}`
(walks CWD manually; staged files from lefthook)
- package.json#check:tsc, check📦 unchanged (no file args)
- lefthook.yml: file-filtered hooks (oxlint, oxfmt, cspell) now use
`sh -c 'LEFTHOOK_FILES="$0" npm run check:*' {staged_files}` to
inject the staged-files list into the env. sort-package-json and
typecheck call npm scripts directly (no file args).
- project-specs.md: document the unification pattern
Why sh -c + env var instead of the simpler 'npm run ... -- {staged_files}':
'oxlint src file.ts' lints the whole src/ tree *plus* file.ts
(oxlint doesn't dedupe paths). Setting LEFTHOOK_FILES as an env
var (which lefthook's 'env:' config does not template) requires
the sh -c wrapper, but it gives the right semantics: when the
var is set, only the explicit files are checked; when unset,
the default (src/ or .) is used.
Verified:
- 'npm run check:oxlint' (no env) lints all of src/
- 'LEFTHOOK_FILES=src/match.ts npm run check:oxlint' lints only that file
- 'npx lefthook run pre-commit' with a staged TS file: cspell output
shows '1/1 src/match.ts' (only staged file, not whole project)
- All 5 hooks pass on a real staged change
- 'lefthook validate' reports 'All good'
- 'npm run check' exits 0
17 lines
565 B
YAML
17 lines
565 B
YAML
min_version: 2.0.0
|
|
|
|
pre-commit:
|
|
parallel: true
|
|
commands:
|
|
oxlint:
|
|
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
|
run: sh -c 'LEFTHOOK_FILES="$0" npm run check:oxlint' {staged_files}
|
|
oxfmt:
|
|
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
|
run: sh -c 'LEFTHOOK_FILES="$0" npm run check:oxfmt' {staged_files}
|
|
cspell:
|
|
run: sh -c 'LEFTHOOK_FILES="$0" npm run check:cspell' {staged_files}
|
|
sort-package-json:
|
|
run: npm run check:package
|
|
typecheck:
|
|
run: npm run check:tsc |