WebStorm 的自动导入功能中是否可以在导入和大括号之间添加空格?
目前自动导入的样子:
import {AbstractControl} from '@angular/forms';
我想改成:
import { AbstractControl } from '@angular/forms';
转到 WebStorm > 文件 > 设置 > 编辑器 > 代码样式 > JavaScript > 空格(第二个选项卡),滚动到“内部”部分并 检查 ES6 导入/导出大括号。
转到 WebStorm > 文件 > 设置 > 编辑器 > 代码样式 > TypeScript > 空格(第二个选项卡),滚动到“Within”部分并检查 ES6 导入/导出大括号。
虽然其他答案是正确的,但它们不可移植。
您必须记住更改运行该项目的所有计算机上的 IntelliJ 设置。
还有更好的选择!
将
.editorconfig
文件添加到您的项目中。
根据您对“IntelliJ/WebStorm”的具体要求,可以通过将其放在
.editorconfig
上来实现:
ij_typescript_spaces_within_imports = true
您可以在此处阅读有关 IntelliJ 和特定
.editorconfig
规则的更多信息。
为了给您提供
.editorconfig
文件功能的更好示例,请检查以下内容:
根=真 [*] 字符集=utf-8 [*.{js,jsx,ts,tsx,vue}] 缩进样式 = 空格 缩进大小 = 2 行尾 = lf insert_final_newline = true 修剪_尾随_空白=真 ij_typescript_spaces_within_imports = true
更新
.editorconfig
,添加 typescript 和 javascript 文件的属性
[{*.ats,*.cts,*.mts,*.ts}]
ij_typescript_spaces_within_imports = true
[{*.cjs,*.js,*.jsx}]
ij_javascript_spaces_within_imports = true
您可能需要检查
Within interpolation expressions
选项卡的 Other
部分中的 Spaces
。