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

fix(rome_js_analyze): false positives for noUselessFragments #3668 #3858

Merged
merged 1 commit into from
Nov 28, 2022

Conversation

ematipico
Copy link
Contributor

Summary

Fixes #3668

Test Plan

Added two new test cases.

@netlify
Copy link

netlify bot commented Nov 25, 2022

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit a57a0bf
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/6380c86eb2816600096bd8aa

@MichaReiser
Copy link
Contributor

Would you mind giving this PR a more descriptive title. It's hard to guess what it is about from looking at the PR list or git log

@@ -108,31 +106,42 @@ impl Rule for NoUselessFragments {
let model = ctx.model();
match node {
NoUselessFragmentsQuery::JsxFragment(fragment) => {
let matches_allowed_parents = node
let parents_where_fragments_must_be_preserved = node
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be safer to instead allow list the parents where the fragment must not be preserved? That way adding new AST node types won't break the rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it wouldn't. I personally see it way harder to maintain

@ematipico ematipico changed the title fix(rome_js_analyze): false positives #3668 fix(rome_js_analyze): false positives for noUselessFragments #3668 Nov 25, 2022
.syntax()
.parent()
.and_then(|parent| {
if let Some(parenthesized_expression) =
Copy link
Contributor

Choose a reason for hiding this comment

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

This would need to use an equivalent of omit_parentheses iterating through the ancestor nodes, or it's only going to catch the first parenthesized expression it encounters and fail on a case like this: { key: (((<>content</>))) }

Copy link
Contributor Author

@ematipico ematipico Nov 25, 2022

Choose a reason for hiding this comment

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

Yes, I am aware of it and I intentionally left it out. I consider it an edge case that we can tackle if we really know if could cause issue.

There's to consider that the formatter will remove all the parentheses

@ematipico ematipico merged commit e373ce8 into main Nov 28, 2022
@ematipico ematipico deleted the fix/issue-3668 branch November 28, 2022 11:09
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.

🐛 noUselessFragments is inconsistent/buggy
3 participants