javascript eslint-plugin-import用于按软件包名称排序

xpszyzbs  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(86)

我已经按照以下顺序导入了:react first,外部包,代码库,当前目录
比如说

import * as React from "react"
import { css } from "emotion"
import a from "hooks" // this lives below emotion because I want to sort on package name

import Form from "my/own/component/path" // notice I also want gap between these imports

import Something from "./something" // import from current directory

如何使用eslint-plugin-import来更正规则?
到目前为止,我有这样的东西:

"import/order": [
      "error",
      {
        "alphabetize": {
          "caseInsensitive": true,
          "order": "asc"
        },
        "groups": ["external", "builtin", "parent", ["sibling", "index"]],
        "newlines-between": "never",
        "pathGroups": [
          {
            "group": "external",
            "pattern": "react",
            "position": "before"
          },
          {
            "group": "builtin",
            "pattern": "**",
            "position": "after"
          },
          {
            "group": "external",
            "pattern": "./**",
            "position": "after"
          }
        ],
        "pathGroupsExcludedImportTypes": ["builtin"]
      }
    ]

相关问题