Skip to content

import/order: don't force new line on specific pathGroup #1746

@beatriz

Description

@beatriz

I would like to be able to have a specific pathGroup that doesn't force a newline.

My objective would be to have the imports ordered in the following manner (with react before all, but together with the external imports):

import React from "react";
import PropTypes from "prop-types";
import _ from "lodash";

import {Form, Input, Checkbox} from "antd";

At the moment I have this config:

"import/order": [
  "warn",
  {
    "groups": [
      "builtin",
      "external",
      "internal",
      ["parent", "sibling", "index"]
    ],
    "pathGroups": [
      {
        "pattern": "{antd,@ant-design/icons}",
        "group": "external",
        "position": "after"
      }
    ],
    "pathGroupsExcludedImportTypes": ["builtin"],
    "alphabetize": {"order": "asc"},
    "newlines-between": "always"
  }
]

Which forces me to alphabetize all the imports, to something like this:

import _ from "lodash";
import PropTypes from "prop-types";
import React from "react";

import {Form, Input, Checkbox} from "antd";

The only alternative I find is to add a specific pathGroup for react, with:

{
  "pattern": "react",
  "group": "external",
  "position": "before"
}

But this forces me to have a line between the react import and all other external imports.

Is there a way to have a specific pathGroup without newlines at the end?
As an alternative, I would be ok with not alphabetizing the imports on the external group, but I don't think this is possible either.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions