-
Notifications
You must be signed in to change notification settings - Fork 656
feat(rome_js_analyze): noUselessFragments
#3256
Conversation
✅ Deploy Preview for rometools canceled.
|
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
01a5c1b
to
0ac02c1
Compare
Comparing feat(rome_js_analyze):
1 page tested
|
Chrome Desktop | iPhone, 4G LTE | Motorola Moto G Power, 3G connection |
---|---|---|
Most significant changes
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
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragment.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragment.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragment.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_useless_fragment.rs
Outdated
Show resolved
Hide resolved
1e5a870
to
bc25873
Compare
bc25873
to
ca18225
Compare
crates/rome_js_analyze/tests/specs/nursery/noUselessFragment/withChildren.jsx.snap
Outdated
Show resolved
Hide resolved
warning[nursery/noUselessFragment]: Avoid using unnecessary Fragment. | ||
┌─ withChildren.jsx:2:5 | ||
│ | ||
2 │ <>foo</> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
bfe87d3
to
9b92b1d
Compare
There was a problem hiding this 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>
@leops the last commit adds a fix and test case to cover what you suggested. Nice catch! |
f1c9330
to
a653bcd
Compare
noUselessFragment
noUselessFragments
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