Skip to content

Commit fecc208

Browse files
ondrejmirtesphpstan-bot
authored andcommitted
Setting reportIgnoresWithoutComments: true will disallow @phpstan-ignore-line and @phpstan-ignore-next-line
1 parent 2b5da02 commit fecc208

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

.github/workflows/e2e-tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,13 @@ jobs:
303303
cd e2e/report-ignores-without-comments
304304
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan --error-format=raw")
305305
echo "$OUTPUT"
306-
../bashunit -a contains 'test.php:4:Ignore with identifier variable.undefined has no comment' "$OUTPUT"
306+
../bashunit -a contains 'test.php:4:Ignore with identifier variable.undefined has no comment.' "$OUTPUT"
307+
../bashunit -a contains 'test.php:4:Variable $undefined might not be defined.' "$OUTPUT"
307308
../bashunit -a not_contains 'test.php:7' "$OUTPUT"
309+
../bashunit -a contains 'test.php:10:Ignoring all errors on a line is not allowed.' "$OUTPUT"
310+
../bashunit -a contains 'test.php:10:Variable $yetAnotherUndefined might not be defined.' "$OUTPUT"
311+
../bashunit -a contains 'test.php:12:Ignoring all errors on a line is not allowed.' "$OUTPUT"
312+
../bashunit -a contains 'test.php:12:Variable $yetYetAnotherUndefined might not be defined.' "$OUTPUT"
308313
309314
steps:
310315
- name: Harden the runner (Audit all outbound calls)

e2e/report-ignores-without-comments/test.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55

66
// @phpstan-ignore variable.undefined (this one has a comment so no error)
77
echo $anotherUndefined;
8+
9+
// @phpstan-ignore-next-line
10+
echo $yetAnotherUndefined;
11+
12+
echo $yetYetAnotherUndefined; // @phpstan-ignore-line

src/Analyser/FileAnalyser.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ public function analyseFile(
135135
foreach ($linesToIgnore as $ignoredFile => $lines) {
136136
foreach ($lines as $line => $identifiers) {
137137
if ($identifiers === null) {
138+
$fileErrors[] = (new Error(
139+
'Ignoring all errors on a line is not allowed.',
140+
$ignoredFile,
141+
$line,
142+
false,
143+
$ignoredFile,
144+
null,
145+
'Use @phpstan-ignore with an identifier and a comment (in parentheses).',
146+
))->withIdentifier('ignore.allLineErrors');
147+
unset($linesToIgnore[$ignoredFile][$line]);
148+
unset($unmatchedLineIgnores[$ignoredFile][$line]);
138149
continue;
139150
}
140151

@@ -152,6 +163,8 @@ public function analyseFile(
152163
null,
153164
'Explain why this ignore is necessary in parentheses after the identifier.',
154165
))->withIdentifier('ignore.noComment');
166+
unset($linesToIgnore[$ignoredFile][$line]);
167+
unset($unmatchedLineIgnores[$ignoredFile][$line]);
155168
}
156169
}
157170
}

0 commit comments

Comments
 (0)