[英]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:修复当前文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.