Skip to content

Commit 5c41b85

Browse files
authored
Use first line as default when no line is set (#120)
1 parent a606cb0 commit 5c41b85

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

cs2pr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ foreach ($root as $file) {
105105

106106
foreach ($file as $error) {
107107
$type = (string) $error['severity'];
108-
$line = (string) $error['line'];
108+
$line = (string) (isset($error['line']) ? $error['line'] : 1);
109109
$message = (string) $error['message'];
110110
$source = isset($error['source']) ? (string) $error['source'] : null;
111111

tests/errors/without-line.expect

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
::warning file=someFile.php,line=1::Found violation(s) of type: some_fixer_name_here_1
2+
::warning file=someFile.php,line=1::Found violation(s) of type: some_fixer_name_here_2
3+
::warning file=anotherFile.php,line=1::Found violation(s) of type: another_fixer_name_here

tests/errors/without-line.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<checkstyle>
3+
<file name="someFile.php">
4+
<error severity="warning" source="PHP-CS-Fixer.some_fixer_name_here_1" message="Found violation(s) of type: some_fixer_name_here_1" />
5+
<error severity="warning" source="PHP-CS-Fixer.some_fixer_name_here_2" message="Found violation(s) of type: some_fixer_name_here_2" />
6+
</file>
7+
<file name="anotherFile.php">
8+
<error severity="warning" source="PHP-CS-Fixer.another_fixer_name_here" message="Found violation(s) of type: another_fixer_name_here" />
9+
</file>
10+
</checkstyle>

tests/tests.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ function testXml($xmlPath, $expectedExit, $expectedOutput = null, $options = '')
6363
testXml(__DIR__.'/errors/mixed-case.xml', 1, file_get_contents(__DIR__.'/errors/mixed-case.expect'));
6464

6565
testXml(__DIR__.'/errors/mixed.xml', 1, file_get_contents(__DIR__.'/errors/errors-as-warnings.expect'), '--errors-as-warnings');
66+
67+
testXml(__DIR__.'/errors/without-line.xml', 1, file_get_contents(__DIR__.'/errors/without-line.expect'));

0 commit comments

Comments
 (0)