Is there any valid reason Rector should run more than once for one file? #7085
Replies: 1 comment 1 reply
-
Hi, it's the way the nodes and tokens are traversed. It usually does not happen, but it depends on use case. Here it's quite clear, as former doblock, not even PHP node, is convertded to a new element, an E.g. if a rule changes visibliity of method from Nodes are traversed from top to the bottom. See: https://github.com/nikic/PHP-Parser/blob/master/doc/2_Usage_of_basic_components.markdown#node-traversation Usually, you won't notice these as Rector runs in CI and commits changes untill there is no more. Still, my knowledge is limited, so maybe there is a way to handle these cases better. If you can see it, please propose a PR so we can save even more work 👍 (I've moved this to discussions, as this is not an issue, but rather topic to talk about.) |
Beta Was this translation helpful? Give feedback.
-
Question
I came accross this, for example, using the
AnnotationToAttributeRector
combined withNewlineAfterStatementRector
. The first pass converts the annotations to attributes, and the next pass (re-)adds the newlines. I would expect both of these rules to do their magic in a single pass.I found this behavior with ECS as well. I understand a bug could be causing the file to change, so that it has to be parsed again for a complete refactoring.
However, I am wondering if there would be any valid reason for this behavior to occur beyond of the scope of bugs -- if there is, how do I know (up front?) how many passes are needed for a file? One, two, maybe even more?
What is your point of view about this?
Beta Was this translation helpful? Give feedback.
All reactions