djLint
djLint copied to clipboard
[BUG] [Linter] H025 false positive
- [x] I'm on the latest version of djLint
- [x] I've searched the issues
- [x] I've read the docs
System Info
- OS: e.g. ubuntu 22.04
- Python Version (
3.10.4
) - djLint Version (
1.12.1
) - template language:
django
Issue
When HTML tags are used inside strings on Django templates (e.g. as an attribute for a filter), H025 shows a false positive, thinking that the tag is orphan.
How To Reproduce
These two code snippets fall into the H025 rule but none of them should.
{% if tag|startswith:"<del>" %}
{% if tag|startswith:"<ins>" %}
@heitorado thanks 😀 this one is a very hard problem to solve. I wonder if the linter rules need another option to say if the matches are allowed to be inside template syntax or not. Some of the other rules will probably fall in the same boat.
like {% if tag|startswith:"<img />" %}
triggers several other rules too.
I'm thinking something like this:
and then checking the conditions before reporting:
I'm thinking this is also the same as/similar to #357.
I'm also seeing false-positive H25 (Tag seems to be an orphan) on this golang syntax:
{{$link := printf "<a href=\"%s\">%s</a>" $url $text}}
Apparently it's tripping on the escaped double quotes as this case is accepted:
{{$link := printf `<a href="%s">%s</a>` $url $text}}