Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (26 sloc) 1.27 KB

Husky hooks

You can configure your project to run linting and tests prior for certain git actions with husky. That way you can ensure your quality checks pass before you, for instance, commit or push.

Setup

... is done quickly.

Make sure your project already has a Git repository. Otherwise just create one with:

git init

Install husky using npm and save it as a dev-dependency:

npm install husky --save-dev

Extend the scripts property of your package.json with all the hooks you want:

{
  "scripts": {
    // ...
    "precommit": "gulp linting-throw",
    "prepush": "gulp linting-throw && gulp karma && gulp protractor",
  }
}

The above example will run ESLint and JSONLint checks when you git commit and additionally Karma tests when you git push.

Additional information on gulp tasks

gulp linting-throw

The gulp linting-throw task will run linting checks and throw an error on failed checks. The gulp linting on the other hand will perform checks, report errors on the command line but not throw an error. Thus it would successfully pass the hook even when there's linting issues.