18

I use husky to check JS before commit. In my package.json i have

"scripts": {
    "lintStyles": "stylelint app/**/*.scss",
    "fixStylesLinting": "stylelint app/**/*.scss --fix",
    "lintJS": "eslint app/**/*.js",
    "fixJSLinting": "eslint --fix app/**/*.js",
    "precommit": "npm run lintJS"
  }

It works, what i don't understand is how can i run both lintJS, lintStyles commands.

Rantiev
  • 2,121
  • 2
  • 32
  • 56

3 Answers3

38

to include more than one script add &&for ex:

precommit: npm run lint:sass && npm run lint:js

chris_r
  • 2,039
  • 1
  • 22
  • 22
2

This should work:

"scripts": {
  "lint:scss": "stylelint app/**/*.scss",
  "fixStylesLinting": "stylelint app/**/*.scss --fix",
  "lint:js": "eslint app/**/*.js",
  "fixJSLinting": "eslint --fix app/**/*.js",
  "precommit": "npm run lint:*"
}
netweb
  • 622
  • 5
  • 12
1

In order to run multiple hooks on single pre-commit you need to do like this

npx husky add .husky/pre-commit "npx lint-staged"

similarly for other hook add:

npx husky add .husky/pre-commit "npm run ban"

so that the file looks like this in the husky folder:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npm run ban

Then in package.json add following

"pre-commit": "npm run lint && npm run ban"

separated by &&

double-beep
  • 5,031
  • 17
  • 33
  • 41
Sajid Khaki
  • 121
  • 1
  • 3