-
Notifications
You must be signed in to change notification settings - Fork 650
feat(rome_js_analyze): add support for spread props in various rules #3444
Conversation
✅ Deploy Preview for rometools ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
b79a3d0
to
83cd5ee
Compare
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Should this be a rule on itself? "Spread should be at the beginning on JSX bla bla bla". |
I think we had a rule that actually wanted to prevent the use of spread props, but it doesn't play well when using other components (like UI libraries) or library authors. If we had a some type information, we could make it a rule. |
crates/rome_js_analyze/src/analyzers/nursery/use_key_with_click_events.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/use_valid_anchor.rs
Outdated
Show resolved
Hide resolved
2bd5398
to
4ef322c
Compare
4ef322c
to
8d05644
Compare
///``` | ||
/// | ||
/// ```jsx, | ||
/// <div onClick={() => {}} {...spread}></div> |
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.
I'm not sure I get why onClick {...spread}
is valid but {...spread} onClick
is not, in both case the spread expression may inject an onKey*
event we don't know about ?
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 you're right, good catch
8d05644
to
5a708b8
Compare
5a708b8
to
cceccad
Compare
Summary
This PR adds support for checking the presence of spread attributes inside some rules around JSX. The position where the spread attribute is positioned is important. These two snippets yield two different results.
Considering that we don't have any typing information around the spread props, it's safe to assume that when a spread attribute is after the attribute that triggers the rule, the rule should not be triggered anymore, because the spread attribute might contain the correct attribute.
Test Plan
I added new test cases in the rules that have been affected