djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
689 stars 84 forks source link

[BUG] [Formatter] Fix for #584 perpetually adds an empty line after front matter in nunjucks files #596

Closed aarongoldenthal closed 1 year ago

aarongoldenthal commented 1 year ago

System Info

Issue

The fix for #584 in v1.20.0 adds an empty line after front matter in nunjucks files even if on exists.

How To Reproduce

Using the following as an example:

---
layout: layouts/base.njk
---

{{ content | safe }}

Running djlint --reformat . adds another empty line after the front matter, then running djlint --check . fails saying another blank line would be added, and the cycle repeats.

This worked properly in 1.19.17, but behaves as above starting in 1.20.0 and in all subsequent releases (currently through 1.23.0).

christopherpickering commented 1 year ago

@aarongoldenthal Thanks, do you have any config options set? I don't get this on mac, but will add a test and try on windows.

aarongoldenthal commented 1 year ago

I do, my config is

{
  "extension": "njk",
  "indent": "4",
  "blank_line_after_tag": "extends, include",
  "blank_line_before_tag": "extends, include",
  "profile": "nunjucks",
  "require_pragma": false,
  "max_line_length": "120",
  "max_attribute_length": "100",
  "use_gitignore": true,
  "format_attribute_template_tags": true,
  "preserve_leading_space": false,
  "preserve_blank_lines": true,
  "format_css": false,
  "format_js": false
}
christopherpickering commented 1 year ago

Thanks, I'm guessing it is the preserve_blank_lines. I'll check it out and try to get a fix out shortly.

christopherpickering commented 1 year ago

:tada: This issue has been resolved in version 1.23.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: