我打算使用eslint来强制我的导入(import)按照标准顺序进行。
我已经实现了这一点,但是由于我设置了许多不同的路径以及TypeScript别名,我希望eslint规则在对外部包排序时排除它们,这导致了一个很长的eslint文件。
目前我的实现方式如下:
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal"],
"pathGroups": [
{
"pattern": "react*",
"group": "external",
"position": "before"
},
{
"pattern": "Components/**",
"group": "internal"
},
{
"pattern": "Constants/**",
"group": "internal"
}
... more patterns here
],
"pathGroupsExcludedImportTypes": ["react", "internal"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
我想知道是否有一种方法可以对这些模式进行分组,这样我就可以采取更类似于以下方式的操作:
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal"],
"pathGroups": [
{
"pattern": "react*",
"group": "external",
"position": "before"
},
{
"pattern": "Components/**|Constants/**|AnotherAlias/**|AnotherAlias/**",
"group": "internal"
}
],
"pathGroupsExcludedImportTypes": ["react", "internal"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],