Skip to content

fix(organizeImports): merge bare exports#9373

Merged
Conaclos merged 6 commits intomainfrom
conaclos/organizeImports-fix-7583
Mar 6, 2026
Merged

fix(organizeImports): merge bare exports#9373
Conaclos merged 6 commits intomainfrom
conaclos/organizeImports-fix-7583

Conversation

@Conaclos
Copy link
Member

@Conaclos Conaclos commented Mar 6, 2026

Summary

Fix #7583. Follow-up of #9353. organizeImports now merges bare exports:
Here is an example of bare export merging:

- export { a };
- export { b };
+ export { a, b };

Bare export are now sorted with other exports.
Bare exports are placed after export from. This is why I manually re-implemented Ord for ImportKey.
Here is an example:

- export { A };
  export * as path from "node:path";
+ export { A };

I chose this order because:

  • bare export are often placed at the end
  • export from statements are between import and export.
    Imports are usually placed first, then bare exports should be placed last (export from are in-between).
  • import with attributes are placed above import without attributes.
    Thus, placing exports with a from clause above exports without it follows the same logic.

Finally, this PR solves another issue reported some weeks or months ago about a missing blank line between imports and a bare export. Unfortunately, I didn't find the issue or discussion that brought it up.
Here is an example of the fix:

  import { A } from "package";
+
  export { A };

Test Plan

I added several tests.

Docs

I edited the changeset of #9353 to cover this PR.

@changeset-bot

This comment was marked as resolved.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Mar 6, 2026
/// If no group contains `candidate`, then the returned value corresponds to the index of the implicit group.
/// The index of the implicit group correspond to the number of groups.
pub fn index(&self, candidate: &ImportCandidate<'_>) -> u16 {
candidate.source.as_str();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a useless code. Strangely, this was not reported by Clippy.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Walkthrough

This change makes organizeImports sort and merge adjacent bare export specifier lists and insert a blank line between an import chunk and an export chunk. It refactors merge logic to combine JsExportNamedClause and JsExportNamedFromClause, preserves leading trivia on merged items, and introduces a public merge_export_specifiers function (duplicated). ImportKey/ImportInfo source fields were changed to Option<...> and Ord/PartialOrd were implemented for ImportKey. New tests and a custom options file exercise the behaviour.

Possibly related PRs

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(organizeImports): merge bare exports' directly summarizes the main change: implementing bare export merging in the organizeImports feature.
Description check ✅ Passed The description explains the motivation (fixing #7583), the key changes (merging bare exports, reordering exports and imports), includes concrete examples, and documents the test additions.
Linked Issues check ✅ Passed The PR fully addresses issue #7583 by implementing bare export merging with proper sorting, establishing a deterministic order (exports without 'from' after exports with 'from'), and adding the blank-line spacing fix.
Out of Scope Changes check ✅ Passed All changes are scoped to organizeImports functionality: enhanced merge logic for bare/named exports, updated import/export key ordering, new test cases, and configuration files—all directly aligned with fixing bare export handling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch conaclos/organizeImports-fix-7583

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

@Conaclos Conaclos requested review from a team March 6, 2026 20:24
@github-actions github-actions bot added the A-LSP Area: language server protocol label Mar 6, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/neat-papers-think.md:
- Around line 5-7: Update the changeset opener to the required bug-fix format by
replacing the current first sentence "Fixed
[`#7583`](https://github.com/biomejs/biome/issues/7583)." with "Fixed
[`#7583`](https://github.com/biomejs/biome/issues/7583): sorts named specifiers
inside bare exports and merges bare exports" (or similar concise description),
so the issue link is followed by a colon and the description; ensure the rest of
the blurb mentioning `organizeImports` remains unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 11d7de2f-19df-4fb0-93dd-2326ed5fc3ba

📥 Commits

Reviewing files that changed from the base of the PR and between 270c6a7 and 27e2436.

📒 Files selected for processing (2)
  • .changeset/neat-papers-think.md
  • crates/biome_lsp/src/server.tests.rs

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 6, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing conaclos/organizeImports-fix-7583 (c37ae5f) with main (78e74a2)2

Open in CodSpeed

Footnotes

  1. 156 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.

  2. No successful run was found on main (29cac17) during the generation of this report, so 78e74a2 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Conaclos Conaclos force-pushed the conaclos/organizeImports-fix-7583 branch from 08e9b65 to f7f7387 Compare March 6, 2026 20:56
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as duplicate.

@Conaclos Conaclos merged commit 3c8996c into main Mar 6, 2026
18 checks passed
@Conaclos Conaclos deleted the conaclos/organizeImports-fix-7583 branch March 6, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-LSP Area: language server protocol L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 oragnizeImports doesn't organize bare export

2 participants