From 4fe1a1cdc0727ad13a41542593a9ca7b61aadf3b Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Thu, 30 Jul 2026 02:25:29 +0200 Subject: [PATCH] Use prek for pre-commit hooks --- README.md | 33 +++++++++++++++++++++++---------- mise.toml | 1 + prek.toml | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 prek.toml diff --git a/README.md b/README.md index 87c72e9..18c7ae6 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,21 @@ command-line tools. mise trust mise install npm install + prek install cp env-example .env.local +## Scripts + +- `npm run start` - Start Expo development server on port 19001 +- `npm run android` - Run app in Android emulator +- `npm run ios` - Run app in iOS simulator (requires macOS) +- `npm run web` - Run app in web browser +- `npm run lint` - Check code with ESLint +- `npm run format` - Fix code formatting with ESLint +- `npm run check-types` - Run TypeScript type checking +- `npm test` - Run the test suite +- `npm run test:watch` - Run the test suite in watch mode + ## Development This app uses native functionality that isn't supported by [Expo Go](https://expo.dev/client), @@ -54,17 +67,17 @@ Many packages (`expo-*`, `react-native`, and more) are versioned in lockstep wit Expo SDK. Check them with `npx expo install --check` and upgrade with `npx expo install --fix` instead of `npm update`. -## Scripts +## Pre-commit hooks -- `npm run start` - Start Expo development server on port 19001 -- `npm run android` - Run app in Android emulator -- `npm run ios` - Run app in iOS simulator (requires macOS) -- `npm run web` - Run app in web browser -- `npm run lint` - Check code with ESLint -- `npm run format` - Fix code formatting with ESLint -- `npm run check-types` - Run TypeScript type checking -- `npm test` - Run the test suite -- `npm run test:watch` - Run the test suite in watch mode +Git hooks are managed with [prek](https://prek.j178.dev/) (installed by `mise install`) +and configured in `prek.toml`. Enable them with: + + prek install + +Commits then only succeed if linting, type checking and the related tests pass. Run all +hooks against the whole repo with: + + prek run --all-files ## History diff --git a/mise.toml b/mise.toml index 5a92242..19a9549 100644 --- a/mise.toml +++ b/mise.toml @@ -2,3 +2,4 @@ android-sdk = "latest" java = "temurin-17" node = "24" +prek = "latest" diff --git a/prek.toml b/prek.toml new file mode 100644 index 0000000..5a9aa5d --- /dev/null +++ b/prek.toml @@ -0,0 +1,42 @@ +#:schema https://www.schemastore.org/prek.json + +[[repos]] +repo = "builtin" +hooks = [ + { id = "check-added-large-files" }, + { id = "check-case-conflict" }, + { id = "check-json", exclude = '^tsconfig\.json$' }, # tsconfig is JSONC, comments allowed + { id = "check-merge-conflict" }, + { id = "check-yaml" }, + { id = "detect-private-key" }, + { id = "end-of-file-fixer" }, + { id = "mixed-line-ending", args = ["--fix=lf"] }, + { id = "trailing-whitespace", args = ["--markdown-linebreak-ext=md"] }, +] + +[[repos]] +repo = "local" + +[[repos.hooks]] +id = "eslint" +name = "eslint" +entry = "npx --no-install eslint --fix --no-warn-ignored" +language = "system" +types_or = ["javascript", "jsx", "ts", "tsx"] + +[[repos.hooks]] +id = "check-types" +name = "tsc" +entry = "npx --no-install tsc" +language = "system" +files = '\.tsx?$|^tsconfig\.json$' +pass_filenames = false + +[[repos.hooks]] +id = "jest" +name = "jest (tests related to staged files)" +entry = "npx --no-install jest --bail --findRelatedTests --passWithNoTests" +language = "system" +types_or = ["javascript", "jsx", "ts", "tsx"] +# One jest invocation for all files — parallel invocations contend and time out +require_serial = true