Skip to content

Commit 51fe764

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

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
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

+21-7
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,36 @@ It should trim whitespace between nodes
1010

1111
It should normalize the param type
1212
{% doc %}
13-
@param { string } paramName - param with description
13+
@param {string} paramName - param with description
1414
{% enddoc %}
1515

1616
It should format the param description with a dash separator
1717
{% doc %}
18-
@param paramName - param with description
18+
@param paramName - param with description
1919
{% enddoc %}
2020

2121
It should respect the liquidDocParamDash option liquidDocParamDash: false
22+
liquidDocParamDash: false
2223
{% doc %}
23-
@param paramName param with description
24+
@param paramName - param with description
2425
{% enddoc %}
2526

2627
It should normalize the param description
2728
{% doc %}
28-
@param paramName - param with description
29+
@param paramName - param with description
30+
{% enddoc %}
31+
32+
It should strip whitespace between optional param delimiters
33+
{% doc %}
34+
@param [ paramName ] - param with description
35+
{% enddoc %}
36+
37+
It should handle 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
2943
{% enddoc %}
3044

3145
It should push example content to the next line
@@ -65,8 +79,8 @@ It should remove empty lines at the end of the content
6579

6680
It should respect example content with param and description
6781
{% doc %}
68-
@param paramName - param with description
69-
@example
82+
@param paramName - param with description
83+
@example
7084
71-
This is a valid example
85+
This is a valid example
7286
{% enddoc %}

0 commit comments

Comments
 (0)