Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/prettier-plugin-liquid/src/printer/print/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,10 @@ function printNamedLiquidBlockStart(
return tag(trailingWhitespace);
}

case NamedTags.function: {
const markup = node.markup;
const trailingWhitespace = markup.args.length > 0 ? line : ' ';
return tag(trailingWhitespace);
}
case NamedTags.function:
case NamedTags.graphql: {
const markup = node.markup;
const trailingWhitespace = markup.args.length > 0 ? line : ' ';
const trailingWhitespace = markup.args.length > 0 || markup.filters.length > 0 ? line : ' ';
return tag(trailingWhitespace);
}

Expand Down
13 changes: 13 additions & 0 deletions packages/prettier-plugin-liquid/src/printer/printer-liquid-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ function printNode(
),
);
}
if (node.filters.length > 0) appendFilters(doc as Doc[], path, print);
return doc;
}

Expand All @@ -455,6 +456,7 @@ function printNode(
),
);
}
if (node.filters.length > 0) appendFilters(doc as Doc[], path, print);
return doc;
}

Expand All @@ -470,6 +472,7 @@ function printNode(
),
);
}
if (node.filters.length > 0) appendFilters(doc as Doc[], path, print);
return doc;
}

Expand Down Expand Up @@ -838,6 +841,16 @@ export const printerLiquidHtml3: Printer3<LiquidHtmlNode> & {
},
};

function appendFilters(doc: Doc[], path: LiquidAstPath, print: (path: LiquidAstPath) => Doc) {
doc.push(
line,
join(
line,
path.map((p) => print(p as LiquidAstPath), 'filters'),
),
);
}

function hasOrIsNode<N extends LiquidHtmlNode, K extends keyof N>(node: N, key: K) {
const v = node[key];
// this works because there's no ()[] type that is string | Node, it only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ It should format dot-access result variable

It should format variable partial
{% function res = partial_name %}

It should preserve filters on function tag result (file-based)
{% function res = 'modules/core/api_calls/send',
data: object,
template: 'modules/openai/responses'
| dig: 'results'
%}

It should preserve filters on function tag with no args
{% function res = 'modules/core/api_calls/send' | dig: 'results' %}

It should break on long lines with filters
printWidth: 1
{% function res = 'modules/core/api_calls/send',
data: object
| dig: 'results'
%}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ It should format dot-access result variable

It should format variable partial
{% function res = partial_name %}

It should preserve filters on function tag result (file-based)
{% function res = 'modules/core/api_calls/send', data: object, template: 'modules/openai/responses' | dig: 'results' %}

It should preserve filters on function tag with no args
{% function res = 'modules/core/api_calls/send' | dig: 'results' %}

It should break on long lines with filters
printWidth: 1
{% function res = 'modules/core/api_calls/send', data: object | dig: 'results' %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
It should format a basic graphql tag
{% graphql response = 'modules/core/api_calls/send' %}

It should format graphql tag with named args
{% graphql response = 'modules/core/api_calls/send', data: object %}

It should preserve filters on graphql tag result (file-based)
{% graphql response = 'modules/core/api_calls/send',
data: object,
template: 'modules/openai/responses'
| dig: 'api_call'
%}

It should preserve filters on graphql tag with no args
{% graphql response = 'modules/core/api_calls/send' | dig: 'api_call' %}

It should break on long lines with filters
printWidth: 1
{% graphql response = 'modules/core/api_calls/send',
data: object
| dig: 'api_call'
%}

It should format inline graphql tag with filter
{% graphql response | dig: 'results' %}query { test }{% endgraphql %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
It should format a basic graphql tag
{% graphql response = 'modules/core/api_calls/send' %}

It should format graphql tag with named args
{% graphql response = 'modules/core/api_calls/send', data: object %}

It should preserve filters on graphql tag result (file-based)
{% graphql response = 'modules/core/api_calls/send', data: object, template: 'modules/openai/responses' | dig: 'api_call' %}

It should preserve filters on graphql tag with no args
{% graphql response = 'modules/core/api_calls/send' | dig: 'api_call' %}

It should break on long lines with filters
printWidth: 1
{% graphql response = 'modules/core/api_calls/send', data: object | dig: 'api_call' %}

It should format inline graphql tag with filter
{% graphql response | dig: 'results' %}query { test }{% endgraphql %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test } from 'vitest';
import { assertFormattedEqualsFixed } from '../test-helpers';

test('Unit: liquid-tag-graphql', async () => {
await assertFormattedEqualsFixed(__dirname);
});