Skip to content

Commit

Permalink
Removed all parse error warnings from sniffs and core (ref #2455)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jan 31, 2020
1 parent 9dd5641 commit 896ed40
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 48 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The file documents changes to the PHP_CodeSniffer project.
- The `--extensions` command line argument no longer accepts the tokenizer along with the extension
- Previously, you would check `.module` files as PHP files using `--extensions=module/php`
- Now, you use `--extensions=module`
- None of the included sniffs will warn about possible parse errors any more
- This improves the experience when the file is being checked inside an editor during live coding
- If you want to detect parse errors, use a linter instead
- Composer installs no longer include any test files

### Removed
Expand Down
3 changes: 1 addition & 2 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1683,8 +1683,7 @@ public function getMemberProperties($stackPtr)
if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
|| empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
) {
$error = 'Possible parse error: interfaces may not include member vars';
$this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
// Parse error or live coding.
return [];
}
} else {
Expand Down
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']).' '.$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 @@ -53,7 +53,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 @@ -47,8 +47,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
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 @@ -82,10 +82,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 @@ -47,9 +47,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 @@ -60,8 +60,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 @@ -74,9 +73,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) {
$error = 'Possible parse error: no opening 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 @@ -49,7 +49,7 @@ public function getErrorList()
*/
public function getWarningList()
{
return [71 => 1];
return [];

}//end getWarningList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getErrorList()
*/
public function getWarningList()
{
return [129 => 1];
return [];

}//end getWarningList()

Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Squiz/Tests/Scope/MemberVarScopeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getErrorList()
*/
public function getWarningList()
{
return [71 => 1];
return [];

}//end getWarningList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,21 @@ public function getErrorList()
public function getWarningList()
{
return [
6 => 1,
14 => 1,
20 => 1,
26 => 1,
32 => 1,
39 => 1,
45 => 1,
51 => 1,
64 => 1,
70 => 1,
73 => 1,
76 => 1,
79 => 1,
82 => 1,
94 => 1,
107 => 1,
6 => 1,
14 => 1,
20 => 1,
26 => 1,
32 => 1,
39 => 1,
45 => 1,
51 => 1,
64 => 1,
70 => 1,
73 => 1,
76 => 1,
79 => 1,
82 => 1,
94 => 1,
];

}//end getWarningList()
Expand Down

0 comments on commit 896ed40

Please sign in to comment.