Adding multiple paths to eslint-plugin-import pattern

Viewed 24

I am looking to use eslint to force my imports to be in a standard order.

I have got this working, however it leads to a long eslint file as I have many different paths I have TypeScript aliases set up with that I want the eslint rules to exclude when sorting the external packages.

I have it working like this:

"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
    }
  }
],

I was wondering if there was a way to group the patterns, so I could do something more like this:

"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
    }
  }
],
0 Answers
Related