[Bug] Additional newlines added during every format under prettier-ignore
LandGod opened this issue Β· comments
With the latest update I have found that in some cases running format document
causes a new line to be added in some places over and over again. It seems that this happens below blocks that have been ignored by prettier. I've recorded my screen to demonstrate:
Sorry for the poor quality. But, as you can see, every time I use the "format document" (with prettier selected as my formatter) it is adding an additional new line to that same spot. When I remove the preceding <!-- prettier-ignore -->
statement it stops doing it.
Interestingly, this doesn't happen with anywhere else in this document even though there are similar statements below this one, so there must be something special about that particular section.
Unfortunately this file is part of a private repo, so I can't share access, but here is the entire file for reference:
faqs.html
{{ "<!-- FAQs partial -->" | safeHTML }}
<section id="faq" class="bg-black section faqs responsive-image__bg-section">
{{ $currentProductKey := "" }}
{{ $ctx := . }}
{{ with (cond (eq hugo.Environment "devstore") .Params.devProductId .Params.productId) }}
{{ $currentProductKey = (partialCached "products/get-product-by-id" . . ).key }}
{{ else }}
{{ $ctx = .ctx }}
{{ $currentProductKey = .key }}
{{ end }}
{{ $key := $currentProductKey }}
<!-- prettier-ignore -->
{{ $allFaqsData := (partialCached "get-data" (dict
"ctx" $ctx
"dataFile" "faqs"
) "faqs" ) }}
{{ $faqsData := index $allFaqsData $key }}
{{ partial "site/faqs-structured-data" (dict "faqsdata" $faqsData ) }}
{{ partial "imgix" (dict
"type" "bg"
"image" "/pages/shared/faq-background.jpg"
"alt" ( i18n "faq_background_img_alt" )
"wrapperClass" "responsive-image__bg-wrapper-absolute"
)
}}
<div class="container responsive-image__bg-content">
<!-- prettier-ignore -->
{{ partialCached "page-sections/heading" (dict
"heading" (i18n "frequently_asked_questions")
"isBackgroundDark" true
) "faqs-heading" }}
{{ "<!-- accordion -->" | safeHTML }}
<div id="accordion mx-auto" class="rfs:px-5">
{{ range $faqsData }}
{{ "<!-- accordion item -->" | safeHTML }}
<div>
<button
class="accordion faqsplus focus:ring-0 focus-visible:ring-2 focus-visible:ring-blue-600 active:ring-0"
data-toggle="collapse"
data-target=".collapse{{ with .id }}
{{ (printf ".%v" .) }}
{{ else }}
{{ ( printf ".%v" .ID ) }}
{{ end }}"
data-text="Collapse"
>
{{ .title }}
</button>
<div
id="{{ with .id }}
{{ (printf "%v" .) }}
{{ else }}
{{ ( printf "%v" .ID ) }}
{{ end }}"
class="accordion-panel block collapse {{ with .id }}
{{ (printf "%v" .) }}
{{ else }}
{{ ( printf "%v" .ID ) }}
{{ end }} hidden"
data-parent="#accordion"
>
<div class="accordion-content block__content">
{{ .content | safeHTML }}
</div>
</div>
</div>
{{ end }}
</div>
</div>
<!-- prettier-ignore -->
{{- partialCached "cta-button" (dict
"key" false
"ctx" $ctx
) $ctx.Params.productId $ctx.Section -}}
</section>
{{ "<!-- /FAQs partial -->" | safeHTML }}
I hope this is enough context to be a helpful bug report, but if not I am happy to investigate further and/or provide more information.
EDIT: Found another example of this in action. In the following file new lines are continuously added after line 13: {{ $sources := index (findRE "<section class=\"footnotes\" role=\"doc-endnotes\">" .content) 0 }}
unless <!-- prettier-ignore -->
is removed.
footnote-format.html
{{ "<!-- footnote-format -->" | safeHTML }}
{{/* This partial is necessary because there is no way to edit footnotes html without modifying the content */}}
{{/* Although the title is footnote-format, we still need to grab the entire content block, including the footnotes, so we can replace them using regex */}}
{{/* This partial modifies content to include footnotes heading */}}
{{/* as well as to add aria attributes to the sources links */}}
<!-- prettier-ignore -->
{{/*****************************************************
Accepted arguments:
- content: (string) [REQUIRED] Content of the page inside of which the pattern will be found and replaced.
*****************************************************/}}
{{ $sources := index (findRE "<section class=\"footnotes\" role=\"doc-endnotes\">" .content) 0 }}
{{ with $sources }}
{{ $sourcesLabeled := print $sources (printf "<h2 class=\"not-sr-only\" id=\"sources-label\">%s</h2>" (i18n "sources_heading")) }}
{{ $noteref := "role=\"doc-noteref\"" }}
{{ $noterefLabeled := print $noteref " aria-describedby=\"sources-label\"" }}
{{ $backlink := "role=\"doc-backlink\"" }}
{{ $backlinkLabeled := print $backlink (printf " aria-label=\"%s\"" (i18n "backlink")) }}
{{ $.content | replaceRE $noteref $noterefLabeled | replaceRE $backlink $backlinkLabeled | replaceRE . $sourcesLabeled | safeHTML }}
{{ else }}
{{ .content | safeHTML }}
{{ end }}
{{ "<!-- /footnote-format -->" | safeHTML }}
Additional info:
My system info
"prettier": "^2.3.2",
"prettier-plugin-go-template": "^0.0.11",
"prettier-plugin-packagejson": "^2.2.11",
$ npm version
{
'jbc-marketing-site': '1.0.2',
npm: '7.10.0',
node: '16.0.0',
v8: '9.0.257.17-node.10',
uv: '1.41.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.17.1',
modules: '93',
nghttp2: '1.42.0',
napi: '8',
llhttp: '6.0.0',
openssl: '1.1.1k+quic',
cldr: '39.0',
icu: '69.1',
tz: '2021a',
unicode: '13.0',
ngtcp2: '0.1.0-DEV',
nghttp3: '0.1.0-DEV'
}
PS: I LOVE the new update! Thank you all so much for this wonderful plugin which makes my life as a Hugo dev 10,000 times better every day!!
I'm not sure if the following is related to the above, or an entire separate issue, but I am also seeing a single extra line added between a Hugo tag and an HTML tag.
For example, this codes is formatted in a that I think we would all expect.
<div>
<div>
{{ partial "someHugoExpression" . }}
</div>
<div>text</div>
</div>
On the other hand, when we have a hugo tag by itself followed by a new HTML tag, then we get this extra line for some reason. Example:
<div>
{{ partial "someHugoExpression" . }}
<div>text</div>
</div>
Note that the newline is not forced if there was no blank line to begin with, but as soon as one blank line is added in this case, prettier adds a second one for some reason.
It looks like faq.html
doesn't produce a new line, but footnote-format.html
does still produce a newline in prettier-plugin-go-template@0.0.12-beta-1
@all-contributors please add @jasikpark for bug doc example ideas maintenance question
I've put up a pull request to add @jasikpark! π
I've put up a pull request to add @jasikpark! π
This was about time π
@all-contributors please add @LandGod for bug
I've put up a pull request to add @LandGod! π
Sorry for the e-mail spam guys π