Skip to content

Commit f388876

Browse files
authored
chore(phpcs): adds EndFileNewline to phpcs (#23)
https://pixelfederation.atlassian.net/browse/TS2-18528
1 parent 7edfeca commit f388876

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

phpcs.ruleset.83.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@
227227
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.BeforeCloseBrace">
228228
<severity>5</severity>
229229
</rule>
230+
<rule ref="Generic.Files.EndFileNewline">
231+
<severity>5</severity>
232+
</rule>
230233

231234
<rule ref="Zend.Files.ClosingTag"/>
232235

tests/Functional/PhpcsTestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@
55
namespace PixelFederation\CodingStandards\Tests\Functional;
66

77
use PHPUnit\Framework\TestCase;
8+
use RuntimeException;
89

910
abstract class PhpcsTestCase extends TestCase
1011
{
12+
public static function trimEndFileNewline(string $file): void
13+
{
14+
$file = __DIR__ . '/' . $file;
15+
$content = file_get_contents($file);
16+
if ($content === false) {
17+
throw new RuntimeException('Could not read file: ' . $file);
18+
}
19+
20+
$trimmedContent = rtrim($content, "\n");
21+
22+
file_put_contents($file, $trimmedContent);
23+
}
24+
1125
public static function assertPhpcbf(
1226
string $fileBefore,
1327
string $fileAfter,

tests/Functional/SuperfluousWhitespace/Bar.SuperfluousWhitespace.before.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ public function __construct(
3030
$this->superNumber = $total + $heightDoubled;
3131
}
3232

33-
}
33+
}

tests/Functional/SuperfluousWhitespaceTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ final class SuperfluousWhitespaceTest extends PhpcsTestCase
88
{
99
public function testPhpcbfFixesWhitespaceAsExpected(): void
1010
{
11-
self::assertPhpcbf(
12-
'SuperfluousWhitespace/Bar.SuperfluousWhitespace.before.php',
13-
'SuperfluousWhitespace/Bar.SuperfluousWhitespace.after.php',
14-
);
11+
$fileBefore = 'SuperfluousWhitespace/Bar.SuperfluousWhitespace.before.php';
12+
$fileAfter = 'SuperfluousWhitespace/Bar.SuperfluousWhitespace.after.php';
13+
14+
// Ensure no trailing newlines interfere with the comparison
15+
self::trimEndFileNewline($fileBefore);
16+
17+
self::assertPhpcbf($fileBefore, $fileAfter);
1518
}
1619
}

0 commit comments

Comments
 (0)