Skip to content

Commit 8ac4805

Browse files
committed
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 three test files to allow for seeing internal errors.
1 parent b28e39a commit 8ac4805

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/Files/File.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
879879
// Filter out any messages for sniffs that shouldn't have run
880880
// due to the use of the --sniffs command line argument.
881881
if ($includeAll === false
882+
&& $parts[0] !== 'Internal'
882883
&& ((empty($this->configCache['sniffs']) === false
883884
&& in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
884885
|| (empty($this->configCache['exclude']) === false

src/Standards/Generic/Tests/PHP/BacktickOperatorUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function getErrorList()
4343
*/
4444
public function getWarningList()
4545
{
46-
// Warning about incorrect annotation will be shown on line 1 once PR #3915 would be merged.
47-
return [];
46+
// Warning about incorrect annotation.
47+
return [1 => 1];
4848

4949
}//end getWarningList()
5050

src/Standards/Generic/Tests/PHP/DisallowAlternativePHPTagsUnitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ public function getErrorList($testFile='')
5656
public function getWarningList($testFile='')
5757
{
5858
if ($testFile === 'DisallowAlternativePHPTagsUnitTest.2.inc') {
59+
// Check if the Internal.NoCodeFound error can be expected on line 1.
60+
$option = (bool) ini_get('short_open_tag');
61+
$line1 = 1;
62+
if ($option === true) {
63+
$line1 = 0;
64+
}
65+
5966
return [
67+
1 => $line1,
6068
2 => 1,
6169
3 => 1,
6270
4 => 1,

src/Standards/Generic/Tests/PHP/DisallowShortOpenTagUnitTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ public function getWarningList($testFile='')
8888
case 'DisallowShortOpenTagUnitTest.1.inc':
8989
return [];
9090
case 'DisallowShortOpenTagUnitTest.3.inc':
91+
// Check if the Internal.NoCodeFound error can be expected on line 1.
92+
$option = (bool) ini_get('short_open_tag');
93+
$line1 = 1;
94+
if ($option === true) {
95+
$line1 = 0;
96+
}
9197
return [
98+
1 => $line1,
9299
3 => 1,
93100
6 => 1,
94101
11 => 1,

0 commit comments

Comments
 (0)