在 VS Code 的自动格式上打开括号之前没有 space

No space before opening parenthesis on auto format in VS Code

如果我按 Shift + Alt + F 让 VS Code 格式化我的 JS它转换的源代码

for(var key in indexObj)

for (var key in indexObj)

如何防止 VS Code 这样做?

  • 安装 beautify plugin for VSCode
  • 创建一个 .jsbeautifyrc 文件。以this one为例
  • 将其 space_before_conditional 值设置为 false
  • 将文件放在您的主目录中以便全局使用它,或者将它放在您要格式化的 .js 所在的同一文件夹中
  • Shift+Alt+F 格式化代码

要在没有插件的情况下解决这个问题,您可以在 vscode settings.json:

上设置配置
{
  "editor.formatOnSave": false,
  "editor.formatOnType": false
}

或转到文件 - 首选项 - 设置,寻找保存时格式化并取消选中它。