Skip to content

Commit

Permalink
File::addMessage(): do not ignore Internal errors when scanning sel…
Browse files Browse the repository at this point in the history
…ectively

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.
  • Loading branch information
jrfnl committed Oct 31, 2023
1 parent 7126fad commit f0040e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,19 @@ 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.
$aspTags = false;
if (PHP_VERSION_ID < 70000) {
$aspTags = (bool) ini_get('asp_tags');
}

$line1 = 1;
if ($aspTags === true) {
$line1 = 0;
}

return [
1 => $line1,
3 => 1,
4 => 1,
5 => 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

0 comments on commit f0040e5

Please sign in to comment.