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
fix(lint/useJsxKeyInIterable): handle fragments more comprehensively #2747
fix(lint/useJsxKeyInIterable): handle fragments more comprehensively #2747
Conversation
cc6d7f2
to
c93fd10
Compare
CodSpeed Performance ReportMerging #2747 will not alter performanceComparing Summary
|
In Eslint, using fragments inside an iterator is encouraged by utilizing the Fragment component exported by React: a.map(e => <Fragment key={e.id}>{e}</Fragment>) I'm not necessarily advocating for this approach; just providing some food for thought. |
c93fd10
to
4a28330
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.
Recursion spotted! 😄 We should remove it
crates/biome_js_analyze/src/lint/correctness/use_jsx_key_in_iterable.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/correctness/use_jsx_key_in_iterable.rs
Outdated
Show resolved
Hide resolved
.filter_map(|child| { | ||
match &child { | ||
AnyJsxChild::JsxElement(_) | AnyJsxChild::JsxSelfClosingElement(_) => { | ||
any_tags_found = true; | ||
} | ||
// HACK: don't flag the entire fragment if there's a conditional expression | ||
AnyJsxChild::JsxExpressionChild(node) => { | ||
let expr = node.expression()?; | ||
if expr.as_js_conditional_expression().is_some() { | ||
any_tags_found = true; | ||
} | ||
} | ||
_ => {} | ||
} | ||
handle_jsx_child(&child, model) |
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.
Mixing a closure approach with internal filtering is not very idiomatic in the Rust world. I suggest using just a loop to collect the information that you require.
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.
Not sure if I've fixed this the way you want, but it looks a bit cleaner.
4a28330
to
77df690
Compare
crates/biome_js_analyze/src/lint/correctness/use_jsx_key_in_iterable.rs
Outdated
Show resolved
Hide resolved
77df690
to
e89f0d9
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.
Thank you! We should add a new changelog entry, then we can merge it
e89f0d9
to
3abadbe
Compare
Summary
This PR makes the
useJsxKeyInIterable
lint handle more cases related to JSX fragments. It can now handle cases like this:related to: #2590
Test Plan
Added snapshot tests
cargo test -p biome_js_analyze use_jsx_key_in_iterable