【问题标题】:Autofix or shortcut for prettier issues in VS Code React Native projectVS Code React Native 项目中更漂亮问题的自动修复或快捷方式
【发布时间】:2020-01-12 10:08:11
【问题描述】:
我正在将 Visual Studio Code 与 React Native 项目一起使用。 ESLint 用于检查.prettierrc.js 中指定的内容。
当某些事情不正确时,我会得到这样的提示:
我不想获得这些通知并右键单击它们,选择Fix this prettier/prettier problem,而是希望自动或使用快捷方式组合解决问题。我该如何配置?我目前使用的是纯 JavaScript,没有 Typescript。
【问题讨论】:
标签:
react-native
visual-studio-code
prettier
【解决方案1】:
编辑/创建 .vscode/settings.json 使其包含
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
}
修复了保存问题。
【解决方案2】:
感谢@jonrsharpe!只是想加我几分钱。
-
转到 settings.json 文件:
- 视窗
%APPDATA%\Code\User\settings.json
- macOS
$HOME/Library/Application Support/Code/User/settings.json
- Linux
$HOME/.config/Code/User/settings.json
添加:
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
}
- 重启 VSCode
享受编码!))
更新
虽然在 Mac 上,上述解决方案对我有用,但在 Windows 上,我必须在 settings.json 中添加以下内容:
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll": true
},
"eslint.autoFixOnSave": true