-
-
Notifications
You must be signed in to change notification settings - Fork 955
fix(lint): fixed the issue with false positive errors for noLeakedRender rule
#8306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3302fed
fix(noLeakedRender): fixed false positive errors
dibashthapa d3eb270
chores: added changeset
dibashthapa b9a815f
chores: removed duplicate test case
dibashthapa d4bdd58
chores: restored nested test cases
dibashthapa 3a75545
chores: fixed the namings inside test case
dibashthapa 62c6fc8
chores: changed to unwrap_or_default
dibashthapa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| --- | ||
| '@biomejs/biome': patch | ||
| --- | ||
|
|
||
| Fixed [#8288](https://github.com/biomejs/biome/issues/8288): Fixed the issue with false positive errors | ||
|
|
||
| This new change will ignore attribute and only show diagnostics for JSX Expressions | ||
|
|
||
| For example | ||
|
|
||
| Valid: | ||
|
|
||
| ```jsx | ||
| <Something checked={isOpen && items.length} /> | ||
| ``` | ||
|
|
||
| Invalid: | ||
| ```jsx | ||
| const Component = () =>{ | ||
| return isOpen && items.length | ||
| } | ||
| ``` |
This file contains hidden or 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 hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
crates/biome_js_analyze/tests/specs/nursery/noLeakedRender/issue8288.invalid.jsx
This file contains hidden or 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 @@ | ||
| /* should generate diagnostics */ | ||
| const Component1 = () => { | ||
| return ( | ||
| <Nested> | ||
| <SecondNested>{userId ? 1 : undefined} </SecondNested> | ||
| </Nested> | ||
| ); | ||
| }; |
36 changes: 36 additions & 0 deletions
36
crates/biome_js_analyze/tests/specs/nursery/noLeakedRender/issue8288.invalid.jsx.snap
This file contains hidden or 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,36 @@ | ||
| --- | ||
| source: crates/biome_js_analyze/tests/spec_tests.rs | ||
| expression: issue8288.invalid.jsx | ||
| --- | ||
| # Input | ||
| ```jsx | ||
| /* should generate diagnostics */ | ||
| const Component1 = () => { | ||
| return ( | ||
| <Nested> | ||
| <SecondNested>{userId ? 1 : undefined} </SecondNested> | ||
| </Nested> | ||
| ); | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
| # Diagnostics | ||
| ``` | ||
| issue8288.invalid.jsx:5:19 lint/nursery/noLeakedRender ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| i Potential leaked value that might cause unintended rendering. | ||
|
|
||
| 3 │ return ( | ||
| 4 │ <Nested> | ||
| > 5 │ <SecondNested>{userId ? 1 : undefined} </SecondNested> | ||
| │ ^^^^^^^^^^^^^^^^^^^^^^ | ||
| 6 │ </Nested> | ||
| 7 │ ); | ||
|
|
||
| i This happens when you use ternary operators in JSX with alternate values that could be variables. | ||
|
|
||
| i Replace with a safe alternate value like an empty string , null or another JSX element. | ||
|
|
||
|
|
||
| ``` |
35 changes: 35 additions & 0 deletions
35
crates/biome_js_analyze/tests/specs/nursery/noLeakedRender/issue8288.valid.jsx
This file contains hidden or 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,35 @@ | ||
| /* should not generate diagnostics */ | ||
| function getValue() { | ||
| return Math.random() > 0.5; | ||
| } | ||
|
|
||
| export default function MyComponent() { | ||
| return <button onClick={getValue() ? getValue : undefined} />; | ||
| } | ||
|
|
||
| const Component1 = () => { | ||
| return isPending ? loader : userResults; | ||
| }; | ||
|
|
||
| const Component2 = () => { | ||
| return someRandomId && !someRandomBooleanValue ? <ContentHere /> : <NotFound />; | ||
| }; | ||
|
|
||
| // Ignore Attribute | ||
| const Component3 = () => { | ||
| return ( | ||
| <NoErrorWithAttribute | ||
| error={firstBool && secondBool} | ||
| coerceError={!!(firstBool && secondBool)} | ||
| orderId={isChecked ? orderId : undefined} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const Component4 = () => { | ||
| return ( | ||
| <Nested> | ||
| <SecondNested>{userId ? 1 : null} </SecondNested> | ||
| </Nested> | ||
| ); | ||
| }; |
43 changes: 43 additions & 0 deletions
43
crates/biome_js_analyze/tests/specs/nursery/noLeakedRender/issue8288.valid.jsx.snap
This file contains hidden or 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: issue8288.valid.jsx | ||
| --- | ||
| # Input | ||
| ```jsx | ||
| /* should not generate diagnostics */ | ||
| function getValue() { | ||
| return Math.random() > 0.5; | ||
| } | ||
|
|
||
| export default function MyComponent() { | ||
| return <button onClick={getValue() ? getValue : undefined} />; | ||
| } | ||
|
|
||
| const Component1 = () => { | ||
| return isPending ? loader : userResults; | ||
| }; | ||
|
|
||
| const Component2 = () => { | ||
| return someRandomId && !someRandomBooleanValue ? <ContentHere /> : <NotFound />; | ||
| }; | ||
|
|
||
| // Ignore Attribute | ||
| const Component3 = () => { | ||
| return ( | ||
| <NoErrorWithAttribute | ||
| error={firstBool && secondBool} | ||
| coerceError={!!(firstBool && secondBool)} | ||
| orderId={isChecked ? orderId : undefined} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const Component4 = () => { | ||
| return ( | ||
| <Nested> | ||
| <SecondNested>{userId ? 1 : null} </SecondNested> | ||
| </Nested> | ||
| ); | ||
| }; | ||
|
|
||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.