Skip to content

Commit

Permalink
TableErrorFormatter - always output identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 30, 2024
1 parent 84a3354 commit fc66c24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
28 changes: 1 addition & 27 deletions src/Command/ErrorFormatter/TableErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
use PHPStan\File\RelativePathHelper;
use PHPStan\File\SimpleRelativePathHelper;
use Symfony\Component\Console\Formatter\OutputFormatter;
use function array_key_exists;
use function array_map;
use function count;
use function explode;
use function getenv;
use function in_array;
use function is_string;
use function ltrim;
use function sprintf;
Expand Down Expand Up @@ -69,44 +67,20 @@ public function formatErrors(

/** @var array<string, Error[]> $fileErrors */
$fileErrors = [];
$outputIdentifiers = $output->isVerbose();
$outputIdentifiersInFile = [];
foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {
if (!isset($fileErrors[$fileSpecificError->getFile()])) {
$fileErrors[$fileSpecificError->getFile()] = [];
}

$fileErrors[$fileSpecificError->getFile()][] = $fileSpecificError;
if ($outputIdentifiers) {
continue;
}

$filePath = $fileSpecificError->getTraitFilePath() ?? $fileSpecificError->getFilePath();
if (array_key_exists($filePath, $outputIdentifiersInFile)) {
continue;
}

if ($fileSpecificError->getIdentifier() === null) {
continue;
}

if (!in_array($fileSpecificError->getIdentifier(), [
'ignore.unmatchedIdentifier',
'ignore.parseError',
'ignore.unmatched',
], true)) {
continue;
}

$outputIdentifiersInFile[$filePath] = true;
}

foreach ($fileErrors as $file => $errors) {
$rows = [];
foreach ($errors as $error) {
$message = $error->getMessage();
$filePath = $error->getTraitFilePath() ?? $error->getFilePath();
if (($outputIdentifiers || array_key_exists($filePath, $outputIdentifiersInFile)) && $error->getIdentifier() !== null && $error->canBeIgnored()) {
if ($error->getIdentifier() !== null && $error->canBeIgnored()) {
$message .= "\n";
$message .= '🪪 ' . $error->getIdentifier();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ public function dataFormatterOutputProvider(): iterable
'numGenericErrors' => 0,
'verbose' => false,
'extraEnvVars' => [],
'expected' => ' ------ ------------
'expected' => ' ------ ----------------
Line foo.php
------ ------------
------ ----------------
5 Foobar\Buz
🪪 foobar.buz
💡 a tip
------ ------------
------ ----------------
[ERROR] Found 1 error
Expand Down

0 comments on commit fc66c24

Please sign in to comment.