question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Additional newlines added during every format under prettier-ignore

See original GitHub issue

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:

lyG0Hs8wwd

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!!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
NiklasPorcommented, Mar 31, 2022

@all-contributors please add @LandGod for bug

2reactions
allcontributors[bot]commented, Mar 31, 2022

@NiklasPor

I’ve put up a pull request to add @jasikpark! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Markdown inserts unexpected newline in lists #8004 - GitHub
I insert the newline between "Nested item 2" and "Top level item 2" intentionally, to keep the the top level items visually distinct, ......
Read more >
Ignoring Code - Prettier
Use .prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.
Read more >
Is there a config in prettier to keep line breaks? - Stack Overflow
According to this Github issue and looking at the doc, it doesn't seem to be possible to configure it to keep line breaks....
Read more >
prettier ignore all files | The AI Search Engine You Control
Its not possible add an ignore config to prettiers config file (based on the docs). The only ways seems to be to have...
Read more >
prettierignore line Code Example
prettier-ignore. ... “prettierignore line” Code Answer's. prettier ignore line ... coverage. Source: prettier.io. Add a Grepper Answer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found