Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LiquidDoc] Formatting support for optional @param delimiters [] #734

Merged
merged 1 commit into from
Feb 6, 2025
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
6 changes: 6 additions & 0 deletions .changeset/olive-cougars-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/prettier-plugin-liquid': minor
---

Add formatting support for optional liquidDoc parameters (e.g. `@param [optional-parameter] - paramDescription`).
Whitespace is now stripped around the parameter name and the optional delimiters.
4 changes: 3 additions & 1 deletion packages/prettier-plugin-liquid/src/printer/print/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,10 @@ export function printLiquidDocParam(
parts.push(' ', `{${node.paramType.value}}`);
}

if (node.paramName.value) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always true, so I'm just removing this

if (node.required) {
parts.push(' ', node.paramName.value);
} else {
parts.push(' ', `[${node.paramName.value}]`);
}

if (node.paramDescription?.value) {
Expand Down
14 changes: 14 additions & 0 deletions packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ It should format the param description with a dash separator
{% enddoc %}

It should respect the liquidDocParamDash option liquidDocParamDash: false
liquidDocParamDash: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing a test - this got removed at some point

{% doc %}
@param paramName param with description
{% enddoc %}
Expand All @@ -28,6 +29,19 @@ It should normalize the param description
@param paramName - param with description
{% enddoc %}

It should strip whitespace between optional param delimiters
{% doc %}
@param [paramName] - param with description
{% enddoc %}

It should not break params with malformed optional delimiters
{% doc %}
@param [missingTail - param with description
@param missingHead - ] - param with description
@param [too many words no desc]
@param [too many words] - param with description
{% enddoc %}

It should push example content to the next line
{% doc %}
@example
Expand Down
13 changes: 13 additions & 0 deletions packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ It should normalize the param description
@param paramName - param with description
{% enddoc %}

It should strip whitespace between optional param delimiters
{% doc %}
@param [ paramName ] - param with description
{% enddoc %}

It should handle params with malformed optional delimiters
{% doc %}
@param [missingTail - param with description
@param missingHead - ] - param with description
@param [too many words no desc]
@param [too many words] - param with description
{% enddoc %}

It should push example content to the next line
{% doc %}
@example This is a valid example
Expand Down