# install lint-staged
npm install -D lint-staged
# create this file with following content
.lintstagedrc
{
"*.js": [
"eslint --fix",
"prettier --write"
]
}
# you can now try to lint staged files with
npx lint-staged
# install husky
npm install -D husky
npm set-script prepare "husky install"
npm run prepare
# create hook
npx husky add .husky/pre-commit "npx lint-staged"
git add .husky/pre-commit
# create another hook
write in this file .husky/post-merge
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
if $(git diff --name-only HEAD@{1} HEAD | grep package-lock.json) ; then
echo "? package-lock.json changed. Running npm ci to update your dependencies..."
npm ci
else
echo "? no need to update dependencies"
fi
# on another machine you can git clone, and this command is automatically executed on "npm install", otherwise run it :
npm run prepare