-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Format-preserving bug for multipes NodeVisitors #400
Comments
I used this as hotfix for time being: rectorphp/rector@9ab6c84 |
Where is the CloningVisitor being applied? Unfortunately GH can only search master. |
I see. I use own ApIication for testing, because I don't know how to apply changes on dry-run (without changing actuall content): https://github.com/TomasVotruba/Rector/blob/9ab6c8462988fefe7597808dde214ce0eb8fe4cc/src/Testing/Application/FileReconstructor.php#L54-L67 Here's the printer: https://github.com/TomasVotruba/Rector/blob/new-rector-named-services/src/Printer/CodeStyledPrinter.php CloningVisitor is added to Dependecy Injection container and loaded to NodeTraverser. |
Does I tried using it fast and using it last and still there are some issues. |
@TomasVotruba It should definitely run first. To be on the safe side (especially if enterNode visitors are used), I'd also run it as an independent pass instead of interleaving it with other visitors. |
I tried your solution and it works like a charm 🍾 $cloningNodeTraverser = new PhpParser\NodeTraverser();
$cloningNodeTraverser->addVisitor(new PhpParser\NodeVisitor\CloningVisitor);
$oldStmts = $this->parser->parse($fileContent);
$oldTokens = $this->lexer->getTokens();
$newStmts = $cloningNodeTraverser->traverse($oldStmts);
$newStmts = $this->nodeTraverser->traverse($newStmts);
$prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens); Thank you! |
With format-perserving printer [#344] I came across weird bug.
I have 2 visitor modifying the code:
This is error output from Travis Report:
declare (strict_types=1);\n
is added instead of itThis would be understandable from some point, but...
But when I switch first 2 arguments, this NodeVisitor works but the other doesn't.
In this case,
afterTraverse()
isn't taken into account.The text was updated successfully, but these errors were encountered: