Track JSX presence per-function, fixing some false negatives #830
+76
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Removing some false negatives of movable functions that were ignored because they were defined after some JSX
This is a follow up to 8a999c0
I noticed this example has a false negative:
where
doBaz
comes afterBar
, so it's treated as unmovable because the rule is using a singular boolean flag.If
const Bar = <div />
is moved to afterdoBaz
, it correctly identifies it as movable because the flag hasn't been set yet.The scope has to reach module-level again before the flag is turned off, meaning any safely-movable functions succeeding some JSX, or succeeding another scope with some JSX in are ignored.
This PR changes the rule to track whether JSX has been identified more finely, so it no longer ignores safe functions like these.
I tried this change out on a large-ish React codebase and whilst it picked up a previous false negative that could be safely moved, it didn't newly identify any false positives, so that's a good sign above and beyond the test examples.