eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

is any options to add `exclude pathGroup` in `import/order`?

Open deeeeno opened this issue 3 years ago • 4 comments

Hi. I have a question for using import/order

I have import ordering dependency in code, so I want to set pathGroup to exclude.

is any options to add exclude pathGroup in import/order?

deeeeno avatar Aug 21 '22 08:08 deeeeno

Can you elaborate? Example code and what you want it to do, and what it currently does, would be helpful.

ljharb avatar Aug 21 '22 15:08 ljharb

Hi @ljharb! Thanks for your reply!

In some reasons, I have to set css, scss file to buttom of import area. Here's example.

import React from 'react';
import ComponentA from 'client/component/A';
...
import Style from 'client/common/style/a.css'.  //have to be buttom
import StyleA from './styleA.scss';   //have to be bottom

I use alphabetize option in import/order, so when eslint --fix, Style import codes goes up. To prevent it, I set the parent, sibling group to bottom, but it only works for 'relative path'.

Here's my rules.

"import/order": [
      "error",
      {
        "groups": [
          "builtin",
          "external",
          "internal",
          "index",
          "object",
          "type",
          ["parent", "sibling"]
        ],
        "pathGroups": [
          {
            "pattern": "react*",
            "group": "builtin",
            "position": "before"
          },
        ],
        "pathGroupsExcludedImportTypes": ["react"],

        "alphabetize": {
          "order": "asc",
          "caseInsensitive": true
        },
        "newlines-between": "never"
      }
    ]

I want to make style import codes with using absolute path exclude for import/order rules

deeeeno avatar Aug 22 '22 00:08 deeeeno

Why do they have to be at the bottom?

ljharb avatar Aug 22 '22 18:08 ljharb

(also note that it's an absolute path only when it starts with /; it's a package specifier when it starts with something that's not . or /)

ljharb avatar Aug 22 '22 18:08 ljharb