import-js/eslint-plugin-import

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

Open

#1,746 opened on May 4, 2020

View on GitHub
 (12 comments) (13 reactions) (0 assignees)JavaScript (1,540 forks)batch import
enhancementhelp wantedquestion

Repository metrics

Stars
 (4,946 stars)
PR merge metrics
 (Avg merge 138d 22h) (3 merged PRs in 30d)

Description

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.

Contributor guide