Skip to content

Commit 66b6567

Browse files
donatjstaabm
andauthored
Adds a flag to allow showing the source of the message (#70)
* Adds a flag to allow showing the source of the message * Tests --prepend-source flag * Update composer.json Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
1 parent 643cbf9 commit 66b6567

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

cs2pr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $version = '1.5.1-dev';
2222
$colorize = false;
2323
$gracefulWarnings = false;
2424
$noticeAsWarning = false;
25+
$prependSource = false;
2526

2627
// parameters
2728
$params = array();
@@ -35,6 +36,9 @@ foreach ($argv as $arg) {
3536
case 'colorize':
3637
$colorize = true;
3738
break;
39+
case 'prepend-source':
40+
$prependSource = true;
41+
break;
3842
case 'notices-as-warnings':
3943
$noticeAsWarning = true;
4044
break;
@@ -60,6 +64,7 @@ if (count($params) === 1) {
6064
echo " --graceful-warnings Don't exit with error codes if there are only warnings.\n";
6165
echo " --colorize Colorize the output (still compatible with Github Annotations)\n";
6266
echo " --notices-as-warnings Convert notices to warnings (Github does not annotate notices otherwise).\n";
67+
echo " --prepend-source Prepend error 'source' attribute to the message.\n";
6368
exit(9);
6469
}
6570

@@ -91,6 +96,11 @@ foreach ($root as $file) {
9196
$type = (string) $error['severity'];
9297
$line = (string) $error['line'];
9398
$message = (string) $error['message'];
99+
$source = isset($error['source']) ? (string) $error['source'] : null;
100+
101+
if ($prependSource && $source) {
102+
$message = $source.': '.$message;
103+
}
94104

95105
$annotateType = annotateType($type, $noticeAsWarning);
96106
annotateCheck($annotateType, relativePath($filename), $line, $message, $colorize);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
::error file=test/phpunit/Traits/BuildingPermissionIdAwareTraitTest.php,line=13::PhanUndeclaredMethod: Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::getPermissionIds
2+
::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=12::PhanUndeclaredClassReference: Reference to undeclared class \CIDRmatch\CIDRmatch
3+
::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=21::PhanTypeMismatchArgument: Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20
4+
::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=28::PhanUndeclaredClassReference: Reference to undeclared class \CIDRmatch\CIDRmatch
5+
::warning file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=38::PhanTypeMismatchArgument: Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20
6+
::error file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=54::Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny
7+
::error file=test/phpunit/Utils/Cidr/MultiCidrMatchTest.php,line=69::Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="ISO-8859-15"?>
2+
<checkstyle version="6.5">
3+
<file name="test/phpunit/Traits/BuildingPermissionIdAwareTraitTest.php">
4+
<error line="13" severity="error" message="Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::getPermissionIds" source="PhanUndeclaredMethod"/>
5+
</file>
6+
<file name="test/phpunit/Utils/Cidr/MultiCidrMatchTest.php">
7+
<error line="12" severity="warning" message="Reference to undeclared class \CIDRmatch\CIDRmatch" source="PhanUndeclaredClassReference"/>
8+
<error line="21" severity="warning" message="Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20" source="PhanTypeMismatchArgument"/>
9+
<error line="28" severity="warning" message="Reference to undeclared class \CIDRmatch\CIDRmatch" source="PhanUndeclaredClassReference"/>
10+
<error line="38" severity="warning" message="Argument 2 ($CIDRmatch) is $cidr of type \PHPUnit\Framework\MockObject\MockObject|\PHPUnit_Framework_MockObject_MockObject but \Utils\Cidr\MultiCidrMatch::__construct() takes \CIDRmatch\CIDRmatch defined at application/classes/Utils/Cidr/MultiCidrMatch.php:20" source="PhanTypeMismatchArgument"/>
11+
<error line="54" severity="error" message="Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny"/>
12+
<error line="69" severity="error" message="Call to undeclared method \PHPUnit\Framework\MockObject\MockObject::matchAny"/>
13+
</file>
14+
</checkstyle>

tests/tests.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function testXml($xmlPath, $expectedExit, $expectedOutput = null, $options = '')
5252
testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices.expect'));
5353
testXml(__DIR__.'/errors/notices.xml', 1, file_get_contents(__DIR__.'/errors/notices-as-warnings.expect'), '--notices-as-warnings');
5454

55+
testXml(__DIR__.'/errors/mixed-source-attributes.xml', 1, file_get_contents(__DIR__.'/errors/mixed-source-attributes.expect'), '--prepend-source');
56+
5557
testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/mixed-colors.expect'), '--colorize');
5658

5759
testXml(__DIR__.'/noerrors/only-header.xml', 0, file_get_contents(__DIR__.'/noerrors/only-header.expect'));

0 commit comments

Comments
 (0)