Skip to content

Commit 7038766

Browse files
committed
Add formatting support for optional liquidDoc params
----- Strips whitespace between optional param delimiters, and around the default value if it exists.
1 parent 463c120 commit 7038766

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

.changeset/olive-cougars-float.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/prettier-plugin-liquid': minor
3+
---
4+
5+
Add formatting support for optional liquidDoc params and default values. Whitespace is now stripped between the optional delimiter and the param name, and around the default value if it exists.

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,14 @@ 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+
if (node.defaultValue?.value) {
526+
parts.push(' ', `[${node.paramName.value}=${node.defaultValue.value}]`);
527+
} else {
528+
parts.push(' ', `[${node.paramName.value}]`);
529+
}
524530
}
525531

526532
if (node.paramDescription?.value) {

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

+20
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,23 @@ 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+
@param [paramName=defaultValue] - param with description
35+
@param [paramName=defaultValue] - param with description
36+
{% enddoc %}
37+
38+
39+
It should not break params with malformed optional delimiters
40+
{% doc %}
41+
@param [ missingTail - param with description
42+
@param missingHead ] - param with description
43+
@param [ too many words no type no desc]
44+
@param [too many words no type ] - param with description
45+
@param {String} [too many words no desc ]
46+
@param {String} [ too many words = default value] - description
47+
@param {String} [ too many words = default value no desc ]
48+
@param {String} [ too many words = default value no type ]
49+
{% enddoc %}

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

+19
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,22 @@ 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+
@param [ paramName = defaultValue] - param with description
35+
@param [paramName=defaultValue ] - param with description
36+
{% enddoc %}
37+
38+
It should handle params with malformed optional delimiters
39+
{% doc %}
40+
@param [ missingTail - param with description
41+
@param missingHead ] - param with description
42+
@param [ too many words no type no desc]
43+
@param [too many words no type ] - param with description
44+
@param {String} [too many words no desc ]
45+
@param {String} [ too many words = default value] - description
46+
@param {String} [ too many words = default value no desc ]
47+
@param {String} [ too many words = default value no type ]
48+
{% enddoc %}

0 commit comments

Comments
 (0)