Why is lint-staged running on unstaged files with my configuration?

Viewed 947

I have husky and lint-staged set up in my package.json file and it runs, but on all files, whereas I would expect it to run on only staged files.

"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},
"lint-staged": {
  "./**/*.js": [
    "eslint . --fix --quiet"
  ]
},
1 Answers

Removing the "." in your eslint command should fix this.

"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},
"lint-staged": {
  "./**/*.js": [
    "eslint --fix --quiet"
  ]
},

The command   eslint . --fix --quiet   runs eslint on all files in the current directory.

So, when the pre-commit hook is triggered for a staged file, since your eslint command is running on all files in your current directory, it affects your unstaged files too.


Whenever lint-staged runs on a file, it automatically passes the file's name to all the specified commands.

For example, if the staged index.js file is being processed,

eslint --fix --quiet

is transformed into

eslint --fix --quiet index.js
Related