-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
A combination of sniffs and their fixers produces syntactically invalid code #890
Comments
It should be fixed in bc3d492 But it only works with |
@kukulich although the fixed sniff no longer corrupts the file, it doesn't fix it either. Even with cat > composer.json << 'EOF'
{
"require-dev": {
"doctrine/coding-standard": "^7.0.2",
"slevomat/coding-standard": "dev-master as 6.1.5"
}
}
EOF
cat > phpcs.xml.dist << 'EOF'
<?xml version="1.0"?>
<ruleset>
<rule ref="Doctrine"/>
</ruleset>
EOF
cat > Problem.php << 'EOF'
<?php
declare(strict_types=1);
class Problem
{
public function test() : int
{
if (true) { // Comment
return 1;
} elseif (true) { // Comment
return 2;
} else { // Comment
return 3;
}
}
}
EOF
composer install
vendor/bin/phpcbf --version
# PHP_CodeSniffer version 3.5.4 (stable) by Squiz (http://www.squiz.net)
composer show | grep slevomat
# slevomat/coding-standard dev-master a741c09 Slevomat Coding Standar...
vendor/bin/phpcbf Problem.php
# ----------------------------------------------------------------------
# FILE FIXED REMAINING
# ----------------------------------------------------------------------
# /tmp/phpcs/Problem.php FAILED TO FIX
# ----------------------------------------------------------------------
# A TOTAL OF 3 ERRORS WERE FIXED IN 1 FILE
# ----------------------------------------------------------------------
# PHPCBF FAILED TO FIX 1 FILE
# ----------------------------------------------------------------------
cat Problem.php
# <?php
#
# declare(strict_types=1);
#
# class Problem
# {
# public function test() : int
# {
# if (true) { // Comment
# return 1;
# } elseif (true) { // Comment
# return 2;
# } else { // Comment
# return 3;
# }
# }
# } |
Strange, I used the code in my tests: bc3d492#diff-d6aa3d124fe7d65433e3980b6b6fb0bfR456 bc3d492#diff-b68d5ff564633e1b09b18146ab6377b8R522 But I use tabs. Maybe I should try spaces in the test. |
It looks like that. In #881 (comment), the inline comment extracted from the |
Improved in a05d520 The bug was in something else :) |
Thanks for the update. I just tried fixing the code example from #890 (comment) using I see that there’s a similar file fixed in the test added by a05d520. Is there potentially a conflict with other sniffs? |
It can be. Can you try to enable only EarlyExitSniff? |
phpcbf --sniffs=SlevomatCodingStandard.ControlStructures.EarlyExit Problem.php Yes, this way it works. |
JumpStatementsSpacing can conflict with it I think if you use it too. |
phpcbf --exclude=SlevomatCodingStandard.ControlStructures.JumpStatementsSpacing Problem.php You’re right. The above command was able to fix the file. Also applying the Is it something that could be fixed in a separate issue? Or it’s by design? In any event, this issue seems to be solved. Thanks a lot! |
I've just tried one small change in master. If it does not work I will give up. PHPCS fixer works in 50 loops. I think it should remove |
No, still cannot fix it (I tried d767b5e). I’ve experienced some more other conflicts when fixing the codebase, so I think I'll do some broader analysis of the failures first and then document them. Then we could decide if those conflicts are fixable or it’s by design and what the recommended approach to resolve them is. Thanks again! |
Ok, closing for now :) |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Below are the relevant dependency versions:
Consider the following code example:
All coding standard violations are reported as fixable and seem to be non-conflicting:
An attempt to fix this file using
phpcs
fails:and produces the following code:
Replacing
else if
withelseif
solves the syntax error issue but still doesn’t help the auto-fixing the violations.The text was updated successfully, but these errors were encountered: