如何配置VSCode的“组织导入"顺序? [英] How to config VSCode's Organize Imports order?
问题描述
我要配置组织导入"的订单.
I want to config Organize Imports's order.
现在,它将与node_modules相关的import语句移到最顶部,将本地 ts
文件移到最底部:
Right now, it moves node_modules related import statement at very top, and local ts
file at very bottom:
正常:
import myFunction from './myFunction';
import fs from 'fs';
console.log(fs)
console.log(myFunction)
运行组织导入"命令后:
After running Organize Imports command:
import fs from 'fs';
import myFunction from './myFunction';
console.log(fs)
console.log(myFunction)
我想做的是颠倒顺序,我希望node_modules非常底部,本地导入非常顶部.
What I want to do is reverse the order, I want node_modules to be very bottom, local imports to be very top.
如何实现这种行为?
推荐答案
The built-in "Organize Imports" functionality has no configuration, according to the documentation.
您可以使用第三方扩展程序(例如 alfnielsen.vsc-organize-imports
或使用单独的整理工具(如eslint或tslint).
You can customize import ordering using a third-party extension, such as alfnielsen.vsc-organize-imports
or by using a separate linting tool like eslint or tslint.
在eslint(我的建议,因为tslint已被弃用)中,您还需要使用类似快速修复.
In eslint (my recommendation, since tslint has been deprecated), you'll need to also use a plugin like eslint-plugin-import
to get the more-specific configuration you want. Then, instead of using the VSCode "Organize Imports" action, you'll use the "Fix All" action or a invoke a quick fix.
这是部分示例 .eslint.js
配置文件.
Here's a partial example .eslint.js
config file.
module.exports = {
plugins: [
"import",
],
rules: {
"import/order": [
"error",
{
groups: [
"index",
"sibling",
"parent",
"internal",
"external",
"builtin"
]
}
]
}
}
这篇关于如何配置VSCode的“组织导入"顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!