From db7b849898cda03475e937d3c8e2f807342b6f09 Mon Sep 17 00:00:00 2001 From: Romaric Date: Wed, 14 Sep 2022 18:09:18 +0100 Subject: [PATCH] Set up pre-commit git hook using husky Install the hooks in the prepare script through a node call rather than just `husky install` as the package won't be installed on Heroku, which would make the `prepare` script fail A mix of both solutions from: https://typicode.github.io/husky/#/?id=with-a-custom-script --- .husky/pre-commit | 4 ++++ package-lock.json | 16 ++++++++++++++++ package.json | 4 +++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..cf0c46b936 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no-install lint-staged diff --git a/package-lock.json b/package-lock.json index e08da9c677..a86c7335de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,6 +63,7 @@ "eslint-plugin-n": "^15.5.1", "eslint-plugin-promise": "^6.1.1", "html-validate": "7.10.0", + "husky": "^8.0.2", "jest": "^29.3.1", "jest-axe": "^7.0.0", "jest-dev-server": "^6.1.1", @@ -11813,6 +11814,21 @@ "ms": "^2.0.0" } }, + "node_modules/husky": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.2.tgz", + "integrity": "sha512-Tkv80jtvbnkK3mYWxPZePGFpQ/tT3HNSs/sasF9P2YfkMezDl3ON37YN6jUUI4eTg5LcyVynlb6r4eyvOmspvg==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/package.json b/package.json index 3aaa19e038..cf7172f9fa 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "lint:js": "npm run lint:js:cli -- \"**/*.{cjs,js,mjs}\"", "lint:js:cli": "eslint --cache --cache-location .cache/eslint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0", "lint:scss": "npm run lint:scss:cli -- \"{app,src}/**/*.scss\"", - "lint:scss:cli": "stylelint --cache --cache-location .cache/stylelint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0" + "lint:scss:cli": "stylelint --cache --cache-location .cache/stylelint --cache-strategy content --color --ignore-path .gitignore --max-warnings 0", + "prepare": "node -e \"process.env.CI || require('husky').install() \"" }, "dependencies": { "@babel/core": "^7.20.2", @@ -87,6 +88,7 @@ "eslint-plugin-n": "^15.5.1", "eslint-plugin-promise": "^6.1.1", "html-validate": "7.10.0", + "husky": "^8.0.2", "jest": "^29.3.1", "jest-axe": "^7.0.0", "jest-dev-server": "^6.1.1",