VS Code React Native 项目中更漂亮问题的自动修复或快捷方式

ste*_*wpf 2 react-native visual-studio-code prettier

我在 React Native 项目中使用 Visual Studio Code。ESLint 用于检查.prettierrc.js. 当某些事情不正确时,我会收到这样的提示:

在此处输入图片说明

Fix this prettier/prettier problem我希望自动或使用快捷方式组合修复这些问题,而不是获取这些通知并右键单击它们,选择。我该如何配置?我目前使用纯 JavaScript,没有打字稿。

ste*_*wpf 7

编辑/创建.vscode/settings.json以便它将包含

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

修复保存问题。


Ant*_*gin 5

感谢@jonrsharpe!只是想添加我的几分钱。

  1. 转到settings.json文件:

    • 视窗%APPDATA%\Code\User\settings.json
    • 苹果系统$HOME/Library/Application Support/Code/User/settings.json
    • Linux$HOME/.config/Code/User/settings.json
  2. 在那里添加:

 {
   "editor.codeActionsOnSave": {
     "source.fixAll.eslint": true
   },
 }
Run Code Online (Sandbox Code Playgroud)
  1. 重启VSCode

享受编码的乐趣!))

更新

虽然在 Mac 上,上述解决方案对我有用,但在 Windows 上,为了使其工作,我必须将以下内容添加到settings.json

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