From 5e72c9caf40d5721dd72423074b51307ecc1c323 Mon Sep 17 00:00:00 2001 From: Tasia Iso Date: Tue, 4 Jun 2024 15:08:10 +0200 Subject: [PATCH] build: add husky to automatically format code - husky installs a git hook to run make format every time you commit new code - if `make format` fails (if a dependency is missing or prettier throws an error), the hook will still succeed as to not block people for dumb reasons - pin prettier and husky to 3.2.5 and 9.0.11 respectively - add prettier as a dependency for the `make format` rule --- .husky/pre-commit | 1 + .prettierignore | 1 + GNUmakefile | 2 +- package-lock.json | 21 +++++++++++++++++++-- package.json | 8 +++++--- 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..750aa6b9 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +make format || exit 0 diff --git a/.prettierignore b/.prettierignore index 595b4cc1..ba5237bc 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,6 +2,7 @@ node_modules src deps .clang-format +flake.lock # Minified files **/*.min.css diff --git a/GNUmakefile b/GNUmakefile index 14f8fe78..cac12f11 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -902,7 +902,7 @@ dist-test: dist @rm -rf tildefriends-$(VERSION_NUMBER) .PHONY: dist-test -format: +format: prettier @clang-format -i $(wildcard src/*.c src/*.h src/*.m) .PHONY: format diff --git a/package-lock.json b/package-lock.json index 731d4b09..cbf5a821 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,12 +6,29 @@ "": { "name": "tildefriends", "license": "MIT", - "dependencies": { - "prettier": "^3.2.5" + "devDependencies": { + "husky": "9.0.11", + "prettier": "3.2.5" + } + }, + "node_modules/husky": { + "version": "9.0.11", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", + "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", + "dev": true, + "bin": { + "husky": "bin.mjs" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" } }, "node_modules/prettier": { "version": "3.2.5", + "dev": true, "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" diff --git a/package.json b/package.json index 6808eff0..7f0f4aee 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,13 @@ { "name": "tildefriends", "scripts": { - "prettier": "prettier . --check --cache --write" + "prettier": "prettier . --check --cache --write", + "prepare": "husky" }, "author": "Cory McWilliams", "license": "MIT", - "dependencies": { - "prettier": "^3.2.5" + "devDependencies": { + "prettier": "3.2.5", + "husky": "9.0.11" } }