djLint
djLint copied to clipboard
[BUG] [Linter] False postitive on T002 when tag is embedded in an HTML attribute
- [x] I'm on the latest version of djLint
- [x] I've searched the issues
- [x] I've read the docs
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"
Thanks for opening your first issue here!
Thanks for reporting with examples. This is a similar case to #141 and will probably be fixed in the same code.
Sorry, maybe I misunderstand but what stops you from using double quotes in the alt
and aria-label
attributes?
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)
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.