顾名思义,是对导入的模块进行排序,成果如下:

比照排序前后代码,排序后的代码看起来更整洁,react**全家桶内部库公共组件子组件api工具类顺次排列。

罕用规定配置

{  "import/order": ["error", {        "groups": [          "builtin",      "external",      ["internal", "parent", "sibling", "index"],      "unknown",        ],    "pathGroups": [      {        "pattern": "@app/**",        "group": "external",        "position": "after"      }    ],    "pathGroupsExcludedImportTypes": ["builtin"],        "newlines-between": "always",        "alphabetize": {            "order": "asc",            "acseInsensitive": true        }  }]}

其中,group 是对导入模块进行分组,pathGroups 是通过门路自定义分组,newlines-between 不同组之间是否进行换行,alphabetize 依据字母程序对每个组内的程序进行排序

重点介绍下 pathGroups 属性,该属性有 4 个子属性:

  • pattern:以后组中模块的最短门路匹配
  • patternOptions:如果须要更准确的匹配,看这里
  • group:在规定的组当选其一,indexsiblingparentinternalexternalbuiltinobjecttypeunknown
  • position:定义组的地位,afterbefore

对于 pathGroupsExcludedImportTypes 的作用愣是没看懂,欢送大家补充。