lint-staged: Lint staged not working, no error, no warning

I followed this example https://github.com/okonet/lint-staged#installation-and-setup

Have this in my package.json

 "scripts": {
    
    "pre-commit": "lint-staged"
  },

and added this to my .lintstagedrc file

{
	"*.css": "stylelint",
	"*.scss": "stylelint --syntax=scss"
}

Latest OSX, Node version v6.10.0 and npm version 3.10.10

I had stylelint installed already and my stylelint works fine if I run via my grunt task. grunt stylelint

I made a change to my existing .scss file but don’t get anything in CLI when I add files to staging and commit. Things just work like there is no lint-staged.

Edited

I followed this article https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8

// package.json
...
"scripts" {
 "lint-staged": "lint-staged",
 "stylelint-staged": "stylelint --syntax scss"
},
"lint-staged": {
 "*.js": "eslint",
 "*.scss": "stylelint-staged"
},
"pre-commit": "lint-staged"
...

and it worked but I get this warning too after linting errors

pre-commit: 
pre-commit: We've failed to pass the specified git pre-commit hooks as the `lint-staged`
pre-commit: hook returned an exit code (1). If you're feeling adventurous you can
pre-commit: skip the git pre-commit hooks by adding the following flags to your commit:
pre-commit: 
pre-commit:   git commit -n (or --no-verify)
pre-commit: 
pre-commit: This is ill-advised since the commit is broken.
pre-commit: 

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 22

Most upvoted comments

I ran rm -rf node_modules and npm install again. after deleting .git/hooks/pre-commit file and setup everything again from here https://github.com/okonet/lint-staged#installation-and-setup

Now I’m back to this error again https://github.com/okonet/lint-staged/issues/165#issuecomment-301003092

After a brief moment of clarity and looking at index.js, I realized I didn’t have "lint-staged": "lint-staged" in my package.json which silently fails index.js:228for me. I apologize for the false alarm in my case.

i ran npm ci because I couldn’t get lint-staged to work either. On re-install i saw a message in terminal:

husky > Setting up git hooks Husky requires Git >= 2.13.2, please update Git husky > Failed to install

So i ran git --version. I am on 2.9. So I updated git to 2.23 and ran npm ci again with a successful install.

now when I try to commit files my lint-staged hook runs and I see errors as expected.

No, just choose one. pre-commit don’t have uninstall scripts so you have to clean it up before installing husky probably.

Hmm, the error you’re seeing seem to be in my code. Checking.

Not sure what’s going on but I’d recommend cleaning up the .git/hooks directory — remove all actually hooks (without sample), rm -rf node_modules and do a new npm install.

@okonet Do we need to use husky and pre-commit both?

I uninstalled pre-commit and installed husky and getting this error

❯ git commit -m "feat(grunt): test"

> husky - npm run -s precommit

/Users/jitendravyas/app-v3/node_modules/lint-staged/src/index.js:6
const path = require('path')
^^^^^
SyntaxError: Use of const in strict mode.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/jitendravyas/app-v3/node_modules/lint-staged/index.js:2:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

> husky - pre-commit hook failed (add --no-verify to bypass)
> husky - to debug, use 'npm run precommit'