Skip to content

Commit d5d91dd

Browse files
authored
Merge pull request #684 from hazendaz/main
[css] Add empty new line at end of file
2 parents 1e96597 + 3e9843d commit d5d91dd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/main/java/net/revelc/code/formatter/css/CssFormatter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ protected String doFormat(final String code, final LineEnding ending) throws IOE
6060
// Patch converted 'tab' back to '\9' for IE 7,8, and 9 hack. Cssparser switches it to 'tab'.
6161
formattedCode = formattedCode.replace("\t;", "\\9;");
6262

63+
// Adding new line at end of file when needed
64+
String[] lines = formattedCode.split(ending.getChars());
65+
if (!lines[lines.length - 1].equals(ending.getChars())) {
66+
formattedCode = formattedCode + ending.getChars();
67+
}
68+
6369
if (code.equals(formattedCode)) {
6470
return null;
6571
}

src/test/java/net/revelc/code/formatter/css/CssFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class CssFormatterTest extends AbstractFormatterTest {
3636
void testDoFormatFile() throws Exception {
3737
// FIXME Handle linux vs windows since this formatter does not accept line endings
3838
final var expectedHash = LineEnding.LF.isSystem()
39-
? "1af0032669532658f137ff80186df756abcfbccbe84e9663b54ef70be2c641f5af9e8c16ceeb3da7df9dc02599a3da0c0139a9397f93e383d6e8c6c50fd65c53"
40-
: "684255d79eb28c6f4cfa340b6930fe1cfd9de16a1c6abf5f54e8f6837694b599101ef247ed00b8aea5460aa64cda60b418cebefd8ea28d5e747ed9cf4c3a9274";
39+
? "6434062bd7499e707dea1ea17d301556712222b7671fae79ec20d906cda467a2b2210896a196dbaa9da7d221f04cab87a6b2e5538ca3c46fa7fdbedb46010a8c"
40+
: "488b10041890a552141edb844a7d98f04ec2f30291a774dcb7f5fedcaad87dac85d3d9ed43b02f4d8d266e96549acd234038cff6e16b32a57034609f16330c8b";
4141
final var lineEnding = LineEnding.LF.isSystem() ? LineEnding.LF : LineEnding.CRLF;
4242
this.twoPassTest(Collections.emptyMap(), new CssFormatter(), "someFile.css", expectedHash, lineEnding);
4343
}

0 commit comments

Comments
 (0)