Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_analyze): noUselessFragments #3256

Merged
merged 8 commits into from
Sep 21, 2022
Merged

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Sep 20, 2022

Summary

It implements #3254

The old rule had also a suggested fix, which I would like to implement in another PR. Having this PR with the correct diagnostics, would help me later to avoid regressions.

It seems now that there are some recurrent patterns emerging, I will refactor them in another PR.

Test Plan

I added new test cases

@ematipico ematipico temporarily deployed to netlify-playground September 20, 2022 09:38 Inactive
@netlify
Copy link

netlify bot commented Sep 20, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit a653bcd
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/632b2a8f9357cd000928e7b2

@github-actions
Copy link

github-actions bot commented Sep 20, 2022

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44939 44939 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1621 1621 0
Failed 4325 4325 0
Panics 0 0 0
Coverage 27.26% 27.26% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12395 12395 0
Failed 3862 3862 0
Panics 0 0 0
Coverage 76.24% 76.24% 0.00%

@ematipico ematipico temporarily deployed to netlify-playground September 20, 2022 09:54 Inactive
@ematipico ematipico force-pushed the feature/no-useless-fragment branch from 01a5c1b to 0ac02c1 Compare September 20, 2022 15:23
@ematipico ematipico temporarily deployed to netlify-playground September 20, 2022 15:23 Inactive
@ematipico ematipico marked this pull request as ready for review September 20, 2022 15:23
@ematipico ematipico requested a review from a team September 20, 2022 15:23
@calibre-analytics
Copy link

calibre-analytics bot commented Sep 20, 2022

Comparing feat(rome_js_analyze): noUselessFragment Snapshot #14 to median since last deploy of rome.tools.

LCP? CLS? TBT?
Overall
Median across all pages and test profiles
1.89s
from 561ms
0.0
no change
174ms
from 46ms
Chrome Desktop
Chrome Desktop • Cable
1.89s
from 610ms
0.0
no change
357ms
from 239ms
iPhone, 4G LTE
iPhone 12 • 4G LTE
926ms
from 215ms
0.0
no change
0ms
no change
Motorola Moto G Power, 3G connection
Motorola Moto G Power • Regular 3G
12.5s
from 561ms
0.0
no change
174ms
from 46ms

1 page tested

 Home

Browser previews

Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection
Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection

Most significant changes

Value Budget
JS Parse & Compile
iPhone, 4G LTE
448ms
from 8ms
Total JavaScript Size in Bytes
Chrome Desktop
4.04 MB
from 86.8 KB
Total JavaScript Size in Bytes
iPhone, 4G LTE
4.04 MB
from 86.8 KB
Total JavaScript Size in Bytes
Motorola Moto G Power, 3G connection
4.04 MB
from 86.8 KB
JS Parse & Compile
Motorola Moto G Power, 3G connection
1.48s
from 31ms

28 other significant changes: JS Parse & Compile on Chrome Desktop, First Contentful Paint on Motorola Moto G Power, 3G connection, Largest Contentful Paint on Motorola Moto G Power, 3G connection, Speed Index on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection, Number of Requests on Motorola Moto G Power, 3G connection, Time to Interactive on Motorola Moto G Power, 3G connection, Number of Requests on Chrome Desktop, Number of Requests on iPhone, 4G LTE, First Contentful Paint on Chrome Desktop, Time to Interactive on Chrome Desktop, First Contentful Paint on iPhone, 4G LTE, Speed Index on Chrome Desktop, Speed Index on iPhone, 4G LTE, Largest Contentful Paint on iPhone, 4G LTE, Total Blocking Time on Motorola Moto G Power, 3G connection, Time to Interactive on iPhone, 4G LTE, Largest Contentful Paint on Chrome Desktop, Total Image Size in Bytes on Chrome Desktop, Total Image Size in Bytes on iPhone, 4G LTE, Total Image Size in Bytes on Motorola Moto G Power, 3G connection, Total HTML Size in Bytes on Chrome Desktop, Total HTML Size in Bytes on iPhone, 4G LTE, Total HTML Size in Bytes on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Chrome Desktop

Calibre: Site dashboard | View this PR | Edit settings | View documentation

@ematipico ematipico force-pushed the feature/no-useless-fragment branch from 1e5a870 to bc25873 Compare September 21, 2022 08:39
@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 08:39 Inactive
@ematipico ematipico force-pushed the feature/no-useless-fragment branch from bc25873 to ca18225 Compare September 21, 2022 09:14
@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 09:14 Inactive
warning[nursery/noUselessFragment]: Avoid using unnecessary Fragment.
┌─ withChildren.jsx:2:5
2 │ <>foo</>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Fragment jargon? Is it OK for us to assume that people know that <> is called a fragment or should we change the messaging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have a rule called useFragmentSyntax. Maybe that's where we can give more explanation?

@@ -18,7 +18,7 @@ createElement('div', {
# Diagnostics
```
warning[nursery/noDangerouslySetInnerHtml]: Avoid passing content using the dangerouslySetInnerHTML prop.
┌─ createElementBinding.js:4:5
┌─ createElementBindingInvalid.js:4:5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding an example with a comment (and yes, this is valid)

</* test */>empty</>;
<>empty</* comment */ />;
<>empty</ /* comment */>

I would argue that the rule should probably not trigger for these cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule as it is now triggers for these cases, it seems. Would you mind give us a reason, please? It seems an edge case, so I can better document the code and rule itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning is that these fragments are entirely useless because it is otherwise not possible to add the comments (except using an expression).

However, we could reason that we should flag these nonetheless but not provide an autofix because it is unclear where to place the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this rule is not over yet, there are still few cases that doesn't take into account. And the autofix will arrive with another PR :)

@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 14:44 Inactive
@ematipico ematipico force-pushed the feature/no-useless-fragment branch from bfe87d3 to 9b92b1d Compare September 21, 2022 14:51
@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 14:51 Inactive
Copy link
Contributor

@leops leops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this rule properly handle the case where the Fragment component is user-defined instead of being imported from React ? It seems important that the rule does not raise a diagnostic for this code:

function Fragment() {}
<Fragment>foo</Fragment>

@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 15:01 Inactive
@ematipico
Copy link
Contributor Author

@leops the last commit adds a fix and test case to cover what you suggested. Nice catch!

@ematipico ematipico force-pushed the feature/no-useless-fragment branch from f1c9330 to a653bcd Compare September 21, 2022 15:15
@ematipico ematipico temporarily deployed to netlify-playground September 21, 2022 15:15 Inactive
@ematipico ematipico changed the title feat(rome_js_analyze): noUselessFragment feat(rome_js_analyze): noUselessFragments Sep 21, 2022
@ematipico ematipico merged commit 38a7286 into main Sep 21, 2022
@ematipico ematipico deleted the feature/no-useless-fragment branch September 21, 2022 15:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants