Skip to content

Commit 55ca388

Browse files
committed
Add formatting support for optional liquidDoc params
---- - Preserve `[]` delimiters - Strips whitespace between delimiter and param name
1 parent d5e8ec9 commit 55ca388

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

.changeset/olive-cougars-float.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/prettier-plugin-liquid': minor
3+
---
4+
5+
Add formatting support for optional liquidDoc parameters (e.g. `@param [optional-parameter] - paramDescription`).
6+
Whitespace is now stripped around the parameter name and the optional delimiters.

packages/prettier-plugin-liquid/src/printer/print/liquid.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,10 @@ export function printLiquidDocParam(
520520
parts.push(' ', `{${node.paramType.value}}`);
521521
}
522522

523-
if (node.paramName.value) {
523+
if (node.required) {
524524
parts.push(' ', node.paramName.value);
525+
} else {
526+
parts.push(' ', `[${node.paramName.value}]`);
525527
}
526528

527529
if (node.paramDescription?.value) {

packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ It should format the param description with a dash separator
1919
{% enddoc %}
2020

2121
It should respect the liquidDocParamDash option liquidDocParamDash: false
22+
liquidDocParamDash: false
2223
{% doc %}
2324
@param paramName param with description
2425
{% enddoc %}
@@ -28,6 +29,19 @@ It should normalize the param description
2829
@param paramName - param with description
2930
{% enddoc %}
3031

32+
It should strip whitespace between optional param delimiters
33+
{% doc %}
34+
@param [paramName] - param with description
35+
{% enddoc %}
36+
37+
It should not break params with malformed optional delimiters
38+
{% doc %}
39+
@param [missingTail - param with description
40+
@param missingHead - ] - param with description
41+
@param [too many words no desc]
42+
@param [too many words] - param with description
43+
{% enddoc %}
44+
3145
It should push example content to the next line
3246
{% doc %}
3347
@example

packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid

+17-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@ It should respect the liquidDocParamDash option liquidDocParamDash: false
2525

2626
It should normalize the param description
2727
{% doc %}
28-
@param paramName - param with description
28+
@param paramName - param with description
29+
{% enddoc %}
30+
31+
It should strip whitespace between optional param delimiters
32+
{% doc %}
33+
@param [ paramName ] - param with description
34+
{% enddoc %}
35+
36+
It should handle params with malformed optional delimiters
37+
{% doc %}
38+
@param [missingTail - param with description
39+
@param missingHead - ] - param with description
40+
@param [too many words no desc]
41+
@param [too many words] - param with description
2942
{% enddoc %}
3043

3144
It should push example content to the next line
@@ -65,8 +78,8 @@ It should remove empty lines at the end of the content
6578

6679
It should respect example content with param and description
6780
{% doc %}
68-
@param paramName - param with description
69-
@example
81+
@param paramName - param with description
82+
@example
7083
71-
This is a valid example
84+
This is a valid example
7285
{% enddoc %}

0 commit comments

Comments
 (0)