Skip to content

Instantly share code, notes, and snippets.

@vre2h
Last active August 8, 2019 13:32
Show Gist options
  • Save vre2h/10bad7213841bc172a54efe89692d37e to your computer and use it in GitHub Desktop.
Save vre2h/10bad7213841bc172a54efe89692d37e to your computer and use it in GitHub Desktop.
Git hooks

How to add git hooks to project

Installing

npm i -D husky lint-staged

Usage

  • In package.json
  "lint-staged": {
    "src/**/*.{ts,tsx}": [
      "tslint -c tslint.json --fix --format verbose",
      "git add",
      "react-scripts test --findRelatedTests"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "export CI=true && lint-staged",
      "pre-push": "export CI=true && npm test"
    }
  },

Requirements

Note, We're using husky and lint-staged to lint and test code before commiting that's why you need at least Node's 8.12.0 version.

Troubleshooting

Lint-staged

Note, You shouldn't place space between ts and tsx in package.json in lint-staged section.

Wrong

    "*.{ts, tsx}"

Right

    "*.{ts,tsx}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment