djLint icon indicating copy to clipboard operation
djLint copied to clipboard

[BUG] [Linter] H025 false positive

Open heitorado opened this issue 2 years ago • 3 comments

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 avatar Sep 06 '22 18:09 heitorado

@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:

image

and then checking the conditions before reporting:

image

christopherpickering avatar Sep 07 '22 12:09 christopherpickering

I'm thinking this is also the same as/similar to #357.

christopherpickering avatar Sep 07 '22 12:09 christopherpickering

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}}

silverwind avatar Jun 13 '23 22:06 silverwind