Skip to content

fix(organizeImports): sort specifiers in bare exports#9353

Open
Conaclos wants to merge 2 commits intomainfrom
conaclos/sort-bare-exports
Open

fix(organizeImports): sort specifiers in bare exports#9353
Conaclos wants to merge 2 commits intomainfrom
conaclos/sort-bare-exports

Conversation

@Conaclos
Copy link
Member

@Conaclos Conaclos commented Mar 5, 2026

Summary

Fix partially #7583

This addresses the main issue which is sorting named specifiers of bare exports.
Here is an example of teh code action:

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

Test Plan

I added a test

Docs

I added a changeset.

@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: 7c1b786

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Mar 5, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29120c97-691b-4f25-b52d-3e52af341059

📥 Commits

Reviewing files that changed from the base of the PR and between 78d6feb and 7c1b786.

📒 Files selected for processing (2)
  • crates/biome_js_analyze/src/assist/source/organize_imports.rs
  • crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs

Walkthrough

Adds sorting support for named specifiers in bare export statements and wires it into the organize_imports flow. Introduces public modules import_key and specifiers_attributes (and a private util), a new JsExportNamedSpecifierList variant, and distinct APIs for export-from vs named-specifier lists (are/sort/merge functions). Updates sorting, merging and unsorted-item reporting paths to use the new helpers, adjusts trivia/newline handling, and includes a test demonstrating transforming export { b, a }; into export { a, b };.

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: fixing organizeImports to sort specifiers in bare exports, which aligns with the changeset and code modifications.
Description check ✅ Passed The description explains the motivation (fixing #7583), provides a concrete code example showing the before/after behaviour, mentions tests and changeset were added.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch conaclos/sort-bare-exports

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

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: 2

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

Inline comments:
In `@crates/biome_js_analyze/src/assist/source/organize_imports.rs`:
- Around line 857-864: The Issue::UnorganizedItem constructed when an export has
no `from` clause should not set are_attributes_unsorted to true; update the
UnorganizedItem creation in the block that pushes for exports (the one using
item.syntax().index(), are_specifiers_unsorted, and NewLineIssue::None) to set
are_attributes_unsorted: false to reflect that clause.attribute() is None and no
attributes exist to be unsorted.

In
`@crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs`:
- Around line 239-276: The function merge_export_specifiers is dead code (the
active merge path uses merge_export_from_specifiers) — either delete
merge_export_specifiers to remove unused code or keep it but document why (e.g.,
reserved for future “bare export” merging) and mark it as intentionally unused;
update the function comment to mention its relation to
merge_export_from_specifiers and the sort_export_specifiers behavior for
JsExportNamedSpecifierList so future readers understand its purpose, or remove
all references to it to eliminate the dead function entirely.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 530e72ef-e2a4-4de2-b63f-c5b14637827b

📥 Commits

Reviewing files that changed from the base of the PR and between 5046d2b and 168a2da.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/source/organizeImports/unsorted-from-less-export.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/neat-papers-think.md
  • crates/biome_js_analyze/src/assist/source/organize_imports.rs
  • crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs
  • crates/biome_js_analyze/tests/specs/source/organizeImports/unsorted-from-less-export.js

@Conaclos Conaclos force-pushed the conaclos/sort-bare-exports branch from 168a2da to 265367e Compare March 5, 2026 21:32
@github-actions github-actions bot added the A-LSP Area: language server protocol label Mar 5, 2026
@Conaclos Conaclos force-pushed the conaclos/sort-bare-exports branch 2 times, most recently from 64f6251 to 78d6feb Compare March 5, 2026 21:35
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 5, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing conaclos/sort-bare-exports (7c1b786) with main (cb4d7d7)

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.

@Conaclos Conaclos requested review from a team March 5, 2026 21:37
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.

🧹 Nitpick comments (3)
crates/biome_lsp/src/server.tests.rs (1)

2019-2019: Keep this fixture unsorted to preserve LSP coverage of the new behaviour.

Line 2019 is now already sorted, so this test no longer proves that organizeImports sorts bare export specifiers end-to-end. Consider keeping it unsorted (or adding a dedicated LSP case) and asserting the extra edit, so future regressions are caught.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_lsp/src/server.tests.rs` at line 2019, The test fixture's export
line "export { describe, test, z }" is now sorted which removes coverage for
LSP's organizeImports behavior; change that line back to an unsorted order
(e.g., "export { z, test, describe }" or similar) in the test fixture so the
organizer must reorder it, and update the corresponding test assertions in the
same test case (the one that triggers organizeImports) to expect the extra edit
produced by the LSP (assert the additional textEdit/WorkspaceEdit that sorts the
bare export specifiers). Ensure you update any helper names referenced in the
test case that locate the edits so the assertion targets the correct edit
produced by organizeImports.
crates/biome_js_analyze/src/assist/source/organize_imports.rs (1)

1177-1181: Minor typo polish: meregd_*merged_*.

Pure readability, but worth fixing while touching this path.

Suggested diff
-            if let Some(meregd_specifiers) =
+            if let Some(merged_specifiers) =
                 merge_export_from_specifiers(&specifiers1, &specifiers2, sort_order)
             {
-                let meregd_clause = clause1.with_specifiers(meregd_specifiers);
-                let merged_item = item2.clone().with_export_clause(meregd_clause.into());
+                let merged_clause = clause1.with_specifiers(merged_specifiers);
+                let merged_item = item2.clone().with_export_clause(merged_clause.into());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_js_analyze/src/assist/source/organize_imports.rs` around lines
1177 - 1181, There are typos in the temporary variable names: rename
meregd_specifiers to merged_specifiers, meregd_clause to merged_clause, and
update any usages (e.g., where meregd_clause is created from clause1 and where
merged_item is created using item2.with_export_clause) so they consistently use
merged_* names; keep the logic in merge_export_from_specifiers(specifiers1,
specifiers2, sort_order) and the subsequent with_specifiers/with_export_clause
calls unchanged, only correct the identifier spellings.
crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs (1)

20-27: Tiny naming tidy-up: fix specifeirs typo for readability.

No functional impact, but this typo appears in multiple match arms and makes scans a touch harder.

Suggested diff
-            Self::JsNamedImportSpecifiers(specifeirs) => {
-                are_import_specifiers_sorted(specifeirs, sort_order)
+            Self::JsNamedImportSpecifiers(specifiers) => {
+                are_import_specifiers_sorted(specifiers, sort_order)
             }
-            Self::JsExportNamedFromSpecifierList(specifeirs) => {
-                are_export_from_specifiers_sorted(specifeirs, sort_order)
+            Self::JsExportNamedFromSpecifierList(specifiers) => {
+                are_export_from_specifiers_sorted(specifiers, sort_order)
             }
-            Self::JsExportNamedSpecifierList(specifeirs) => {
-                are_export_specifiers_sorted(specifeirs, sort_order)
+            Self::JsExportNamedSpecifierList(specifiers) => {
+                are_export_specifiers_sorted(specifiers, sort_order)
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs`
around lines 20 - 27, Rename the misspelled local variable `specifeirs` to
`specifiers` in the match arms for Self::JsNamedImportSpecifiers,
Self::JsExportNamedFromSpecifierList, and Self::JsExportNamedSpecifierList so
the bindings read e.g. `Self::JsNamedImportSpecifiers(specifiers)` and update
the corresponding uses in the calls to are_import_specifiers_sorted,
are_export_from_specifiers_sorted, and are_export_specifiers_sorted to pass
`specifiers`; this is purely a rename for readability so ensure all occurrences
in that match branch are updated consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_js_analyze/src/assist/source/organize_imports.rs`:
- Around line 1177-1181: There are typos in the temporary variable names: rename
meregd_specifiers to merged_specifiers, meregd_clause to merged_clause, and
update any usages (e.g., where meregd_clause is created from clause1 and where
merged_item is created using item2.with_export_clause) so they consistently use
merged_* names; keep the logic in merge_export_from_specifiers(specifiers1,
specifiers2, sort_order) and the subsequent with_specifiers/with_export_clause
calls unchanged, only correct the identifier spellings.

In
`@crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs`:
- Around line 20-27: Rename the misspelled local variable `specifeirs` to
`specifiers` in the match arms for Self::JsNamedImportSpecifiers,
Self::JsExportNamedFromSpecifierList, and Self::JsExportNamedSpecifierList so
the bindings read e.g. `Self::JsNamedImportSpecifiers(specifiers)` and update
the corresponding uses in the calls to are_import_specifiers_sorted,
are_export_from_specifiers_sorted, and are_export_specifiers_sorted to pass
`specifiers`; this is purely a rename for readability so ensure all occurrences
in that match branch are updated consistently.

In `@crates/biome_lsp/src/server.tests.rs`:
- Line 2019: The test fixture's export line "export { describe, test, z }" is
now sorted which removes coverage for LSP's organizeImports behavior; change
that line back to an unsorted order (e.g., "export { z, test, describe }" or
similar) in the test fixture so the organizer must reorder it, and update the
corresponding test assertions in the same test case (the one that triggers
organizeImports) to expect the extra edit produced by the LSP (assert the
additional textEdit/WorkspaceEdit that sorts the bare export specifiers). Ensure
you update any helper names referenced in the test case that locate the edits so
the assertion targets the correct edit produced by organizeImports.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 96fa58fd-7929-48df-8d3d-a40ed49d44f2

📥 Commits

Reviewing files that changed from the base of the PR and between 168a2da and 78d6feb.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/source/organizeImports/unsorted-from-less-export.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (5)
  • .changeset/neat-papers-think.md
  • crates/biome_js_analyze/src/assist/source/organize_imports.rs
  • crates/biome_js_analyze/src/assist/source/organize_imports/specifiers_attributes.rs
  • crates/biome_js_analyze/tests/specs/source/organizeImports/unsorted-from-less-export.js
  • crates/biome_lsp/src/server.tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/neat-papers-think.md
  • crates/biome_js_analyze/tests/specs/source/organizeImports/unsorted-from-less-export.js

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.

1 participant