summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-05-28 06:24:58 +0200
committerRory& <root@rory.gay>2025-05-28 06:24:58 +0200
commit3c070786186c0791c3a1909d663250b21032896c (patch)
tree02137e9ab4c760b423b5dca13db29f3bc32fd2d7
parentSet up gitattributes (diff)
downloadnodejs-final-assignment-3c070786186c0791c3a1909d663250b21032896c.tar.xz
Set up husky and lintstagedrc
-rw-r--r--.husky/pre-commit28
-rw-r--r--.lintstagedrc3
2 files changed, 31 insertions, 0 deletions
diff --git a/.husky/pre-commit b/.husky/pre-commit
new file mode 100644

index 0000000..6d2e7f0 --- /dev/null +++ b/.husky/pre-commit
@@ -0,0 +1,28 @@ +#!/usr/bin/env sh +#!nix-shell -i "bash" -p bash prefetch-npm-deps jq nodejs nix-output-monitor +. "$(dirname -- "$0")/_/husky.sh" + +# Check if nix is available +if [ -x "$(/usr/bin/env which nix-shell 2>/dev/null)" ]; then + # Check if we haven't re-executed ourselves yet + if [ ! "$HOOK_NIX_SHELL" ]; then + echo "Nix is available, updating nix flake..." + export HOOK_NIX_SHELL=1 + nix-shell $0 + exit $? + else + nix flake update + # run ./nix-update.sh if package lock has changed and has no unstaged changes + if [ -n "$(git status --porcelain=v1 2>/dev/null | grep -E '^(MM| M) package-lock.json')" ]; then + echo "package-lock.json has unstaged changes. Skipping update of nix dependencies." + elif [ ! -n "$(git status --porcelain=v1 2>/dev/null | grep -E '^M package-lock.json')" ]; then + echo "package-lock.json has no changes. Skipping update of nix dependencies." + else + nix run .#nix-update || exit $? + fi + fi +else + echo "You do not appear to have nix installed. Skipping update of nix dependencies." +fi + +npx -y lint-staged diff --git a/.lintstagedrc b/.lintstagedrc new file mode 100644
index 0000000..0d509f6 --- /dev/null +++ b/.lintstagedrc
@@ -0,0 +1,3 @@ +{ + "*.js": ["eslint", "prettier --write"] +}