可以使用插件eslint-plugin-import进行配置。具体步骤如下:
- 首先,安装该插件:
npm install --save-dev eslint-plugin-import
- 在.eslintrc配置文件中添加插件:
{
"plugins": ["import"],
"rules": {
// your other rules
}
}
- 添加import/order规则,它将使用同样的顺序,就像VSCode的“Organize Imports”:
{
"plugins": ["import"],
"rules": {
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal", ["parent", "sibling", "object"]],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
]
}
}
其中,groups按照以下方式排序:内置模块(builtin) > 第三方模块(external) > 本地模块(internal) > 父级、同级和对象(parent、sibling、object)
newlines-between:按照引入组之间始终插入一个换行符
alphabetize:指定按字母顺序排序,不区分大小写
这样,eslint检查导入时将使用与VSCode相同的顺序。