Skip to content

Commit de13e20

Browse files
committed
Prettier supoprt for paramDescription and paramName
1 parent 63c194c commit de13e20

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

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

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { NodeTypes, NamedTags, isBranchedTag, RawMarkup } from '@shopify/liquid-html-parser';
1+
import {
2+
NodeTypes,
3+
NamedTags,
4+
isBranchedTag,
5+
RawMarkup,
6+
LiquidDocParamNode,
7+
} from '@shopify/liquid-html-parser';
28
import { Doc, doc } from 'prettier';
39

410
import {
@@ -497,7 +503,22 @@ export function printLiquidDoc(
497503
_args: LiquidPrinterArgs,
498504
) {
499505
const body = path.map((p: any) => print(p), 'nodes');
500-
return [indent([hardline, body]), hardline];
506+
return [indent([hardline, join(hardline, body)]), hardline];
507+
}
508+
509+
export function printLiquidDocParam(
510+
path: AstPath<LiquidDocParamNode>,
511+
_options: LiquidParserOptions,
512+
_print: LiquidPrinter,
513+
_args: LiquidPrinterArgs,
514+
): Doc {
515+
const node = path.getValue();
516+
return [
517+
node.name,
518+
' ',
519+
node.paramName.value,
520+
node.paramDescription.value ? ' ' + node.paramDescription.value : '',
521+
];
501522
}
502523

503524
function innerLeadingWhitespace(node: LiquidTag | LiquidBranch) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
printLiquidRawTag,
4747
printLiquidTag,
4848
printLiquidVariableOutput,
49+
printLiquidDocParam,
4950
} from './print/liquid';
5051
import { printClosingTagSuffix, printOpeningTagPrefix } from './print/tag';
5152
import { bodyLines, hasLineBreakInRange, isEmpty, isTextLikeNode, reindent } from './utils';
@@ -555,7 +556,7 @@ function printNode(
555556
}
556557

557558
case NodeTypes.LiquidDocParamNode: {
558-
return [node.name, ' ', node.paramName, ' ', node.paramDescription];
559+
return printLiquidDocParam(path as AstPath<LiquidDocParamNode>, options, print, args);
559560
}
560561

561562
default: {

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

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ It should not dedent to root
77
{% doc %}
88
@param paramName param with description
99
{% enddoc %}
10+
11+
It should trim whitespace between nodes
12+
{% doc %}
13+
@param paramName param with description
14+
{% enddoc %}

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

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ It should not dedent to root
77
{% doc %}
88
@param paramName param with description
99
{% enddoc %}
10+
11+
It should trim whitespace between nodes
12+
{% doc %}
13+
@param paramName param with description
14+
{% enddoc %}

0 commit comments

Comments
 (0)