This repository was archived by the owner on Jun 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +82
-5
lines changed
Expand file tree Collapse file tree 5 files changed +82
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import {
2828 last ,
2929 first ,
3030 isPrettierIgnoreAttributeNode ,
31+ hasMoreThanOneNewLineBetweenNodes ,
3132} from '~/printer/utils' ;
3233
3334const {
@@ -271,10 +272,22 @@ function printAttributes(
271272
272273 const prettierIgnoreAttributes = isPrettierIgnoreAttributeNode ( node . prev ) ;
273274
274- const printedAttributes = path . map (
275- ( attr ) => print ( attr , { trailingSpaceGroupId : attrGroupId } ) ,
276- 'attributes' ,
277- ) ;
275+ const printedAttributes = path . map ( ( attr ) => {
276+ const attrNode = attr . getValue ( ) ;
277+ let extraNewline : Doc = '' ;
278+ if (
279+ attrNode . prev &&
280+ hasMoreThanOneNewLineBetweenNodes (
281+ attrNode . source ,
282+ attrNode . prev ,
283+ attrNode ,
284+ )
285+ ) {
286+ extraNewline = hardline ;
287+ }
288+ const printed = print ( attr , { trailingSpaceGroupId : attrGroupId } ) ;
289+ return [ extraNewline , printed ] ;
290+ } , 'attributes' ) ;
278291
279292 const forceBreakAttrContent = node . source
280293 . slice ( node . blockStartPosition . start , last ( node . attributes ) . position . end )
Original file line number Diff line number Diff line change 1- import { LiquidAstPath , LiquidHtmlNode , LiquidParserOptions } from '~/types' ;
1+ import {
2+ LiquidAstPath ,
3+ LiquidHtmlNode ,
4+ LiquidParserOptions ,
5+ Position ,
6+ } from '~/types' ;
27
38export function isWhitespace ( source : string , loc : number ) : boolean {
49 if ( loc < 0 || loc >= source . length ) return false ;
@@ -49,3 +54,14 @@ export function hasLineBreakInRange(
4954 const indexOfNewLine = source . indexOf ( '\n' , locStart ) ;
5055 return 0 <= indexOfNewLine && indexOfNewLine < locEnd ;
5156}
57+
58+ export function hasMoreThanOneNewLineBetweenNodes (
59+ source : string ,
60+ prev : { position : Position } | undefined ,
61+ next : { position : Position } | undefined ,
62+ ) : boolean {
63+ if ( ! prev || ! next ) return false ;
64+ const between = source . slice ( prev . position . end , next . position . start ) ;
65+ const count = between . match ( / \n / g) ?. length || 0 ;
66+ return count > 1 ;
67+ }
Original file line number Diff line number Diff line change 1+ It should maintain at most 1 newline between attributes, and none at the end
2+ <label class =" block relative" >
3+ <input
4+ class =" absolute inset-0 opacity-0 pointer-events-none peer"
5+ type =" radio"
6+ name =" id"
7+
8+ id =" variant-{{ variant .id }}"
9+ value =" {{ variant .id }}"
10+ required
11+
12+ {% unless variant.available %}
13+ disabled
14+ {% endunless %}
15+
16+ {% if product.selected_variant == variant %}
17+ checked
18+ {% endif %}
19+ >
20+ </label >
Original file line number Diff line number Diff line change 1+ It should maintain at most 1 newline between attributes, and none at the end
2+ <label class =" block relative" >
3+ <input
4+ class =" absolute inset-0 opacity-0 pointer-events-none peer"
5+ type =" radio"
6+ name =" id"
7+
8+
9+ id =" variant-{{ variant .id }}"
10+ value =" {{ variant .id }}"
11+ required
12+
13+ {% unless variant.available %}
14+ disabled
15+ {% endunless %}
16+
17+ {% if product.selected_variant == variant %}
18+ checked
19+ {% endif %}
20+
21+ >
22+ </label >
Original file line number Diff line number Diff line change 1+ import { assertFormattedEqualsFixed } from '../test-helpers' ;
2+ import * as path from 'path' ;
3+
4+ describe ( `Unit: ${ path . basename ( __dirname ) } ` , ( ) => {
5+ assertFormattedEqualsFixed ( __dirname ) ;
6+ } ) ;
You can’t perform that action at this time.
0 commit comments