Skip to content

[import/order]: allowSeparatedGroups #3203

@otomad

Description

@otomad

ESLint sort-imports has a option allowSeparatedGroups that checks the sorting of import declaration statements only for those that appear on consecutive lines. But import/order doesn't have. Although you can achieve it by using groups and newlines-between options, I don't want to set the groups at eslint config, but respect the existed separated groups in the file.

For example:

Config rule:

{
	"import/order": ["warn", {
		"alphabetize": { "order": "asc", "orderImportKind": "asc", "caseInsensitive": false },
		"named": true,
	}],
}

Original code:

import c from "c";

import b from "b";
import a from "a";

Current fix behavior:

import a from "a";
import b from "b";
import c from "c";

Expected fix behavior:

import c from "c";

import a from "a";
import b from "b";

Original code:

// Group 1
import c from "c";
// Group 2
import e from "e";
import d from "d";
// Group 3
import b from "b";
import a from "a";

Current fix behavior:

// Group 1
import a from "a";
import b from "b";
import c from "c";
// Group 2
import d from "d";
import e from "e";
// Group 3

Expected fix behavior:

// Group 1
import c from "c";
// Group 2
import d from "d";
import e from "e";
// Group 3
import a from "a";
import b from "b";

I wish there will be a new option like allowSeparatedGroups in import/order rule to achieve this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions