husky and lint-staged to run estlint and prettier on pre-commit


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 pkg set "scripts.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

to automatically run "npm install" on package.json changes.
we can write in this file .husky/post-merge

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/"

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
    echo "? no need to update dependencies"

on another machine you can git clone, and this command is automatically executed on "npm install", otherwise run it :

npm run prepare