英文:
What is the reason ESlint doesn't work in VS Code
问题
ESlint不会在保存代码时进行钩子操作,也不会在保存时显示错误,但如果运行npm run lint命令,那么错误将会显示出来。我将附上带有设置的屏幕截图。
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"eslint": "^8.10.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.2",
"eslint-plugin-react-hooks": "^4.3.0",
英文:
ESlint does not hook the code and does not give errors when saving, but if you run the npm run lint command, then the errors are shown, I will attach screenshots with the settings
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"eslint": "^8.10.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.2",
"eslint-plugin-react-hooks": "^4.3.0",
答案1
得分: 2
你可以检查以下步骤:
- 在 vscode 上安装 eslint 扩展
- 在 vscode 设置中的格式设置部分,取消选中“保存时格式化”
- 将设置添加到 .vscode 文件夹中
根据你使用的功能/预设,可以将相关选项添加到 .vscode/settings.json
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": [
"source.fixAll.eslint"
],
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"]
}
- 关闭并重新打开 vscode
英文:
You can check this steps:
- Install eslint extention on vscode
- From vscode settings, formatting section, uncheck Format on save
- Add settings to .vscode folder
> Depending on which features/presets you are using, you can add the related options to .vscode/settings.json
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": [
"source.fixAll.eslint"
],
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"]
}
- Close and re-open vscode
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论