Skip to content

feat(organizeImports): allow grouping a subset of bare imports#10190

Draft
Conaclos wants to merge 1 commit into
nextfrom
conaclos/organizeImports-selective-bare-import-matching
Draft

feat(organizeImports): allow grouping a subset of bare imports#10190
Conaclos wants to merge 1 commit into
nextfrom
conaclos/organizeImports-selective-bare-import-matching

Conversation

@Conaclos
Copy link
Copy Markdown
Member

@Conaclos Conaclos commented May 1, 2026

Summary

We recently added two features:

  • the sortBareImports option that allows sorting all bare imports within other imports.
  • the kind group matcher (e.g., { "kind": "bare" }) that allows to group bare imports.
    This requires to turn on sortBareImports, otherwise these matchers are useless.

They impose two limitations:

  • It is not possible to group a subset of bare imports.
    For example, a user might want to group bare style imports only.
  • This can create some confusion if the user forgets to turn on sortBareImports and use bare import matchers.

This PR solves these two limitations by allowing to group bare imports matched by a bare import matcher without requiring to turn on sortBareImports.

Given the following config...

{ "groups": [
    { "kind": "bare", "source": ":STYLE:" }
  ]
}

We get the following sorting:

+ import "./c.css";
  import "./e.css";
  import d from "./d.js";
- import "./c.css";
  import "./x.js";
+ import "./a.css";
  import "./b.css";
- import "./a.css";

Because import "./x.js" is not matched, it still acts as an import chunk breaker.

A limitation of this system is that it doesn't play well with the implicit group.
For example if we want to group bare style imports at the end, a user could think it is enough to write the following config:

{ "groups": [
    // Note the negated kind using the exclamation mark `!`
    { "kind": "!bare", "source": ":STYLE:" }
  ]
}

Unfortunately, it is not the case because the implicit group doesn't match explicitly bare imports.
Thus, the user has to write:

{ "groups": [
    { "kind": "!bare" },
    { "kind": "bare", "source": ":STYLE:" }
  ]
}

Also, I took the opportunity to do some renaming to make the code easier to read.

Docs

TODO

  • changeset
  • Rule docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 1, 2026

⚠️ No Changeset found

Latest commit: 01adcec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels May 1, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 1, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 196 skipped benchmarks1


Comparing conaclos/organizeImports-selective-bare-import-matching (01adcec) with next (48bb032)

Open in CodSpeed

Footnotes

  1. 196 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant