Edit Post: Select blocks only once multiple verified#12477
Conversation
jorgefilipecosta
left a comment
There was a problem hiding this comment.
Looks good in my tests, as expected no behavior changes were noticed 👍
As referred, this would for sure be an excellent lint rule. Maybe it was already implemented by someone and is available.
The end 2 end tests fail seems totally unrelated and an intermittent problem, I restarted them.
I looked around a bit, and unfortunately couldn't find much. I started working on a rule, and found a few edge cases, mostly stylistic:
Here's my work-in-progress: It finds a lot of very interesting faults! Full report
|
|
Nice exploration 👍
For the destructuring case, I guess an error should be thrown if none of the variables destructured is used before the return if at least one is used I think it is fine.
Yes, I think only limiting to function calls makes sense. |
Related: #5031
This pull request seeks to optimize the multiple-use validation to avoid calling the
getBlocksselector until after verifying that a non-multiple-supporting block is present in the post. This should help alleviate some performance bottleneck for a currently-underperforming selector (getBlocks), particularly when the the condition will not apply for the vast majority of blocks.This is effectively a refactoring to reorganize code to only assign a variable value at a point where it is certain to be relevant for use by the remainder of the function. As an aside, it would be very interesting to try to develop a lint rule to verify that a variable is used before the next
returnstatement.Testing instructions:
Repeat testing instructions from #5031
Add a
console.countat the point thegetBlocksfunction is called, and verify that it is not called while authoring paragraph content (unlike before).