Skip to content

Commit 0263134

Browse files
VasekPurchartondrejmirtes
authored andcommitted
Generate only 1, not 2 newlines at the end of baseline
1 parent 326496c commit 0263134

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,3 @@ parameters:
419419
"""
420420
count: 1
421421
path: tests/PHPStan/Rules/Arrays/AppendedArrayKeyTypeRuleTest.php
422-

src/Command/ErrorFormatter/BaselineNeonErrorFormatter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Command\AnalysisResult;
88
use PHPStan\Command\Output;
99
use PHPStan\File\RelativePathHelper;
10+
use PHPStan\ShouldNotHappenException;
1011
use function ksort;
1112
use function preg_quote;
1213
use function substr;
@@ -70,11 +71,17 @@ public function formatErrors(
7071
*/
7172
private function getNeon(array $ignoreErrors): string
7273
{
73-
return Neon::encode([
74+
$neon = Neon::encode([
7475
'parameters' => [
7576
'ignoreErrors' => $ignoreErrors,
7677
],
7778
], Neon::BLOCK);
79+
80+
if (substr($neon, -2) !== "\n\n") {
81+
throw new ShouldNotHappenException();
82+
}
83+
84+
return substr($neon, 0, -1);
7885
}
7986

8087
}

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ public function testEndOfFileNewlines(array $errors): void
350350
throw new ShouldNotHappenException();
351351
}
352352

353-
Assert::assertSame("\n\n", substr($content, -2));
354-
Assert::assertNotSame("\n", substr($content, -3, 1));
353+
Assert::assertSame("\n", substr($content, -1));
354+
Assert::assertNotSame("\n", substr($content, -2, 1));
355355
}
356356

357357
}

0 commit comments

Comments
 (0)