observing / pre-commit

Automatically installs a git pre-commit script in your git repository which runs your `npm test` on pre-commit
MIT License
1.88k stars 153 forks source link

"pre-commit" doesn't run npm scripts at all #120

Open hutber opened 6 years ago

hutber commented 6 years ago

I believe this should work as pre-commit will run anything defined in scripts.

  "scripts": {
    "lint": "lint-staged",
  },
  "pre-commit": [
    "lint"
  ],
  "lint-staged": {
    "*.js": [
      "prettier --write",
      "eslint",
      "git add"
    ],
    "*.jsx": [
      "prettier --write",
      "eslint",
      "git add"
    ],
    "*.scss": [
      "stylelint --syntax=scss",
      "git add"
    ]
  },

Console with link not running

hutber@hutber-blade /var/www/shipamax-web/frontend $ git add tests/
hutber@hutber-blade /var/www/shipamax-web/frontend $ git commit -m"another test"
[chore/create-circleci-build-rebase 5ff3f76] another test
 1 file changed, 1 insertion(+), 1 deletion(-)
hutber@hutber-blade /var/www/shipamax-web/frontend $ 

Folder Structure

Running Linux Mint 18.3 node v8 npm v5

hutber commented 6 years ago

Some more information in here: https://stackoverflow.com/questions/48789346/pre-commit-not-running-in-linux

ozguruksal commented 6 years ago

@hutber I had the same issue. I installed pre-commit before I had the .git in my project. To fix, make sure you have the .git in your project folder before installing pre-commit.

scssyworks commented 4 years ago

What if .git folder is several directories up? It seems that pre-commit only cares about .git folder which is in same directory as package.json.

AlexanderMakarov commented 2 years ago

@scssyworks eventually I've implemented it "manually" - see https://stackoverflow.com/a/70631351/1535127