Skip to content

Commit

Permalink
CheckstyleErrorFormatter - include error identifier in source attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 16, 2023
1 parent 1c8894d commit f66cf5b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Command/ErrorFormatter/CheckstyleErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public function formatErrors(

foreach ($errors as $error) {
$output->writeRaw(sprintf(
' <error line="%d" column="1" severity="error" message="%s" />',
' <error line="%d" column="1" severity="error" message="%s"%s />',
$this->escape((string) $error->getLine()),
$this->escape($error->getMessage()),
$error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '',
));
$output->writeLineFormatted('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,33 @@ public function testTraitPath(): void
</checkstyle>', $this->getOutputContent());
}

public function testIdentifier(): void
{
$formatter = new CheckstyleErrorFormatter(new SimpleRelativePathHelper(__DIR__));
$error = (new Error(
'Foo',
__DIR__ . '/FooTrait.php',
5,
true,
__DIR__ . '/Foo.php',
null,
))->withIdentifier('argument.type');
$formatter->formatErrors(new AnalysisResult(
[$error],
[],
[],
[],
[],
false,
null,
true,
0,
), $this->getOutput());
$this->assertXmlStringEqualsXmlString('<checkstyle>
<file name="Foo.php">
<error column="1" line="5" message="Foo" severity="error" source="argument.type" />
</file>
</checkstyle>', $this->getOutputContent());
}

}

0 comments on commit f66cf5b

Please sign in to comment.