Recently I started to introduce lint-staged
into my Frontend build tool chain. And when I checked the document about it, I always find it works as following:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css}": [
"prettier --write",
"eslint --fix src/",
"tslint --fix --project .",
"git add"
]
},
and you can find more similar usage in the link: https://github.com/okonet/lint-staged
My confusing point is the last command git add
, what's the purpose of that?
My understand is lint-staged
only validate the code in staged area after git add
and before git commit
. So can't understand why we need to add one more git add
again.
You don't need git add
since lint-staged 10
From v10.0.0 onwards any new modifications to originally staged files will be automatically added to the commit. If your task previously contained a
git add
step, please remove this. The automatic behaviour ensures there are less race-conditions, since trying to run multiple git operations at the same time usually results in an error.