在 WebStorm 中的导入和大括号之间添加空格

Adding spaces between imports and braces in WebStorm

是否可以在 WebStorm 的自动导入功能中在导入和大括号之间添加空格?

目前自动导入的样子:

import {AbstractControl} from '@angular/forms';

我想改成:

import { AbstractControl } from '@angular/forms';

是的。转到 WebStorm -> Preferences -> Editor -> Code Style -> JavaScript -> Spaces(第二个选项卡),滚动到 "Within" 部分并检查 ES6 import/export 大括号。

  • 对于 javascript 项目:

Go to WebStorm > File > Settings > Editor > Code Style > JavaScript > Spaces (second tab), scroll to section "Within" and check ES6 import/export braces.

  • 对于 TypeScript 项目:

Go to WebStorm > File > Settings > Editor > Code Style > TypeScript > Spaces (second tab), scroll to section "Within" and check ES6 import/export braces.

您可能需要检查 Spaces 选项卡的 Other 部分中的 Within interpolation expressions

虽然其他答案是正确的,但它们不可移植。您必须记住在您 运行 项目的所有机器上更改 IntelliJ。您可以将 .editorconfig 文件添加到您的项目中。

根据您对“IntelliJ/WebStorm”的具体要求,可以通过 将此行 放在文件 .editorconfig:

上来实现
ij_typescript_spaces_within_brackets = true

为了更好地说明 .editorconfig 文件的功能,请查看以下内容:

  • 将其标记为根(这样编辑器就不会在别处寻找)
  • 确保所有文件都是 utf-8
  • 如果文件与给定的扩展名相匹配,则会赋予它一些额外的属性
root = true

[*]
charset = utf-8

[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
ij_typescript_spaces_within_brackets = true