在 Visual Studio Code 中找不到自动修复保存按钮

vyt*_*ute 15 eslint visual-studio-code

我正在按照教程打开保存文件时的 ESLint 自动修复。教程演示了如何选中复选框。我找不到它。我需要任何扩展或 smth 吗?

转到:查看 -> 命令面板 -> 首选项:打开工作区设置 -> 扩展 -> ESLint

这是教程中设置页面的样子:

设置页面的外观

这就是我所看到的:

这是我看到的

hot*_*ink 36

该设置已弃用。Auto Fix on Save 现在是 VS Code 的 Code Action on Save 基础设施的一部分。请参阅发行说明。只是为了好玩,您可以通过添加"eslint.autoFixOnSave": truesettings.json来恢复复选框。但是,您现在需要添加的是:

  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
Run Code Online (Sandbox Code Playgroud)

  • 谢谢你,它有帮助:) 对于那些找不到 settings.json 文件的人:转到:文件 -> 首选项 -> 设置 -> ESLint。在那里您将看到“在 settings.json 中编辑”。(它在我之前提供的打印屏幕中可见) (3认同)

小智 5

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
}
Run Code Online (Sandbox Code Playgroud)

Since VSCode 1.56, this solution only works when you trigger save action manually by Ctrl/Cmd + S. It won't work with auto save with onFocusChange or onWindowChange.

In my case, I wanna trigger eslint anytime my code saved. So instead of using editor.codeActionsOnSave, I set eslint as the default formatter for js/ts, then trigger format on save.

"[javascript]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.format.enable": true,
"editor.formatOnSave": true,
Run Code Online (Sandbox Code Playgroud)