Skip to content

Commit 85c3a10

Browse files
committed
fix(formatter/sort_imports): Handle internal prefixes correctly (#16128)
| |Before|After| |-|-|-| | `from "@scoped/foo"`| internal (🐛) | external (✨) | | `from "@/foo"` | internal | internal |
1 parent 116e0d1 commit 85c3a10

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

crates/oxc_formatter/src/ir_transform/sort_imports/compute_metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ fn to_path_kind(source: &str) -> ImportPathKind {
365365
}
366366

367367
// TODO: This can be changed via `options.internalPattern`
368-
if source.starts_with('~') || source.starts_with('@') {
368+
if source.starts_with("~/") || source.starts_with("@/") {
369369
return ImportPathKind::Internal;
370370
}
371371

crates/oxc_formatter/tests/ir_transform/sort_imports.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ import("a");
6666
import b from "b";
6767
import c from "c";
6868
import("a");
69+
"#,
70+
);
71+
assert_format(
72+
r#"
73+
import internal from "~/internal";
74+
import internal2 from "@/internal2";
75+
import external from "external";
76+
import external2 from "@external2";
77+
"#,
78+
r#"{ "experimentalSortImports": {} }"#,
79+
r#"
80+
import external2 from "@external2";
81+
import external from "external";
82+
83+
import internal2 from "@/internal2";
84+
import internal from "~/internal";
6985
"#,
7086
);
7187
}

0 commit comments

Comments
 (0)