Skip to content

Commit

Permalink
Merge pull request #684 from hazendaz/main
Browse files Browse the repository at this point in the history
[css] Add empty new line at end of file
  • Loading branch information
hazendaz committed Feb 2, 2023
2 parents 1e96597 + 3e9843d commit d5d91dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/revelc/code/formatter/css/CssFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ protected String doFormat(final String code, final LineEnding ending) throws IOE
// Patch converted 'tab' back to '\9' for IE 7,8, and 9 hack. Cssparser switches it to 'tab'.
formattedCode = formattedCode.replace("\t;", "\\9;");

// Adding new line at end of file when needed
String[] lines = formattedCode.split(ending.getChars());
if (!lines[lines.length - 1].equals(ending.getChars())) {
formattedCode = formattedCode + ending.getChars();
}

if (code.equals(formattedCode)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class CssFormatterTest extends AbstractFormatterTest {
void testDoFormatFile() throws Exception {
// FIXME Handle linux vs windows since this formatter does not accept line endings
final var expectedHash = LineEnding.LF.isSystem()
? "1af0032669532658f137ff80186df756abcfbccbe84e9663b54ef70be2c641f5af9e8c16ceeb3da7df9dc02599a3da0c0139a9397f93e383d6e8c6c50fd65c53"
: "684255d79eb28c6f4cfa340b6930fe1cfd9de16a1c6abf5f54e8f6837694b599101ef247ed00b8aea5460aa64cda60b418cebefd8ea28d5e747ed9cf4c3a9274";
? "6434062bd7499e707dea1ea17d301556712222b7671fae79ec20d906cda467a2b2210896a196dbaa9da7d221f04cab87a6b2e5538ca3c46fa7fdbedb46010a8c"
: "488b10041890a552141edb844a7d98f04ec2f30291a774dcb7f5fedcaad87dac85d3d9ed43b02f4d8d266e96549acd234038cff6e16b32a57034609f16330c8b";
final var lineEnding = LineEnding.LF.isSystem() ? LineEnding.LF : LineEnding.CRLF;
this.twoPassTest(Collections.emptyMap(), new CssFormatter(), "someFile.css", expectedHash, lineEnding);
}
Expand Down

0 comments on commit d5d91dd

Please sign in to comment.