npm pre commit not working

user7258044 picture user7258044 · Mar 17, 2017 · Viewed 7.8k times · Source

I am using npm precommit hook, but it is not stopping a file with issues to be committed, nor am I getting the message "Pre commit checks" when I try to commit a file.

Package Json:
{
  "name": "myfolder",
  "version": "1.0.0",
  "description": "",
  "main": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 0",
    "precommit-msg": "echo 'Pre-commit checks...' && exit 0",
    "lint": "csslint global/css"
  },
  "author": "SR",
  "license": "ISC",
  "dependencies": {
    "csslint": "^1.0.4",
    "jshint": "^2.9.4",
    "pre-commit": "^1.2.2"
  },
  "pre-commit": [
    "precommit-msg",
    "lint"
  ],
  "devDependencies": {
    "pre-commit": "^1.2.2"
  }
}

Answer

pasul picture pasul · Mar 30, 2017

Please, make sure that your 'package.json' file is in the same folder, where '.git' folder is (where git repository was initialized). When you install 'pre-commit' package, 'pre-commit' file should appear under '.git/hooks/'.

enter image description here