djLint icon indicating copy to clipboard operation
djLint copied to clipboard

[BUG] [Linter] False postitive on T002 when tag is embedded in an HTML attribute

Open thirdjal opened this issue 1 year ago • 5 comments

System Info

  • OS: macOS 13.4
  • Python Version: 3.10.11
  • djLint Version 1.30.2
  • template language: django

Issue

I've run into an issue where a number of my templates are reporting Linting error T002: Double quotes should be used in tags. This rule conflicts with H008: Attributes should be double quoted.

This issue comes up when using i18n translation tags inside attributes of an element, such as a tooltip, image alt-text, or labels for assistive services. These should not be considered a violation of rule T002.

How To Reproduce

Examples with false flags Alt-text on an image <img src="https://picsum.photos/200/100" alt="{% translate 'A very nice image' %}">

A Bootstrap close button <button type="button" class="btn-close" aria-label="{% translate 'Close' %}"></button>

Contents of .djlintrc/pyproject.toml [tool.djlint]

[tool.djlint] blank_line_after_tag="load,extends,endblock" indent=2 max_line_length=120 profile="django"

thirdjal avatar Jun 06 '23 23:06 thirdjal

Thanks for opening your first issue here!

welcome[bot] avatar Jun 06 '23 23:06 welcome[bot]

Thanks for reporting with examples. This is a similar case to #141 and will probably be fixed in the same code.

christopherpickering avatar Jun 07 '23 00:06 christopherpickering

Sorry, maybe I misunderstand but what stops you from using double quotes in the alt and aria-label attributes?

andreighh avatar Nov 15 '23 16:11 andreighh

Another similar case: when the part in single quotes contains double quotes (eg for a bit of html):

{% with '<pre class="dsfr-code">'|concatenate:raw_sample_code|concatenate:"</pre>" as sample_data_code %}

(concatenate here being a custom templatetag)

Ash-Crow avatar Dec 14 '23 09:12 Ash-Crow

Might be the same problem, but with different code:

{% bootstrap_button button_type="submit" content="<i class='fas fa-edit'></i> Save" css_classes="btn btn-primary mt-2" %}

Is reported as:

H008 23:58 Attributes should be double quoted. <i class='fas fa-edi

If it is not the same problem, I can open another issue.

PetrDlouhy avatar Mar 29 '24 20:03 PetrDlouhy