import-js/eslint-plugin-import

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

Open

#1,746 opened on 2020年5月4日

GitHub で見る
 (12 comments) (13 reactions) (0 assignees)JavaScript (1,540 forks)batch import
enhancementhelp wantedquestion

Repository metrics

Stars
 (4,946 stars)
PR merge metrics
 (平均マージ 138d 22h) (30d で 3 merged PRs)

説明

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.

コントリビューターガイド