djlint / djLint

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

[BUG] [Formatter] #865

Open marcodicro-dp opened 1 month ago

marcodicro-dp commented 1 month ago

System Info

Issue

The formatter is adding an extra space inside a literal inside a js script, even if format_js is false.

How To Reproduce

Configuration

{
  "profile": "django",
  "max_blank_lines": 2,
  "max_line_length": 100,
  "indent": 2,
  "close_void_tags": true,
  "format_attribute_template_tags": false,
  "format_css": false,
  "format_js": false
}

File original contents (summarized)

{% block body %}
  <script>

    function fillValue(bulk_updatable_values, field, csvFileData) {
      if (bulk_updatable_values[field]) {
        csvFileData.push(`\<values:${bulk_updatable_values[field].join(",")}\>`);
      } else {
        csvFileData.push(`\<fill_value\>`);
      }
    }

  </script>

{% endblock %}

Reformatted file

{% block body %}
  <script>

    function fillValue(bulk_updatable_values, field, csvFileData) {
      if (bulk_updatable_values[field]) {
        csvFileData.push(`\<values:${bulk_updatable_values[field].join(",")}\>`);
      } else {
        csvFileData.push(`\<fill_value \>`);
      }
    }

  </script>

{% endblock %}

Notice the extra space after fill_value inside the else statement

I expected the formatter to leave that js untouched. I also tested setting close_void_tags to true does not change the behavior.