diff --git a/CHANGELOG.md b/CHANGELOG.md index 96aa6471b7c3..8fb958e6a710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,12 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b - Fix [#1748](https://github.com/biomejs/biome/issues/1748). Now for the following case we won't provide an unsafe fix for the `noNonNullAssertion` rule: + ```ts + x[y.z!]; + ``` + + Contributed by @ah-yu + - Imports that contain the protocol `:` are now sorted after the `npm:` modules, and before the `URL` modules. Contributed by @ematipico @@ -85,17 +91,13 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b + import Component from "./component.js" ``` - ```ts - x[y.z!]; - ``` - - Contributed by @ah-yu - - Fix [#1081](https://github.com/biomejs/biome/issues/1081). The `useAwait` rule does not report `for await...of`. Contributed by @unvalley - Fix [#1827](https://github.com/biomejs/biome/issues/1827) by properly analyzing nested `try-finally` statements. Contributed by @ah-yu +- Fix [#1924](https://github.com/biomejs/biome/issues/1924) Use the correct export name to sort in the import clause. Contributed by @ah-yu + ### CLI #### New features diff --git a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js new file mode 100644 index 000000000000..25f6f6e226bf --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js @@ -0,0 +1,2 @@ +import { path } from './foo'; +import { relative as relativePath, relative } from 'node:path'; diff --git a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js.snap b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js.snap new file mode 100644 index 000000000000..de0c7082fe80 --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/issue-1924.js.snap @@ -0,0 +1,19 @@ +--- +source: crates/biome_js_analyze/tests/spec_tests.rs +expression: issue-1924.js +--- +# Input +```jsx +import { path } from './foo'; +import { relative as relativePath, relative } from 'node:path'; + +``` + +# Actions +```diff +@@ -1,2 +1,2 @@ ++import { relative, relative as relativePath } from 'node:path'; + import { path } from './foo'; +-import { relative as relativePath, relative } from 'node:path'; + +``` diff --git a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js index a85055542bb5..93f8ef3ea6d1 100644 --- a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js +++ b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js @@ -52,3 +52,5 @@ import { k1, /* comment 1 */ k3, // comment 3 k2, /* comment 2 */ } from 'k'; + +import { m1 as m3, m2 } from 'm' diff --git a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js.snap b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js.snap index 7a3a8ddbdbc6..32d396b19017 100644 --- a/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js.snap +++ b/crates/biome_js_analyze/tests/specs/correctness/organizeImports/namedSpecifiers.js.snap @@ -59,11 +59,13 @@ import { k3, // comment 3 k2, /* comment 2 */ } from 'k'; +import { m1 as m3, m2 } from 'm' + ``` # Actions ```diff -@@ -1,54 +1,57 @@ +@@ -1,56 +1,59 @@ -import { a1, a3, a5, a2, a4 } from 'a'; +import { a1, a2, a3, a4, a5 } from 'a'; @@ -78,12 +80,12 @@ import { import { e1, -- e3, -- e5, - e2, -+ e3, - e4, -+ e5, ++ e2, + e3, ++ e4, + e5, +- e2, +- e4, } from 'e'; import { @@ -140,7 +142,8 @@ import { k3, // comment 3 - k2, /* comment 2 */ } from 'k'; +} from 'k'; + +-import { m1 as m3, m2 } from 'm' ++import { m2, m1 as m3 } from 'm' ``` - - diff --git a/crates/biome_js_syntax/src/import_ext.rs b/crates/biome_js_syntax/src/import_ext.rs index 54272018d389..dc1dc4fa26f0 100644 --- a/crates/biome_js_syntax/src/import_ext.rs +++ b/crates/biome_js_syntax/src/import_ext.rs @@ -130,10 +130,9 @@ impl AnyJsNamedImportSpecifier { /// ``` pub fn imported_name(&self) -> Option { match self { - Self::JsNamedImportSpecifier(specifier) => specifier.name().ok()?.value().ok(), - Self::JsShorthandNamedImportSpecifier(specifier) => specifier - .local_name() - .ok()? + specifier @ (Self::JsNamedImportSpecifier(_) + | Self::JsShorthandNamedImportSpecifier(_)) => specifier + .local_name()? .as_js_identifier_binding()? .name_token() .ok(), diff --git a/website/src/content/docs/internals/changelog.md b/website/src/content/docs/internals/changelog.md index a497e966dd97..f65149ff004a 100644 --- a/website/src/content/docs/internals/changelog.md +++ b/website/src/content/docs/internals/changelog.md @@ -80,6 +80,12 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b - Fix [#1748](https://github.com/biomejs/biome/issues/1748). Now for the following case we won't provide an unsafe fix for the `noNonNullAssertion` rule: + ```ts + x[y.z!]; + ``` + + Contributed by @ah-yu + - Imports that contain the protocol `:` are now sorted after the `npm:` modules, and before the `URL` modules. Contributed by @ematipico @@ -91,17 +97,13 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b + import Component from "./component.js" ``` - ```ts - x[y.z!]; - ``` - - Contributed by @ah-yu - - Fix [#1081](https://github.com/biomejs/biome/issues/1081). The `useAwait` rule does not report `for await...of`. Contributed by @unvalley - Fix [#1827](https://github.com/biomejs/biome/issues/1827) by properly analyzing nested `try-finally` statements. Contributed by @ah-yu +- Fix [#1924](https://github.com/biomejs/biome/issues/1924) Use the correct export name to sort in the import clause. Contributed by @ah-yu + ### CLI #### New features