Skip to content

Commit 3c791ea

Browse files
committed
Add formatting support for optional liquidDoc params
1 parent 374d89f commit 3c791ea

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

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

522-
if (node.paramName.value) {
522+
if (node.required) {
523523
parts.push(' ', node.paramName.value);
524+
} else {
525+
parts.push(' ', `[${node.paramName.value}]`);
524526
}
525527

526528
if (node.paramDescription?.value) {

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

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ It should normalize the param description
2727
{% doc %}
2828
@param paramName - param with description
2929
{% 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 not break 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
42+
{% enddoc %}

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

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ It should normalize the param description
2727
{% doc %}
2828
@param paramName - param with description
2929
{% 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
42+
{% enddoc %}

0 commit comments

Comments
 (0)