I'm trying to have es lint and then prettier run pre commit. But es lint or lint staged or someone or something keeps removing my semicolons driving me insane. My app is a basic node js app with no typescript.
This is what my setup includes and I've tried a lot with no success.
package.json
{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.2.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.3",
"prettier": "^2.5.1"
},
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.{js,json,md}": "prettier --write"
}
}
eslintrc.json
{
"env": {
"es2021": true
},
"extends": ["standard"],
"parserOptions": {
"ecmaVersion": "latest"
}
}
husky pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
What seems to happen is that es-lint actually starts first but finishes after prettier, reverting all of its changes (and therefore saying there are no changes). I want it to either work in the order it is specified or stop removing my semicolons.
[STARTED] Preparing lint-staged...
[SUCCESS] Preparing lint-staged...
[STARTED] Running tasks for staged files...
[STARTED] package.json — 4 files
[STARTED] *.js — 4 files
[STARTED] *.{js,json,md} — 4 files
[STARTED] eslint --cache --fix
[STARTED] prettier --write
[SUCCESS] prettier --write
[SUCCESS] *.{js,json,md} — 4 files
[SUCCESS] eslint --cache --fix
[SUCCESS] *.js — 4 files
[SUCCESS] package.json — 4 files
[SUCCESS] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[FAILED] Prevented an empty git commit!
[STARTED] Reverting to original state because of errors...
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up temporary files...
[SUCCESS] Cleaning up temporary files...