From 60f93b862bcf3716fb58db97f23697509291bcd5 Mon Sep 17 00:00:00 2001 From: James Meng Date: Tue, 10 Dec 2024 16:24:50 -0800 Subject: [PATCH] Prettier: Support Param Type Formatting --- .../src/printer/print/liquid.ts | 21 +++++++++++++------ .../src/test/liquid-doc/fixed.liquid | 5 +++++ .../src/test/liquid-doc/index.liquid | 5 +++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/prettier-plugin-liquid/src/printer/print/liquid.ts b/packages/prettier-plugin-liquid/src/printer/print/liquid.ts index 782d45cf..54fae7cc 100644 --- a/packages/prettier-plugin-liquid/src/printer/print/liquid.ts +++ b/packages/prettier-plugin-liquid/src/printer/print/liquid.ts @@ -513,12 +513,21 @@ export function printLiquidDocParam( _args: LiquidPrinterArgs, ): Doc { const node = path.getValue(); - return [ - node.name, - ' ', - node.paramName.value, - node.paramDescription.value ? ' ' + node.paramDescription.value : '', - ]; + const parts: Doc[] = ['@param']; + + if (node.paramType.value) { + parts.push(' ', `{${node.paramType.value}}`); + } + + if (node.paramName.value) { + parts.push(' ', node.paramName.value); + } + + if (node.paramDescription.value) { + parts.push(' ', node.paramDescription.value); + } + + return parts; } function innerLeadingWhitespace(node: LiquidTag | LiquidBranch) { diff --git a/packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid b/packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid index 1eda1569..04662ec8 100644 --- a/packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid +++ b/packages/prettier-plugin-liquid/src/test/liquid-doc/fixed.liquid @@ -12,3 +12,8 @@ It should trim whitespace between nodes {% doc %} @param paramName param with description {% enddoc %} + +It should format the param type +{% doc %} + @param {string} paramName param with description +{% enddoc %} diff --git a/packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid b/packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid index 66f7de6f..aaff7073 100644 --- a/packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid +++ b/packages/prettier-plugin-liquid/src/test/liquid-doc/index.liquid @@ -12,3 +12,8 @@ It should trim whitespace between nodes {% doc %} @param paramName param with description {% enddoc %} + +It should format the param type +{% doc %} + @param { string } paramName param with description +{% enddoc %}