From 0a2d7f1dbddf7a04687d8bcf7c95a54b96aa594b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 31 Oct 2023 18:46:37 +0100 Subject: [PATCH] File::addMessage(): do not ignore `Internal` errors when scanning selectively When either the `--sniffs=...` CLI parameter is used, or the `--exclude=...` CLI parameter, the `File::addMessage()` method bows out when an error is passed which is not for one of the selected sniffs/is for one of the excluded sniffs. Unfortunately, this "bowing out" did not take `Internal` errors into account, meaning those were now hidden, while those should _always_ be thrown as they generally inform the end-user of something seriously wrong (mixed line endings/no code found etc). Fixed now. Includes updating two test files to allow for seeing internal errors. --- src/Files/File.php | 1 + .../Tests/PHP/DisallowAlternativePHPTagsUnitTest.php | 8 ++++++++ .../Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/Files/File.php b/src/Files/File.php index 21cbeb2158..0a442b16ad 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -909,6 +909,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 diff --git a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php index 953e8ad9b5..93db3508f2 100644 --- a/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php @@ -89,7 +89,15 @@ public function getErrorList($testFile='') public function getWarningList($testFile='') { if ($testFile === 'DisallowAlternativePHPTagsUnitTest.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, 4 => 1, 5 => 1, diff --git a/src/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php b/src/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php index b79572ce6b..469fdd4530 100644 --- a/src/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php @@ -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,