easwee.net // tiny digital playground

quick setup for husky with lint-staged

1.) Install dev dependencies:

npm install husky lint-staged eslint --save-dev

Note: if you get an error like

ENOENT: no such file or directory, mkdir 'node_modules/husky/.git/hooks'
husky > Failed to install

just update your git to latest version and it should install fine.

2.) Update package.json with husky and lint-staged definitions by adding:

 ...
 "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js}": [
      "./node_modules/.bin/eslint --fix",
    ]
  }
  ...

Note: you may want to also add ts or jsx like {js,jsx,ts} depending on what kind of setup you are working on

This is the very basic setup – for all extra consult the docs: https://github.com/okonet/lint-staged