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

4.0 | File::addMessage(): do not ignore Internal errors when scanning selectively #98

Open
wants to merge 2 commits into
base: 4.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
// Filter out any messages for sniffs that shouldn't have run
// due to the use of the --sniffs command line argument.
if ($includeAll === false
&& $parts[0] !== 'Internal'
&& ((empty($this->configCache['sniffs']) === false
&& in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
|| (empty($this->configCache['exclude']) === false
Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Generic/Tests/PHP/BacktickOperatorUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function getErrorList()
*/
public function getWarningList()
{
// Warning about incorrect annotation will be shown on line 1 once PR #3915 would be merged.
return [];
// Warning about incorrect annotation.
return [1 => 1];

}//end getWarningList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ public function getErrorList($testFile='')
public function getWarningList($testFile='')
{
if ($testFile === 'DisallowAlternativePHPTagsUnitTest.2.inc') {
// Check if the Internal.NoCodeFound error can be expected on line 1.
$option = (bool) ini_get('short_open_tag');
$line1 = 1;
if ($option === true) {
$line1 = 0;
}

return [
1 => $line1,
2 => 1,
3 => 1,
4 => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ public function getWarningList($testFile='')
case 'DisallowShortOpenTagUnitTest.1.inc':
return [];
case 'DisallowShortOpenTagUnitTest.3.inc':
// Check if the Internal.NoCodeFound error can be expected on line 1.
$option = (bool) ini_get('short_open_tag');
$line1 = 1;
if ($option === true) {
$line1 = 0;
}
return [
1 => $line1,
3 => 1,
6 => 1,
11 => 1,
Expand Down
22 changes: 11 additions & 11 deletions tests/Core/ErrorSuppressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ public function dataNestedSuppressLine()

// Process with line suppression nested within disable/enable suppression.
'disable/enable: slash comment, next line nested single line suppression' => [
'before' => '// phpcs:disable'.PHP_EOL.'// phpcs:ignore',
'before' => '// phpcs:disable'."\n".'// phpcs:ignore',
'after' => '// phpcs:enable',
],
'disable/enable: slash comment, with @, next line nested single line suppression' => [
'before' => '// @phpcs:disable'.PHP_EOL.'// @phpcs:ignore',
'before' => '// @phpcs:disable'."\n".'// @phpcs:ignore',
'after' => '// @phpcs:enable',
],
'disable/enable: hash comment, next line nested single line suppression' => [
'before' => '# @phpcs:disable'.PHP_EOL.'# @phpcs:ignore',
'before' => '# @phpcs:disable'."\n".'# @phpcs:ignore',
'after' => '# @phpcs:enable',
],
];
Expand Down Expand Up @@ -671,7 +671,7 @@ public function dataSuppressFile()
'ignoreFile: start of file, hash comment, with @' => ['before' => '# @phpcs:ignoreFile'],
'ignoreFile: start of file, single-line star comment' => ['before' => '/* phpcs:ignoreFile */'],
'ignoreFile: start of file, multi-line star comment' => [
'before' => '/*'.PHP_EOL.' phpcs:ignoreFile'.PHP_EOL.' */',
'before' => '/*'."\n".' phpcs:ignoreFile'."\n".' */',
],
'ignoreFile: start of file, single-line docblock comment' => ['before' => '/** phpcs:ignoreFile */'],

Expand Down Expand Up @@ -752,18 +752,18 @@ public function dataDisableSelected()
'expectedErrors' => 1,
],
'disable: single sniff, docblock' => [
'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ ',
'before' => '/**'."\n".' * phpcs:disable Generic.Commenting.Todo'."\n".' */ ',
'expectedErrors' => 1,
],
'disable: single sniff, docblock, with @' => [
'before' => '/**'.PHP_EOL.' * @phpcs:disable Generic.Commenting.Todo'.PHP_EOL.' */ ',
'before' => '/**'."\n".' * @phpcs:disable Generic.Commenting.Todo'."\n".' */ ',
'expectedErrors' => 1,
],

// Multiple sniffs.
'disable: multiple sniffs in one comment' => ['before' => '// phpcs:disable Generic.Commenting.Todo,Generic.PHP.LowerCaseConstant'],
'disable: multiple sniff in multiple comments' => [
'before' => '// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:disable Generic.PHP.LowerCaseConstant',
'before' => '// phpcs:disable Generic.Commenting.Todo'."\n".'// phpcs:disable Generic.PHP.LowerCaseConstant',
],

// Selectiveness variations.
Expand All @@ -780,17 +780,17 @@ public function dataDisableSelected()

// Wrong category/sniff/code.
'disable: wrong error code and category' => [
'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.PHP.LowerCaseConstant.Upper,Generic.Comments'.PHP_EOL.' */ ',
'before' => '/**'."\n".' * phpcs:disable Generic.PHP.LowerCaseConstant.Upper,Generic.Comments'."\n".' */ ',
'expectedErrors' => 1,
'expectedWarnings' => 1,
],
'disable: wrong category, docblock' => [
'before' => '/**'.PHP_EOL.' * phpcs:disable Generic.Files'.PHP_EOL.' */ ',
'before' => '/**'."\n".' * phpcs:disable Generic.Files'."\n".' */ ',
'expectedErrors' => 1,
'expectedWarnings' => 1,
],
'disable: wrong category, docblock, with @' => [
'before' => '/**'.PHP_EOL.' * @phpcs:disable Generic.Files'.PHP_EOL.' */ ',
'before' => '/**'."\n".' * @phpcs:disable Generic.Files'."\n".' */ ',
'expectedErrors' => 1,
'expectedWarnings' => 1,
],
Expand Down Expand Up @@ -1047,7 +1047,7 @@ public function dataIgnoreSelected()
'expectedWarnings' => 1,
],
'disable: single sniff; ignore: single sniff' => [
'before' => '// phpcs:disable Generic.Commenting.Todo'.PHP_EOL.'// phpcs:ignore Generic.PHP.LowerCaseConstant',
'before' => '// phpcs:disable Generic.Commenting.Todo'."\n".'// phpcs:ignore Generic.PHP.LowerCaseConstant',
'expectedErrors' => 1,
'expectedWarnings' => 0,
],
Expand Down