Skip to content

Removed all parse error warnings from sniffs #990

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function process(File $phpcsFile, $stackPtr)
$errorData = [strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scopeIdentifier]['content']];

if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Test_Class_Bad_H extends Test_Class_Bad_G {
class Test_Class_Bad_I implements Test_Interface_Bad_C{
}

// This one should be flagged as a potential parse error.
// This one should be ignored as a potential parse error.
class Test_Class_Bad_H

// This is OK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Test_Class_Bad_H extends Test_Class_Bad_G {
class Test_Class_Bad_I implements Test_Interface_Bad_C {
}

// This one should be flagged as a potential parse error.
// This one should be ignored as a potential parse error.
class Test_Class_Bad_H

// This is OK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getErrorList()
*/
public function getWarningList()
{
return [51 => 1];
return [];

}//end getWarningList()

Expand Down
3 changes: 1 addition & 2 deletions src/Standards/PEAR/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function process(File $phpcsFile, $stackPtr)
$errorData = [strtolower($tokens[$stackPtr]['content'])];

if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ if (!class_exists('ClassOpeningBraceTabIndented')) {
}


// Needs to be last test in the file. Intentional parse error.
// Needs to be last test in the file. Intentional parse error. Should be ignored.
class MyParseError extends Exception
4 changes: 0 additions & 4 deletions src/Standards/PEAR/Tests/Classes/ClassDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ public function getErrorList($testFile='')
*/
public function getWarningList($testFile='')
{
if ($testFile === 'ClassDeclarationUnitTest.2.inc') {
return [11 => 1];
}

return[];

}//end getWarningList()
Expand Down
4 changes: 1 addition & 3 deletions src/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function process(File $phpcsFile, $stackPtr)
$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public function process(File $phpcsFile, $stackPtr)
}

if (isset($tokens[$stackPtr]['scope_closer']) === false) {
$error = 'Possible parse error: non-abstract method defined as abstract';
$phpcsFile->addWarning($error, $stackPtr, 'Abstract');
// Parse error or live coding.
return;
}

Expand All @@ -80,9 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
}//end if

if (isset($tokens[$stackPtr]['scope_closer']) === false) {
$error = 'Possible parse error: %s missing opening or closing brace';
$data = [$tokens[$stackPtr]['content']];
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $data);
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ public function process(File $phpcsFile, $stackPtr)

$openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
if ($openingBracket === false) {
$error = 'Possible parse error: FOREACH has no opening parenthesis';
$phpcsFile->addWarning($error, $stackPtr, 'MissingOpenParenthesis');
// Parse error or live coding.
return;
}

if (isset($tokens[$openingBracket]['parenthesis_closer']) === false) {
$error = 'Possible parse error: FOREACH has no closing parenthesis';
$phpcsFile->addWarning($error, $stackPtr, 'MissingCloseParenthesis');
// Parse error or live coding.
return;
}

Expand Down Expand Up @@ -134,8 +132,7 @@ public function process(File $phpcsFile, $stackPtr)

$asToken = $phpcsFile->findNext(T_AS, $openingBracket);
if ($asToken === false) {
$error = 'Possible parse error: FOREACH has no AS statement';
$phpcsFile->addWarning($error, $stackPtr, 'MissingAs');
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public function process(File $phpcsFile, $stackPtr)

$openingBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr);
if ($openingBracket === false || isset($tokens[$openingBracket]['parenthesis_closer']) === false) {
$error = 'Possible parse error: no opening/closing parenthesis for FOR keyword';
$phpcsFile->addWarning($error, $stackPtr, 'NoOpenBracket');
// Parse error or live coding.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public function process(File $phpcsFile, $stackPtr)
}

if (isset($tokens[$nextCase]['scope_opener']) === false) {
$error = 'Possible parse error: CASE missing opening colon';
$phpcsFile->addWarning($error, $nextCase, 'MissingColon');
// Parse error or live coding.
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface TestClass

class MyClass
{
public function myFunction();
public function parseErrorMustBeIgnored();
}//end class

// Closures don't need end comments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface TestClass

class MyClass
{
public function myFunction();
public function parseErrorMustBeIgnored();
}//end class

// Closures don't need end comments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Intentional parse error (missing opening bracket).
// This should be the only test in this file.
// Testing that the sniff is triggered.
// Testing that the sniff stays silent.

class MissingOpeningBracket
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Intentional parse error (missing closing bracket).
// This should be the only test in this file.
// Testing that the sniff is triggered.
// Testing that the sniff stays silent.

class MissingClosingBracket {
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ public function getErrorList($testFile='')
*/
public function getWarningList($testFile='')
{
switch ($testFile) {
case 'ClosingDeclarationCommentUnitTest.1.inc':
return [71 => 1];

case 'ClosingDeclarationCommentUnitTest.2.inc':
case 'ClosingDeclarationCommentUnitTest.3.inc':
return [7 => 1];

default:
return [];
}
return [];

}//end getWarningList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// Parse error/live coding test (no parentheses).
// This test has to be the only test in the file!
// Testing the "NoOpenBracket" warning.
// This should be ignored.
for
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// Parse error/live coding test (no close parenthesis).
// This test has to be the only test in the file!
// Testing the "NoOpenBracket" warning.
// This should be ignored.
for ($i = 10;
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,7 @@ public function getErrorList($testFile='')
*/
public function getWarningList($testFile='')
{
switch ($testFile) {
case 'ForLoopDeclarationUnitTest.2.inc':
case 'ForLoopDeclarationUnitTest.3.inc':
return [6 => 1];

default:
return [];
}//end switch
return [];

}//end getWarningList()

Expand Down