Eslint在Prettier添加后删除半殖民地
我正在尝试让 es lint 然后更漂亮地运行预提交。但是 es lint 或 lint staged 或某人或某物不断删除我的分号,让我发疯。我的应用程序是一个基本的 Node js 应用程序,没有打字稿。
这就是我的设置包括的内容,我已经尝试了很多但没有成功。
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
似乎发生的情况是 es-lint 实际上首先启动,但在 prettier 之后完成,恢复其所有更改(因此说没有更改)。我希望它按照指定的顺序工作,或者停止删除我的分号。
[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...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
semi
规则添加到.eslintrc.json
中(考虑其前面的点):... 如果您使用 prettier,则使用
.prettierrc。 json
:You can add the
semi
rule to your.eslintrc.json
(consider the dot before it):... And if you work with prettier,
.prettierrc.json
: