Skip to content
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

PHPCBF fails to fix file with empty statement at start on control structure #2810

Closed
kkmuffme opened this issue Jan 10, 2020 · 2 comments
Closed

Comments

@kkmuffme
Copy link

phpcf gets stuck in an inifinite loop if the code contains "{;" (which can happen by accident)
It' will do loads of passes where it encounters 0/ violations remaining but then again there are 1, 2, many violations so it never ends.

Sample code:

if ( 2 === 2 ) {;
    echo "hello";
}

Sample output:

Registering sniffs in the abc standard... DONE (248 sniffs registered)
Creating file list... DONE (1 files in queue)
Changing into directory /some/path/
Processing test.php [PHP => 25 tokens in 5 lines]... DONE in 103ms (2 fixable violations)
        => Fixing file: 1/2 violations remaining [made 34 passes]... ^C

===

Suggested fix:

  1. solve that it doesn't end up stuck
  2. additionally if a line ends with {; the ; can be removed?
@gsherwood
Copy link
Member

This is replicated using the included Squiz standard, and is a conflict between Squiz.ControlStructures.ControlSignature and Squiz.WhiteSpace.SemicolonSpacing.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Feb 2, 2020
@gsherwood gsherwood added this to the 3.5.5 milestone Feb 2, 2020
@gsherwood gsherwood changed the title Bug: phpcf stuck on {; PHPCBF fails to fix file with empty statement at start on control structure Feb 18, 2020
gsherwood added a commit that referenced this issue Feb 18, 2020
gsherwood added a commit that referenced this issue Feb 18, 2020
gsherwood added a commit that referenced this issue Feb 18, 2020
gsherwood added a commit that referenced this issue Feb 18, 2020
@gsherwood
Copy link
Member

I've committed a fix for this. Given this is an empty statement, the Squiz.Whitespace.SemicolonSpacing sniff will now ignore it. The code will be fixed like this:

if ( 2 === 2 ) {
    ;
    echo "hello";
}

The Generic.CodeAnalysis.EmptyPHPStatement can be used to detect and fix the empty statement, although I had to commit a fix to get it working for this specific case. That will also be in 3.5.5.

Thanks for the report.

PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

No branches or pull requests

2 participants