如何在 WebStorm / PhpStorm 中自动按字母顺序对 TypeScript 文件的导入进行排序?
How to sort imports alphabetically for TypeScript files automatically in WebStorm / PhpStorm?
我使用带有默认配置的 tslint tslint:recommended
,我想尽可能少地调整规则。
某些规则强制执行 imports should be alphabetized:
src/core/task/TaskMockDecorator.ts[2, 1]: Import sources within a group must be alphabetized.
src/core/task/taskRunner.ts[1, 16]: Named imports must be alphabetized.
我不想自己按字母顺序对导入进行排序。在我禁用该 linting 之前:WebStorm / PhpStorm 可以为我做吗?
自 TSLint 4.0 起,ordered-imports 规则具有自动修复违规功能。您可以使用 --fix
标志通过 CLI 运行 它。
根据网络风暴:https://www.jetbrains.com/help/webstorm/tslint.html
With WebStorm, you can fix some of the issues reported by TSLint > automatically.
To fix a specific error, place the cursor at the highlighted code, press ⌥⏎, and then choose TSLint: fix current error from the pop-up menu.
To fix all the issues detected in the file, choose TSLint: fix current file.
在 WebStorm 和 Rider 中有默认的键映射操作 Optimize Imports,在 CTRL+ALT+O,我想它也存在于PhpStorm中。
我使用带有默认配置的 tslint tslint:recommended
,我想尽可能少地调整规则。
某些规则强制执行 imports should be alphabetized:
src/core/task/TaskMockDecorator.ts[2, 1]: Import sources within a group must be alphabetized.
src/core/task/taskRunner.ts[1, 16]: Named imports must be alphabetized.
我不想自己按字母顺序对导入进行排序。在我禁用该 linting 之前:WebStorm / PhpStorm 可以为我做吗?
自 TSLint 4.0 起,ordered-imports 规则具有自动修复违规功能。您可以使用 --fix
标志通过 CLI 运行 它。
根据网络风暴:https://www.jetbrains.com/help/webstorm/tslint.html
With WebStorm, you can fix some of the issues reported by TSLint > automatically.
To fix a specific error, place the cursor at the highlighted code, press ⌥⏎, and then choose TSLint: fix current error from the pop-up menu. To fix all the issues detected in the file, choose TSLint: fix current file.
在 WebStorm 和 Rider 中有默认的键映射操作 Optimize Imports,在 CTRL+ALT+O,我想它也存在于PhpStorm中。