Skip to content

Commit 085aabb

Browse files
committedFeb 18, 2025··
Add description support for prettier
This commit adds the descripton tag to prettier and helps with formatting.

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed
 

‎.changeset/swift-snails-check.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/prettier-plugin-liquid': patch
3+
---
4+
5+
Add prettier support for the `@description` tag

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

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
RawMarkup,
66
LiquidDocParamNode,
77
LiquidDocExampleNode,
8+
LiquidDocDescriptionNode,
89
} from '@shopify/liquid-html-parser';
910
import { Doc, doc } from 'prettier';
1011

@@ -559,6 +560,22 @@ export function printLiquidDocExample(
559560
return parts;
560561
}
561562

563+
export function printLiquidDocDescription(
564+
path: AstPath<LiquidDocDescriptionNode>,
565+
options: LiquidParserOptions,
566+
_print: LiquidPrinter,
567+
_args: LiquidPrinterArgs,
568+
): Doc {
569+
const node = path.getValue();
570+
const parts: Doc[] = ['@description'];
571+
572+
if (node.content?.value) {
573+
parts.push(' ', node.content.value.trim());
574+
}
575+
576+
return parts;
577+
}
578+
562579
function innerLeadingWhitespace(node: LiquidTag | LiquidBranch) {
563580
if (!node.firstChild) {
564581
if (node.isDanglingWhitespaceSensitive && node.hasDanglingWhitespace) {

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
getConditionalComment,
3+
LiquidDocDescriptionNode,
34
LiquidDocExampleNode,
45
LiquidDocParamNode,
56
NodeTypes,
@@ -49,6 +50,7 @@ import {
4950
printLiquidVariableOutput,
5051
printLiquidDocParam,
5152
printLiquidDocExample,
53+
printLiquidDocDescription,
5254
} from './print/liquid';
5355
import { printClosingTagSuffix, printOpeningTagPrefix } from './print/tag';
5456
import { bodyLines, hasLineBreakInRange, isEmpty, isTextLikeNode, reindent } from './utils';
@@ -566,7 +568,12 @@ function printNode(
566568
}
567569

568570
case NodeTypes.LiquidDocDescriptionNode: {
569-
return '';
571+
return printLiquidDocDescription(
572+
path as AstPath<LiquidDocDescriptionNode>,
573+
options,
574+
print,
575+
args,
576+
);
570577
}
571578

572579
default: {

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

+18
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,21 @@ It should allow multiple example nodes
8888
@example
8989
Second Example
9090
{% enddoc %}
91+
92+
It should move description content inline
93+
{% doc %}
94+
@description This is a description
95+
{% enddoc %}
96+
97+
It should add a space between a description tag and content
98+
{% doc %}
99+
@description This is a description
100+
{% enddoc %}
101+
102+
It should handle param, example, and description nodes
103+
{% doc %}
104+
@param {String} paramName - param with description
105+
@example
106+
This is a valid example
107+
@description This is a description
108+
{% enddoc %}

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

+20
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,23 @@ It should allow multiple example nodes
8787
@example
8888
Second Example
8989
{% enddoc %}
90+
91+
It should move description content inline
92+
{% doc %}
93+
@description
94+
This is a description
95+
{% enddoc %}
96+
97+
It should add a space between a description tag and content
98+
{% doc %}
99+
@descriptionThis is a description
100+
{% enddoc %}
101+
102+
It should handle param, example, and description nodes
103+
{% doc %}
104+
@param {String} paramName - param with description
105+
@example
106+
This is a valid example
107+
@description This is a description
108+
{% enddoc %}
109+

0 commit comments

Comments
 (0)
Please sign in to comment.