forked from biomejs/biome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lint/useImportType):
jsxRuntime
wasn't respected in combined im…
…port statement (biomejs#2483)
- Loading branch information
Showing
6 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...biome_js_analyze/tests/specs/style/useImportType/valid-unused-react-combined.options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"linter": { | ||
"rules": { | ||
"style": { | ||
"useImportType": "error" | ||
} | ||
} | ||
}, | ||
"javascript": { | ||
"jsxRuntime": "reactClassic" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/biome_js_analyze/tests/specs/style/useImportType/valid-unused-react-combined.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React, { MouseEvent } from 'react'; | ||
|
||
function Component() { | ||
const onClick = (event: MouseEvent) => { }; | ||
const onDblClick = (event: React.MouseEvent) => { }; | ||
|
||
return <div onClick={onClick} onDblClick={onDblClick}></div>; | ||
} |
43 changes: 43 additions & 0 deletions
43
crates/biome_js_analyze/tests/specs/style/useImportType/valid-unused-react-combined.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: valid-unused-react-combined.tsx | ||
--- | ||
# Input | ||
```tsx | ||
import React, { MouseEvent } from 'react'; | ||
|
||
function Component() { | ||
const onClick = (event: MouseEvent) => { }; | ||
const onDblClick = (event: React.MouseEvent) => { }; | ||
|
||
return <div onClick={onClick} onDblClick={onDblClick}></div>; | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
valid-unused-react-combined.tsx:1:1 lint/style/useImportType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Some named imports are only used as types. | ||
> 1 │ import React, { MouseEvent } from 'react'; | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
2 │ | ||
3 │ function Component() { | ||
i This import is only used as a type. | ||
> 1 │ import React, { MouseEvent } from 'react'; | ||
│ ^^^^^^^^^^ | ||
2 │ | ||
3 │ function Component() { | ||
i Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules. | ||
i Safe fix: Use import type. | ||
1 │ import·React,·{·type·MouseEvent·}·from·'react'; | ||
│ +++++ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters