Skip to content

Commit 434d72b

Browse files
committed
Report fixable errors in JSON error format
Amp-Thread-ID: https://ampcode.com/threads/T-01a198ef-d81e-7532-81f4-438bae7a4db3
1 parent f6a1605 commit 434d72b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/Command/ErrorFormatter/JsonErrorFormatter.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
5454
$message['identifier'] = $fileSpecificError->getIdentifier();
5555
}
5656

57+
if ($fileSpecificError->isFixable()) {
58+
$message['fixable'] = true;
59+
}
60+
5761
$errorsArray['files']->$file['messages'][] = $message;
5862
}
5963

‎tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Nette\Utils\Json;
66
use PHPStan\Analyser\Error;
7+
use PHPStan\Analyser\FixedErrorDiff;
78
use PHPStan\Command\AnalysisResult;
89
use PHPStan\Testing\ErrorFormatterTestCase;
910
use PHPUnit\Framework\Attributes\DataProvider;
@@ -252,4 +253,17 @@ public function testFormatTip(string $tip, string $expectedTip): void
252253
$this->assertSame($expectedTip, $json['files']['/foo/bar.php']['messages'][0]['tip']);
253254
}
254255

256+
public function testFormatFixable(): void
257+
{
258+
$formatter = new JsonErrorFormatter(false);
259+
$formatter->formatErrors(new AnalysisResult([
260+
new Error('Fixable', '/foo/bar.php', 1, fixedErrorDiffs: [new FixedErrorDiff('/foo/bar.php', 'hash', 'diff')]),
261+
new Error('Not fixable', '/foo/bar.php', 2),
262+
], [], [], [], [], false, null, true, 0, false, []), $this->getOutput());
263+
264+
$json = Json::decode($this->getOutputContent(), Json::FORCE_ARRAY);
265+
$this->assertTrue($json['files']['/foo/bar.php']['messages'][0]['fixable']);
266+
$this->assertArrayNotHasKey('fixable', $json['files']['/foo/bar.php']['messages'][1]);
267+
}
268+
255269
}

0 commit comments

Comments
 (0)