Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Fix trailing whitespace after opening raw tag breaking formatting
Browse files Browse the repository at this point in the history
Turns out our "only want the meat" logic was slightly off and made it so
we printed "" when there was whitespace before the newline character.

Ugh.

Fixes #144
  • Loading branch information
charlespwd committed Dec 13, 2022
1 parent 1af0619 commit 13ca899
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/printer/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const trimEnd = (x: string) => x.trimEnd();

export function bodyLines(str: string): string[] {
return str
.replace(/^\n*|\s*$/g, '') // only want the meat
.replace(/^(?: |\t)*\n*|\s*$/g, '') // only want the meat
.split(/\r?\n/);
}

Expand Down
5 changes: 5 additions & 0 deletions test/issue-144/fixed.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
it should format as expected when there's whitespace after the opening comment
{% comment %}
This is a comment
{% endcomment %}
<p>hello, world!</p>
5 changes: 5 additions & 0 deletions test/issue-144/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
debug it should format as expected when there's whitespace after the opening comment
{% comment %}
This is a comment
{% endcomment %}
<p>hello, world!</p>
6 changes: 6 additions & 0 deletions test/issue-144/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { assertFormattedEqualsFixed } from '../test-helpers';
import * as path from 'path';

describe(`Unit: ${path.basename(__dirname)}`, () => {
assertFormattedEqualsFixed(__dirname);
});

0 comments on commit 13ca899

Please sign in to comment.