🔧 Migrate lefthook config to v2 schema
The previous config was a hybrid of v1 (jobs: array) and v1
(top-level commands: block) that no longer validates under
lefthook 2.x. lefthook 2.0.0's schema has top-level 'commands:'
set to 'false'; the v1 jobs: array form still works, but the
orphan named-commands block at the top was silently invalid
(caught by 'lefthook validate').
Migrate to the v2-native 'commands:' (named) form under the hook:
pre-commit:
parallel: true
commands:
oxlint:
glob: ...
run: npx oxlint {staged_files}
...
Changes:
- Add 'min_version: 2.0.0' to declare the v2 schema explicitly
- Replace pre-commit.jobs: array with pre-commit.commands: (named)
- Inline the glob on each command (was a top-level property on each
job in v1)
- Remove the orphan top-level 'commands:' block — it was never
referenced by any hook, and v2 forbids it
- Update project-specs.md: drop the dangling reference to the
lefthook 'commands:' block (it was the dead top-level one);
describe the v2 commands: form
Verified:
- 'lefthook validate' reports 'All good'
- 'lefthook run pre-commit' executes all 5 hooks (oxlint, oxfmt,
sort-package-json, typecheck, cspell); globs correctly skip hooks
on non-matching files (e.g. lefthook.yml alone) and run them on
TS/JS changes
- 'npm run check' exits 0
- 'lefthook dump' shows the normalized v2 config
This commit is contained in:
1 parent
9bc87aab87
commit
45b6c141e8
2 files changed
+18
-27
No files matched your search
+8
-20
@@ -1,29 +1,17 @@
|
|||||||
|
min_version: 2.0.0
|
||||||
|
|
||||||
pre-commit:
|
pre-commit:
|
||||||
parallel: true
|
parallel: true
|
||||||
jobs:
|
commands:
|
||||||
- name: oxlint
|
oxlint:
|
||||||
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
||||||
run: npx oxlint {staged_files}
|
run: npx oxlint {staged_files}
|
||||||
- name: oxfmt
|
oxfmt:
|
||||||
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
glob: "*.{ts,tsx,js,jsx,mjs,cjs}"
|
||||||
run: npx oxfmt --check {staged_files}
|
run: npx oxfmt --check {staged_files}
|
||||||
- name: cspell
|
cspell:
|
||||||
run: npx cspell {staged_files}
|
run: npx cspell {staged_files}
|
||||||
- name: sort-package-json
|
sort-package-json:
|
||||||
run: npx sort-package-json --check
|
run: npx sort-package-json --check
|
||||||
- name: typecheck
|
|
||||||
run: npx tsc --noEmit
|
|
||||||
|
|
||||||
commands:
|
|
||||||
typecheck:
|
typecheck:
|
||||||
run: npm run check:tsc
|
run: npx tsc --noEmit
|
||||||
spell:
|
|
||||||
run: npm run check:cspell
|
|
||||||
sort:
|
|
||||||
run: npm run check:package
|
|
||||||
lint:
|
|
||||||
run: npm run check:oxlint
|
|
||||||
format:
|
|
||||||
run: npm run check:oxfmt
|
|
||||||
outdated:
|
|
||||||
run: npm run check:outdated
|
|
||||||
+10
-7
@@ -38,12 +38,15 @@ typescript-lib-starter-tiny => https://github.com/tmueller/typescript-lib-starte
|
|||||||
`oxfmtrc`, `oxlintrc`, `sortpackagerc`, `EDITMSG`, `typescriptteam`,
|
`oxfmtrc`, `oxlintrc`, `sortpackagerc`, `EDITMSG`, `typescriptteam`,
|
||||||
`gitmoji`, `dbaeumer`, `msvc`) and a few library names (`tslib`,
|
`gitmoji`, `dbaeumer`, `msvc`) and a few library names (`tslib`,
|
||||||
`typefest`, `lefthook`).
|
`typefest`, `lefthook`).
|
||||||
- **Lefthook**: Pre-commit checks for (run in parallel):
|
- **Lefthook**: Pre-commit checks (run in parallel, lefthook v2 schema):
|
||||||
- oxlint on staged JS/TS files
|
- `min_version: 2.0.0`
|
||||||
- oxfmt --check on staged JS/TS files
|
- `pre-commit.commands.oxlint` — `npx oxlint {staged_files}` on
|
||||||
- cspell on staged files
|
staged `*.{ts,tsx,js,jsx,mjs,cjs}` files
|
||||||
- sort-package-json --check
|
- `pre-commit.commands.oxfmt` — `npx oxfmt --check {staged_files}`
|
||||||
- tsc --noEmit
|
on staged `*.{ts,tsx,js,jsx,mjs,cjs}` files
|
||||||
|
- `pre-commit.commands.cspell` — `npx cspell {staged_files}`
|
||||||
|
- `pre-commit.commands.sort-package-json` — `npx sort-package-json --check`
|
||||||
|
- `pre-commit.commands.typecheck` — `npx tsc --noEmit`
|
||||||
`outdated` is intentionally NOT a pre-commit check (it can flag
|
`outdated` is intentionally NOT a pre-commit check (it can flag
|
||||||
upstream patch releases that aren't actionable locally); it runs in
|
upstream patch releases that aren't actionable locally); it runs in
|
||||||
CI and via the explicit `lefthook run outdated` command.
|
CI and via the explicit `lefthook run outdated` command.
|
||||||
@@ -173,7 +176,7 @@ typescript-lib-starter-tiny => https://github.com/tmueller/typescript-lib-starte
|
|||||||
- `fix:oxfmt`: `oxfmt src`.
|
- `fix:oxfmt`: `oxfmt src`.
|
||||||
- `fix:package`: `sort-package-json --write`.
|
- `fix:package`: `sort-package-json --write`.
|
||||||
(There is no `fix` aggregator in the scripts; run the `fix:*` scripts
|
(There is no `fix` aggregator in the scripts; run the `fix:*` scripts
|
||||||
individually or via the lefthook `commands:` block.)
|
individually.)
|
||||||
|
|
||||||
### HOOKS
|
### HOOKS
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user