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.
It's using husky to hooks some actions before your commit. See at: https://github.com/typicode/husky
lint-staged
just changes your code and make it linting (It runs before commit by husky). After changed, you need add it again to update git index. And your changes will be effect in your commit.