Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lint/origanizeImports): use the correct export name to sort in the import clause #1936

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { path } from './foo';
import { relative as relativePath, relative } from 'node:path';
Original file line number Diff line number Diff line change
@@ -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';

```
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ import {
k1, /* comment 1 */
k3, // comment 3
k2, /* comment 2 */ } from 'k';

import { m1 as m3, m2 } from 'm'
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -78,12 +80,12 @@ import {

import {
e1,
- e3,
- e5,
e2,
+ e3,
e4,
+ e5,
+ e2,
e3,
+ e4,
e5,
- e2,
- e4,
} from 'e';

import {
Expand Down Expand Up @@ -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'

```


7 changes: 3 additions & 4 deletions crates/biome_js_syntax/src/import_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ impl AnyJsNamedImportSpecifier {
/// ```
pub fn imported_name(&self) -> Option<JsSyntaxToken> {
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(),
Expand Down
14 changes: 8 additions & 6 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading