Skip to content

Commit

Permalink
refactor: improve diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Nov 6, 2024
1 parent b13c3fe commit 4b54d9b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,22 @@ impl Rule for NoUnusedImports {
if let Some(blank_line_pos) = blank_line_pos {
// keep all leading trivia until the last blank line.
leading_trivia_pieces.truncate(blank_line_pos + 1);
if let Some(next_sibling) = parent.next_sibling() {
let new_next_sibling = next_sibling
.clone()
.prepend_trivia_pieces(leading_trivia_pieces)?;
mutation.replace_element_discard_trivia(
next_sibling.into(),
new_next_sibling.into(),
);
} else if let Some(prev_sibling) = parent.prev_sibling() {
if let Some(prev_sibling) = parent.prev_sibling() {
let new_prev_sibling = prev_sibling
.clone()
.append_trivia_pieces(leading_trivia_pieces)?;
mutation.replace_element_discard_trivia(
prev_sibling.into(),
new_prev_sibling.into(),
);
} else if let Some(next_sibling) = parent.next_sibling() {
let new_next_sibling = next_sibling
.clone()
.prepend_trivia_pieces(leading_trivia_pieces)?;
mutation.replace_element_discard_trivia(
next_sibling.into(),
new_next_sibling.into(),
);
}
}
mutation.remove_element(parent.into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ invalid-import-namespace.ts:4:18 lint/correctness/noUnusedImports FIXABLE ━
i Safe fix: Remove the unused imports.
1 1 │ import * as Ns1 from ""
2 2 │ export type T1 = Ns1;
3 │ -
2 │ - export·type·T1·=·Ns1;
2 │ + export·type·T1·=·Ns1;
3 3 │
4 │ - import·type·*·as·Ns2·from·""
3 │ +
5 4 │ export type T2 = Ns2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ invalid-unused-react.jsx:5:8 lint/correctness/noUnusedImports FIXABLE ━━
i Safe fix: Remove the unused imports.
1 1 │ import X from "react"
2 2 │ import * as X from "react"
3 3 │ import { default as X } from "react"
4 │ -
3 │ - import·{·default·as·X·}·from·"react"
3 │ + import·{·default·as·X·}·from·"react"
4 4 │
5 │ - import·React·from·"x"
4 │ +
6 5 │ import * as React from "x"
7 6 │ import { default as React } from "x"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ invalid.js:5:13 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
1 1 │ // Header comment
2 2 │ import A from "mod";
3 │ -
2 │ - import·A·from·"mod";
2 │ + import·A·from·"mod";
3 3 │
4 │ - //·Header·comment
5 │ - import·*·as·B·from·"mod";·//·Import·comment
6 3 │
4 │ +
6 4 │
7 5 │ // Header comment
8 6 │ import { C } from "mod"; // Import comment
```
Expand All @@ -108,15 +107,15 @@ invalid.js:8:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
3 3 │
4 4 │ // Header comment
5 5 │ import * as B from "mod"; // Import comment
6 │ -
5 │ - import·*·as·B·from·"mod";·//·Import·comment
5 │ + import·*·as·B·from·"mod";·//·Import·comment
6 6 │
7 │ - //·Header·comment
8 │ - import·{·C·}·from·"mod";·//·Import·comment
9 6 │
7 │ +
9 7 │
10 8 │ // Header comment
11 9 │ import /*a*/ D /*b*/, /*c*/{ E }/*d*/ from "mod"; // Import comment
```
Expand All @@ -136,15 +135,15 @@ invalid.js:11:14 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
6 6 │
7 7 │ // Header comment
8 8 │ import { C } from "mod"; // Import comment
9 │ -
8 │ - import·{·C·}·from·"mod";·//·Import·comment
8 │ + import·{·C·}·from·"mod";·//·Import·comment
9 9 │
10 │ - //·Header·comment
11 │ - import·/*a*/·D·/*b*/,·/*c*/{·E·}/*d*/·from·"mod";·//·Import·comment
12 9 │
10 │ +
12 10 │
13 11 │ import /*a*/ F /*b*/, /*c*/ * as G /*d*/ from "mod";
14 12 │
```
Expand All @@ -165,14 +164,14 @@ invalid.js:13:14 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
9 9 │
10 10 │ // Header comment
11 11 │ import /*a*/ D /*b*/, /*c*/{ E }/*d*/ from "mod"; // Import comment
12 │ -
11 │ - import·/*a*/·D·/*b*/,·/*c*/{·E·}/*d*/·from·"mod";·//·Import·comment
11 │ + import·/*a*/·D·/*b*/,·/*c*/{·E·}/*d*/·from·"mod";·//·Import·comment
12 12 │
13 │ - import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
14 12 │
13 │ +
14 13 │
15 14 │ import {
16 15 │ // Comment
```
Expand All @@ -198,18 +197,18 @@ invalid.js:15:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
11 11 │ import /*a*/ D /*b*/, /*c*/{ E }/*d*/ from "mod"; // Import comment
12 12 │
13 13 │ import /*a*/ F /*b*/, /*c*/ * as G /*d*/ from "mod";
14 │ -
13 │ - import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
13 │ + import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
14 14 │
15 │ - import·{
16 │ - ····//·Comment
17 │ - ····H,
18 │ - ····I,
19 │ - }·from·"mod";
20 14 │
15 │ +
20 15 │
21 16 │ import {/*a*/J/*b*/, /*c*/K/*d*/} from "mod";
22 17 │
```
Expand All @@ -230,14 +229,14 @@ invalid.js:21:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
17 17 │ H,
18 18 │ I,
19 19 │ } from "mod";
20 │ -
19 │ - }·from·"mod";
19 │ + }·from·"mod";
20 20 │
21 │ - import·{/*a*/J/*b*/,·/*c*/K/*d*/}·from·"mod";
22 20 │
21 │ +
22 21 │
23 22 │ // Header comment
24 23 │ import { L as M, } from "mod"; // Import comment
```
Expand All @@ -257,15 +256,15 @@ invalid.js:24:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
19 19 │ } from "mod";
20 20 │
21 21 │ import {/*a*/J/*b*/, /*c*/K/*d*/} from "mod";
22 │ -
21 │ - import·{/*a*/J/*b*/,·/*c*/K/*d*/}·from·"mod";
21 │ + import·{/*a*/J/*b*/,·/*c*/K/*d*/}·from·"mod";
22 22 │
23 │ - //·Header·comment
24 │ - import·{·L·as·M,·}·from·"mod";·//·Import·comment
25 22 │
23 │ +
25 23 │
26 24 │ // See https://github.com/biomejs/biome/issues/653
27 25 │ import {a} from 'a'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ invalid.jsx:5:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
1 1 │ import X from "react"
2 2 │ import * as X from "react"
3 3 │ import { default as X } from "react"
4 │ -
3 │ - import·{·default·as·X·}·from·"react"
3 │ + import·{·default·as·X·}·from·"react"
4 4 │
5 │ - import·React·from·"x"
4 │ +
6 5 │ import * as React from "x"
7 6 │ import { default as React } from "x"
Expand Down Expand Up @@ -210,12 +211,13 @@ invalid.jsx:11:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
6 6 │ import * as React from "x"
7 7 │ import { default as React } from "x"
8 8 │ import React, { useEffect } from "x"
9 │ -
8 │ - import·React,·{·useEffect·}·from·"x"
8 │ + import·React,·{·useEffect·}·from·"x"
9 9 │
10 │ - //·unsupported·patterns
11 │ - import·X,·{·default·as·React·}·from·"react"
9 │ +
12 10 │ import X, * as React from "react"
13 11 │
Expand Down Expand Up @@ -262,12 +264,13 @@ invalid.jsx:15:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
10 10 │ // unsupported patterns
11 11 │ import X, { default as React } from "react"
12 12 │ import X, * as React from "react"
13 │ -
12 │ - import·X,·*·as·React·from·"react"
12 │ + import·X,·*·as·React·from·"react"
13 13 │
14 │ - //·React·import·(no·exception)
15 │ - import·React·from·"react"
13 │ +
16 14 │ import * as React from "react"
17 15 │ import { default as React } from "react"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,13 @@ invalid.ts:5:18 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
1 1 │ // Header comment
2 2 │ import type A from "mod";
3 │ -
2 │ - import·type·A·from·"mod";
2 │ + import·type·A·from·"mod";
3 3 │
4 │ - //·Header·comment
5 │ - import·type·*·as·B·from·"mod";·//·Import·comment
6 3 │
4 │ +
6 4 │
7 5 │ // Header comment
8 6 │ import type { C } from "mod"; // Import comment
```
Expand All @@ -103,15 +102,15 @@ invalid.ts:8:13 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
3 3 │
4 4 │ // Header comment
5 5 │ import type * as B from "mod"; // Import comment
6 │ -
5 │ - import·type·*·as·B·from·"mod";·//·Import·comment
5 │ + import·type·*·as·B·from·"mod";·//·Import·comment
6 6 │
7 │ - //·Header·comment
8 │ - import·type·{·C·}·from·"mod";·//·Import·comment
9 6 │
7 │ +
9 7 │
10 8 │ // Orphan comment
11 9 │
```
Expand All @@ -131,19 +130,19 @@ invalid.ts:13:14 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
6 6 │
7 7 │ // Header comment
8 8 │ import type { C } from "mod"; // Import comment
9 │ -
8 │ - import·type·{·C·}·from·"mod";·//·Import·comment
8 │ + import·type·{·C·}·from·"mod";·//·Import·comment
9 │ +
10 │ + //·Orphan·comment
9 11 │
10 │ - //·Orphan·comment
11 │ -
12 │ - //·Header·comment
13 │ - import·/*a*/·D·/*b*/,·/*c*/{·type·E·}/*d*/·from·"mod";·//·Import·comment
14 9 │
10 │ + //·Orphan·comment
11 │ +
12 │ +
14 12 │
15 13 │ import /*a*/ F /*b*/, /*c*/ * as G /*d*/ from "mod";
16 14 │
```
Expand All @@ -164,14 +163,14 @@ invalid.ts:15:14 lint/correctness/noUnusedImports FIXABLE ━━━━━━
i Safe fix: Remove the unused imports.
11 11 │
12 12 │ // Header comment
13 13 │ import /*a*/ D /*b*/, /*c*/{ type E }/*d*/ from "mod"; // Import comment
14 │ -
13 │ - import·/*a*/·D·/*b*/,·/*c*/{·type·E·}/*d*/·from·"mod";·//·Import·comment
13 │ + import·/*a*/·D·/*b*/,·/*c*/{·type·E·}/*d*/·from·"mod";·//·Import·comment
14 14 │
15 │ - import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
16 14 │
15 │ +
16 15 │
17 16 │ import {
18 17 │ // Comment
```
Expand All @@ -197,18 +196,18 @@ invalid.ts:17:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
13 13 │ import /*a*/ D /*b*/, /*c*/{ type E }/*d*/ from "mod"; // Import comment
14 14 │
15 15 │ import /*a*/ F /*b*/, /*c*/ * as G /*d*/ from "mod";
16 │ -
15 │ - import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
15 │ + import·/*a*/·F·/*b*/,·/*c*/·*·as·G·/*d*/·from·"mod";
16 16 │
17 │ - import·{
18 │ - ····//·Comment
19 │ - ····type·H,
20 │ - ····type·I,
21 │ - }·from·"mod";
22 16 │
17 │ +
22 17 │
23 18 │ import {/*a*/type J/*b*/, /*c*/type K/*d*/} from "mod";
24 19 │
```
Expand All @@ -229,14 +228,14 @@ invalid.ts:23:8 lint/correctness/noUnusedImports FIXABLE ━━━━━━━
i Safe fix: Remove the unused imports.
19 19 │ type H,
20 20 │ type I,
21 21 │ } from "mod";
22 │ -
21 │ - }·from·"mod";
21 │ + }·from·"mod";
22 22 │
23 │ - import·{/*a*/type·J/*b*/,·/*c*/type·K/*d*/}·from·"mod";
24 22 │
23 │ +
24 23 │
25 24 │ // Header comment
26 25 │ import type { L as M, } from "mod"; // Import comment
```
Expand Down

0 comments on commit 4b54d9b

Please sign in to comment.