简体   繁体   English

如何在 WebStorm / PhpStorm 中自动按字母顺序对 TypeScript 文件的导入进行排序?

[英]How to sort imports alphabetically for TypeScript files automatically in WebStorm / PhpStorm?

I use tslint with default config tslint:recommended and I want to adapt as less rules as possible.我将 tslint 与默认配置tslint:recommended并且我想尽可能减少规则。

Certain rules enforce that 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.

I don't want to sort the imports alphabetically by myself.我不想自己按字母顺序对导入进行排序。 Before I disable that linting: Can WebStorm / PhpStorm do that for me?在我禁用该 linting 之前:WebStorm / PhpStorm 可以为我做到这一点吗?

As of TSLint 4.0 , the ordered-imports rule features automatic fixing of violations.TSLint 4.0 开始,ordered-imports 规则具有自动修复违规的功能。 You can run it through the CLI with the --fix flag.您可以使用--fix标志通过 CLI 运行它。

According to webstorm: https://www.jetbrains.com/help/webstorm/tslint.html根据网络风暴: https ://www.jetbrains.com/help/webstorm/tslint.html

With WebStorm, you can fix some of the issues reported by TSLint > automatically.使用 WebStorm,您可以自动修复 TSLint > 报告的一些问题。

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.要修复特定错误,请将光标放在突出显示的代码上,按 ⌥⏎,然后从弹出菜单中选择 TSLint:修复当前错误。 To fix all the issues detected in the file, choose TSLint: fix current file.要修复文件中检测到的所有问题,请选择 TSLint:修复当前文件。

In WebStorm and Rider there is default keymap action to Optimize Imports , under CTRL+ALT+O , I suppose that it exist in PhpStorm as well.WebStormRider 中优化导入有默认的键盘映射操作,在CTRL+ALT+O 下,我想它也存在于PhpStorm中。

JetBrains Rider 设置的屏幕截图,其中显示了优化导入键盘映射

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebStorm,PHPStorm,Jetbrains IDEs - 忽略Typescript项目中的JS和MAP文件 - WebStorm, PHPStorm, Jetbrains IDEs - Ignore JS and MAP files in Typescript Project 使用phpstorm或webstorm进行TypeScript单元测试 - Unit Testing TypeScript with phpstorm or webstorm PhpStorm/WebStorm ESLint 自动修复 TypeScript - PhpStorm/WebStorm ESLint autofix TypeScript PhpStorm / WebStorm配色方案-TypeScript / JavaScript-如何定位注入的服务 - PhpStorm / WebStorm color scheme - TypeScript / JavaScript - how to target injected service TypeScript 自动导入中的 WebStorm/PhpStorm 双引号 - WebStorm/PhpStorm double quotes in TypeScript auto import WebStorm / PhpStorm中的TypeScript文件中的jQuery方法自动完成 - jQuery methods autocomplete in a TypeScript file in WebStorm / PhpStorm 按字母顺序排序 TypeScript 接口键 - alphabetically sort TypeScript interface keys 使用JSPM和Typescript改进Webstorm 11中的导入 - Improving the imports in Webstorm 11 using JSPM and Typescript 如何在 Angular 7 Material Design 的打字稿中按字母顺序对 mat-option 进行排序? - How to sort mat-option alphabetically in typescript in Angular 7 Material Design? WebStorm无法识别导入中的index.ts文件 - WebStorm not recognising index.ts files in imports
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM