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

ScopeIndentSniff causes errors when encountering an unmatched parenthesis #554

Closed
XeroXer opened this issue Apr 16, 2015 · 1 comment
Closed

Comments

@XeroXer
Copy link

XeroXer commented Apr 16, 2015

This is a bug i noticed when running SublimeLinter-phpcs, which copies the content of the current file to a temporary file and runs phpcs on that temporary file.
My CPU went to 100% and freezed my computer, and after digging through the logs I found the problem.

This code:

<?php
/*
$a = array(
    */
);

I know the code is wrong and will trigger syntax errors, but it will also freeze up phpcs.
It will print two errors forever:

PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3431
PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3443

On similar code such as:

<?php
/*
$a = [
    */
];

and:

<?php
/*
if (true) {
    */
}

the checking will work as expected on. So without really checking the source it seems the parentheses triggers the problem.

PHP_CodeSniffer might not be meant as a way to check error code but should using it on a file with syntax errors not work, I don't know.
Might need to rethink using the plugin in that case, just thought I'd report this.

EDIT
Changed line 3430 from:
for ($i = $start; $i >= 0; $i--) {
to:
for ($i = (int) $start; $i >= 0; $i--) {
will end the infinite loop, but not solve the problem fully.
Checking the $start variable shows it being null, which created the infinite loop. Forcing it to an integer instead goes through the code, shows the errors but triggers other notices.

PHP Notice:  Undefined index: parenthesis_opener in .../PHP_CodeSniffer/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php on line 226
PHP Notice:  Undefined index:  in .../PHP_CodeSniffer/CodeSniffer/File.php on line 3431
@gsherwood gsherwood changed the title Block comment ending inside array, started before ScopeIndentSniff causes errors when encountering an unmatched parenthesis Apr 17, 2015
gsherwood added a commit that referenced this issue Apr 17, 2015
@gsherwood
Copy link
Member

Wherever possible, I like PHPCS to be able to recover from a parse error. I've fixed this problem in the ScopeIndent sniff - it was always assuming parenthesis were matched.

Thanks for reporting it.

jrfnl added a commit to jrfnl/PHP_CodeSniffer that referenced this issue Jul 29, 2024
…ric-uselessoverridingmethod-bugfix-close-tag

Generic/UselessOverridingMethod: improve handling of PHP open/close tags between statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants