-
-
Notifications
You must be signed in to change notification settings - Fork 687
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
Incorrect behavior of RemoveDeadStmtRector (and others?) with short echo tags #7789
Comments
That's possibly php-parser bug itself, as just by printing itself got additional https://getrector.com/demo/558b238e-b4d6-497c-918b-5b821c6b4e49 This also possibly related with issue: which commented custom syntax on I sent failing test case PR to nikic/php-parser for duplicated comment: for this use case, you may create another failing test case PR as well to https://github.com/nikic/PHP-Parser :) |
@samsonasik thank you for the reply! I'm not familiar with the details of PHP-Parser, but I cloned the repo and added a test locally:
Though the test failed, it only changed the following:
With rector, the same function (https://getrector.com/demo/9574e31f-3017-4d28-903b-490bcf416628) has a different replacement. PHP-Parser didn't appear to try and add Edit: <?php
function hi() {
// var_dump('hi');
?>
<img src="<?= escape('Test'); ?>">
<?php
} though https://getrector.com/demo/d04994f8-2e5b-44bc-8720-868074fd4caf does: <?php
function hi() {
// var_dump('hi');
?>
<img src="<?= escape('Test'); ?>">
<?php
} |
Demo page and local may have different addition You can try latest "rector/rector": "dev-main" locally |
@samsonasik When run locally, though I no longer get the extra closing tag from the second example above, I still get the weird tag doubling:
Are you thinking this is from PHP-Parser, though running tests through it as included above doesn't seem to result in doubling-up of php opening tags (rector turning Thanks! |
Yes, if no rule applied and open tag added, it possibly php-parser bug or cache somewhere, you may also try enable short open tag as @realtebo tried at #7784 (comment) and ensure run with There is ongoing todo on nikic/php-parser due to printing inlineHTML, see: |
@samsonasik Thanks for the continued advice! I ran it again locally, with I am running with the rules $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74
]); nikic/php-parser does seem to handle parsing the code fine, and only changes |
If unit test result is different with run on command, you may need to add
See the diff, and submit the pull request with expected output at https://github.com/rectorphp/rector-src/blob/main/e2e/plain-views/expected-output.diff then, create PR as failing test case PR, would be awesome if you can include the fix :) |
I am looking into it at PR: |
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/a7122f39-c255-4c56-908c-6f412f696ec4
Additionally, from https://getrector.com/demo/f3d8ac7d-212b-4cff-86bd-5939a2ee338f ,
Responsible rules
RemoveDeadStmtRector
Expected Behavior
For the first demo link, removing
$args;
and for the second either removing or ignoring the commented var_dump, but for both not also adding php open/close tags around otherwise functional short echo tag.The text was updated successfully, but these errors were encountered: