chore: add lefthook pre-commit hooks - #198
Conversation
There was a problem hiding this comment.
I made a trivial spacing change on this file to see if it would run it on the staged file and it did!! Woooo!
|
So I disable husky pre-hook stuff locally - it does not play nice with git on windows. I'm agreeable to adding this, but I'd really really like to remove some (most?) of these lint rules. |
|
Sorry, could've made the intent here clearer. This is to auto-fix any fixable rules or formatting on commit, not to block commits if they fail a check. Also I need to verify it's working how I expect! I forgot to test if it allows you to successfully commit with a linting error in the code. |
|
Shoot, it does prevent commits if there are errors. Will look into this again later! |
|
Finally got back to this and made it so it doesn't block any commits if there are lint errors happening while still doing any formatting or safe linting fixes! This is ready to go 😁 |
- Add lefthook.yml running oxlint --fix, oxfmt, and prettier on staged files - Autofix only: the hook never blocks a commit, CI remains the gate - Re-stage fixes via stage_fixed so commits record the formatted output - Remove .husky/ and the biome-era lint-staged config - Restore pnpm-workspace.yaml to match main (pnpm 11 scaffolding backed out) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
These import sorts came from the branch's original Biome-based work and are unrelated to the lefthook change. Restores both files to match main. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
oxfmt formats md/mdx/html and oxlint reads astro, but the globs listed only the js/ts subset. A markdown- or astro-only commit skipped the hook entirely and then failed CI, which is the exact case the hook exists to prevent. Also includes a deliberate console.log in site/src/examples/types.ts demonstrating that the hook reformats the line and lets the commit through while still reporting the lint error. Remove before merge. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…lint-fix-and-pre-commit-hooks
Follow lefthook's documented pnpm setup instead of a custom prepare script: allow its postinstall to run, which is what syncs the git hooks. pnpm 11 reads this from pnpm-workspace.yaml's allowBuilds. The docs also mention pnpm.onlyBuiltDependencies in package.json, but pnpm 11 ignores that field and warns about it, so it is omitted. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What
Add lefthook pre-commit hooks. The hook autofixes what it can on commit and never blocks — CI remains the gate for anything unfixable.
How
Adds
lefthook.ymlwith three pre-commit commands:lint.astrooxlint --fixfmtoxfmtfmt-astro.astroprettier --writePlus a
lefthookdevDependency andlefthook: trueunderallowBuildsinpnpm-workspace.yaml.Notable details:
|| true, so an unfixable lint error is printed but still lets the commit through.stage_fixed: truere-stages files the tools modified, so the commit records the formatted output rather than what was originally staged.priorityforcesoxlint --fixto run beforeoxfmt. Lefthook orders commands alphabetically by default, which would have run the formatter first and left lint autofixes unformatted.globper command must cover every file type its tool handles. The globs were derived by probing the tools rather than assuming:oxfmtreformatsjs/jsx/mjs/cjs/mts/cts/ts/tsx/json/jsonc/yaml/yml/md/mdx/html, andoxlintreads.astroin addition to JS/TS. An earlier revision omitted md/mdx/html/astro, which let a markdown- or astro-only commit skip the hook and then fail CI.postinstallto run, and that syncs the hooks. Note the docs also say to addpnpm.onlyBuiltDependenciestopackage.json; pnpm 11 ignores that field and warns about it, so only thepnpm-workspace.yamlentry is used.Verification
Tested from fresh clones on pnpm 11.21.0, driving real
git commitcalls and asserting on committed blob contents:pnpm install→pre-commithook present; a badly formatted.tsthen commits as formatted output..tswith an unfixableno-consoleerror plus bad formatting: commit succeeds, error reported, committed blob is formatted..mdmakespnpm run checkexit 1; the hook formats and re-stages it, so CI stays green..astrofile with a lint error is reported byoxlintand formatted byprettier.PR Checklist
main?console.logis removed)