From ee1186c591089de43a7174f8030dbeb2fc608d63 Mon Sep 17 00:00:00 2001 From: Alexander Bjerkan Date: Fri, 27 Nov 2026 09:27:32 +0100 Subject: [PATCH] chore: add lefthook pre-commit hook for oxfmt and oxlint Add lefthook with a pre-commit hook that runs oxfmt and oxlint --fix on staged files (fixes are re-staged), installed automatically via the prepare script. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- lefthook.yml | 13 ++++++ package.json | 2 + pnpm-lock.yaml | 109 ++++++++++++++++++++++++++++++++++++++++++++ pnpm-workspace.yaml | 2 + 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 lefthook.yml diff --git a/README.md b/README.md index 74cf79f..0ca50b3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ pnpm install ### Linting and formatting -This repository uses [oxlint](https://oxc.rs/docs/guide/usage/linter) (with type-aware rules) for linting and [oxfmt](https://oxc.rs/docs/guide/usage/formatter) for formatting. +This repository uses [oxlint](https://oxc.rs/docs/guide/usage/linter) (with type-aware rules) for linting and [oxfmt](https://oxc.rs/docs/guide/usage/formatter) for formatting. A [lefthook](https://lefthook.dev) pre-commit hook runs `oxfmt` and `oxlint --fix` on staged files, and is installed by `pnpm install`. ``` pnpm lint diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..8232c1b --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,13 @@ +# https://lefthook.dev/configuration/ +pre-commit: + piped: true + jobs: + - name: fmt + glob: '*.{js,jsx,ts,tsx,mjs,cjs,json,jsonc,css,md,yml,yaml}' + exclude: '*.lock.yml' + run: pnpm exec oxfmt --no-error-on-unmatched-pattern {staged_files} + stage_fixed: true + - name: lint + glob: '*.{js,jsx,ts,tsx,mjs,cjs}' + run: pnpm exec oxlint --fix {staged_files} + stage_fixed: true diff --git a/package.json b/package.json index 060e7e3..154373f 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,14 @@ "fmt:check": "oxfmt --check", "lint": "oxlint", "lint:fix": "oxlint --fix", + "prepare": "lefthook install || true", "test": "vitest", "test:ci": "vitest run" }, "devDependencies": { "@arethetypeswrong/core": "0.18.5", "@changesets/cli": "3.0.3", + "lefthook": "2.2.2", "oxfmt": "0.79.0", "oxlint": "1.94.0", "oxlint-tsgolint": "7.0.2005", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d6dcf4..8b51a76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -172,6 +172,9 @@ importers: '@changesets/cli': specifier: 3.0.3 version: 3.0.3 + lefthook: + specifier: 2.2.2 + version: 2.2.2 node: specifier: runtime:^26 version: runtime:26.13.0 @@ -1014,6 +1017,65 @@ packages: launch-editor@2.14.2: resolution: {integrity: sha512-NHJEb30MGBCkmZXLZwz25t37QR4aY03ZzPYUJXOJaOa92uWwExI9SBQUuIznBYc1xkD7cJNGX7oc3Nl3sq2kQQ==} + lefthook-android-arm64@2.2.2: + resolution: {integrity: sha512-wb9rQQFLX7u1dJLxvMrq9VUfMYi5kxM7tJQ6Y4mWEOwaU+SmIm2wjoT/nromKq27Y8fh2Qd7FgCD3G1wfW8CnQ==} + cpu: [arm64] + os: [android] + + lefthook-darwin-arm64@2.2.2: + resolution: {integrity: sha512-6V8D3bLnD/60Xhqn0o2EQD6H3Fe/U9LGkt4WF1O/3eBHbux+5ZJqoH0hfrC+Bi9Dy1Ve1AWxiAY7U2asYl8qVA==} + cpu: [arm64] + os: [darwin] + + lefthook-darwin-x64@2.2.2: + resolution: {integrity: sha512-fH/kArZ9ZZ65wCFtvBMgGcq25qwQpkQ5jp93ba+8wpjgxxzjczYGluwHvM/NQDJWLOFXuKXW0yFs76SramQkyQ==} + cpu: [x64] + os: [darwin] + + lefthook-freebsd-arm64@2.2.2: + resolution: {integrity: sha512-MCRsU01ju989QQffOfS3gCeFfyVDXs5B/FzR65fmrNvqcxb98fldvfzzoAbnK2q6SBJlRT3QT1tNEMCxddCwlA==} + cpu: [arm64] + os: [freebsd] + + lefthook-freebsd-x64@2.2.2: + resolution: {integrity: sha512-LkKuJU0S2oLimeoHwPTy1TLWB6GcN0t5lLxiXNlsBKUkr6R47QRcvPMZMoXmu3IetQtd+WliXMLE8qTwi2fqBg==} + cpu: [x64] + os: [freebsd] + + lefthook-linux-arm64@2.2.2: + resolution: {integrity: sha512-d+HFtS2DEKaOnD7vRU0tUz8pNgHwsUYmQ22+1dyXpOrXGyzNXR0AqX5KsIRF36JGhVvO5X5Anw5QYgR3mxVSuA==} + cpu: [arm64] + os: [linux] + + lefthook-linux-x64@2.2.2: + resolution: {integrity: sha512-N/OlQyAhcU6RAXjrwFxLsh70sn96rBoi+XkuLJ8CVBkk9Ci3VDXQayDZTNz5B1xML8RwoMcV8Wblniy1xFOmSA==} + cpu: [x64] + os: [linux] + + lefthook-openbsd-arm64@2.2.2: + resolution: {integrity: sha512-6G/gKXcpIwC+XcODg7ELZYP/hIrVIHQxhy2GoRdVyecmpGMFj+BZo3iqcUmeWusQMuL+UdNexbkrUaeJalIkNw==} + cpu: [arm64] + os: [openbsd] + + lefthook-openbsd-x64@2.2.2: + resolution: {integrity: sha512-eMJGi3/tqKEqu7XCZlqwQWRtK5JlL/9diaqqgRlEdlRD7GxwzHZN21z6awbITum9emea3lALvXFe6V8odQLGOA==} + cpu: [x64] + os: [openbsd] + + lefthook-windows-arm64@2.2.2: + resolution: {integrity: sha512-4P1EaQb5xG1zhYD1RLJ6TEGdFkmHkB+Slqx6yRDPKuBDNxMiD0+kTAAdUY2E8xPuRR35xHpVPR+b3/HtzPrjQQ==} + cpu: [arm64] + os: [win32] + + lefthook-windows-x64@2.2.2: + resolution: {integrity: sha512-9Ck4zancQilBfXT3ZeRipm7Lcq4RQfxyMpy8SAVINw0t/BrbjsT25V46ZuziERcwdajnE4myfMzC33GoCBwr7g==} + cpu: [x64] + os: [win32] + + lefthook@2.2.2: + resolution: {integrity: sha512-37fYHAhL12r1twaEV0PA5TwoIT491eTGGYjhhXxlYNMq3DSkiGZBQ++Jfk5maXj0vq52NRauLtMikBKtbNJs3Q==} + hasBin: true + lightningcss-android-arm64@1.33.0: resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==} engines: {node: '>= 12.0.0'} @@ -2074,6 +2136,53 @@ snapshots: picocolors: 1.1.1 shell-quote: 1.12.0 + lefthook-android-arm64@2.2.2: + optional: true + + lefthook-darwin-arm64@2.2.2: + optional: true + + lefthook-darwin-x64@2.2.2: + optional: true + + lefthook-freebsd-arm64@2.2.2: + optional: true + + lefthook-freebsd-x64@2.2.2: + optional: true + + lefthook-linux-arm64@2.2.2: + optional: true + + lefthook-linux-x64@2.2.2: + optional: true + + lefthook-openbsd-arm64@2.2.2: + optional: true + + lefthook-openbsd-x64@2.2.2: + optional: true + + lefthook-windows-arm64@2.2.2: + optional: true + + lefthook-windows-x64@2.2.2: + optional: true + + lefthook@2.2.2: + optionalDependencies: + lefthook-android-arm64: 2.2.2 + lefthook-darwin-arm64: 2.2.2 + lefthook-darwin-x64: 2.2.2 + lefthook-freebsd-arm64: 2.2.2 + lefthook-freebsd-x64: 2.2.2 + lefthook-linux-arm64: 2.2.2 + lefthook-linux-x64: 2.2.2 + lefthook-openbsd-arm64: 2.2.2 + lefthook-openbsd-x64: 2.2.2 + lefthook-windows-arm64: 2.2.2 + lefthook-windows-x64: 2.2.2 + lightningcss-android-arm64@1.33.0: optional: true diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 18ec407..61d5853 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,4 @@ packages: - 'packages/*' +allowBuilds: + lefthook: true