azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

Feature: `sort-imports` custom-groups Regex match #138

Open movahhedi opened 2 weeks ago

movahhedi commented 2 weeks ago

What rule do you want to change?

sort-imports

Describe the problem

To match imports in custom groups with Regex (instead of / along with) minimatch. Because minimatch doesn't support wildcard matching for parent paths. So i have to do something like:

// eslint.config.mjs
const longParentPath =
    "{.," +
    Array.from({ length: 10 }, (_, i) => "../".repeat(i + 1).slice(0, -1)).join(",") +
    "}";

// returns: {.,..,../..,../../..,../../../..,../../../../..,../../../../../..,../../../../../../..,../../../../../../../..,../../../../../../../../..,../../../../../../../../../..}

// ...
"custom-groups": {
    value: {
        "AdmoPro-Basics": `${longParentPath}/Basics/**`,
    },
    type: {
        "AdmoPro-Basics": `${longParentPath}/Basics/**`,
    },
}
// ...

to be able to match:

import { i18n } from "../../../Basics/Language";
// and
import { i18n } from "../../../../../Basics/Language";

and other similar imports in files with various depths.

Code example

Provided.

Additional comments

No response

Validations