Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Linter] Can't ignore H006 #333

Closed
3 tasks done
aleprovencio opened this issue Aug 16, 2022 · 15 comments
Closed
3 tasks done

[BUG] [Linter] Can't ignore H006 #333

aleprovencio opened this issue Aug 16, 2022 · 15 comments
Labels
🔍 linter 🦠 bug Something isn't working released

Comments

@aleprovencio
Copy link

aleprovencio commented Aug 16, 2022

System Info

  • OS: Archlinux
  • Python Version (3.10.6)
  • djLint Version (1.9.4)
  • template language: django

Issue

I'm not able to ignore H006 ('img tag should have height and width attributes.').

How To Reproduce

On pre-commit config use args: ["-i H006"] or use one of the methods provided on documentation

@aleprovencio aleprovencio added 🔍 linter 🦠 bug Something isn't working labels Aug 16, 2022
@christopherpickering
Copy link
Contributor

Hi, Can you provide some of the code? I'm unable to reproduce with this example:

{# djlint:off H006 #}
<img />
{# djlint:on #}

H006 is ignored in the output:

H013 2:0 Img tag should have an alt attribute. <img />

Linted 1 file, found 1 error.

Or w/ a .pre-commit-config.yaml:

repos:
- repo: https://github.com/Riverside-Healthcare/djLint
  rev: v1.9.5
  hooks:
    - id: djlint-django
      args: [-i, H006]

and a simple html file:

<img />
git add .
pre-commit run --all-files

Does not return H006:

index.html

H013 1:0 Img tag should have an alt attribute. <img />

Linted 1 file, found 1 error.

@aleprovencio
Copy link
Author

Thanks for the reply.

I'm not able to get the same results on your very first example:

Hi, Can you provide some of the code? I'm unable to reproduce with this example:

{# djlint:off H006 #}
<img />
{# djlint:on #}

H006 is ignored in the output:

H013 2:0 Img tag should have an alt attribute. <img />

Linted 1 file, found 1 error.

My test is generating a project with cookiecutter-django, installing djlint on the venv and edit a template there the same way as you did.

@christopherpickering
Copy link
Contributor

Thanks, can you give me the exact steps you follow from scratch to reproduce it?
eg: clone ..., virtualenv venv... venv/bin/python -m pip install djlint ... ?

@aleprovencio
Copy link
Author

aleprovencio commented Aug 18, 2022

Sure,

  1. cookiecutter gh:cookiecutter/cookiecutter-django --no-input
  2. cd my_awesome_project/
  3. python -m venv .venv
  4. source .venv/bin/activate.fish
  5. pip install -r requirements/local.txt
  6. pip install djlint
  7. nvim my_awesome_project/templates/500.html
  8. make changes like above comments
  9. djlint --profile=django my_awesome_project/templates/500.html

@christopherpickering
Copy link
Contributor

@aleprovencio I've copied your steps and still cannot reproduce it - I swapped the fish command for the one working on Mac, and used Nano instead of nvim.

Here's some pics w/ the long pip logs removed:

image

image

image

image

image

@christopherpickering
Copy link
Contributor

Fyi, I'm finally able to reproduce on a windows machine. I'll dig into it more, I wonder if it in a way the regex is being handled.

@christopherpickering
Copy link
Contributor

Upgrading from djlint-1.3.0 to 1.11.0 fixed the problem on windows. Can you test out a pip install --upgrade djlint?

@aleprovencio
Copy link
Author

Just tested it out.

Although specifying lint error like this, is still not working:

{# djlint:off H006 #}

...this code already works as expected:

{# djlint:off #}

So I guess you're on track 😃

@christopherpickering
Copy link
Contributor

Ok cool thanks! This is getting close.

Do you have djlint in the .venv still?

In the env/lib(?)/site-packages/djlint/helpers.py, can you add two print statements for me, and then run again?

image

print(rule)
print(list(set(re.split(r"\s|,", ignored_match.group(1).strip()))))

rule should be "H006"
and the list should be "H006, H016" probably.... but maybe something else will show up :)

Otherwise, when you have time you can go on the discord and we can do a screen share on there to debug.

@aleprovencio
Copy link
Author

Hey!
On the 500.html file, with this code:

{# djlint:off H006 #}
<img />
{# djlint:on #}

The additional printed text is:

T003
['H006']
H006
['H006']
H006
['H006']
H013
['H006']

Note that finding T003 makes sense because this file comes with this by default.

However, does this output mean that T003 producing a H006 lint error?

@aleprovencio
Copy link
Author

Following your suggestions of #344:

Applying the additional print(rule_regex) on helpers.py:

<!--\s*djlint\:off(.+?)-->.*?(?=<!--\s*djlint\:on\s*-->)
{\#\s*djlint\:\s*off(.+?)\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
T003
['H006']
{%\s*comment\s*%\}\s*djlint\:off(.*?)\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s
*djlint\:on\s*\{%\s*endcomment\s*%\})
{{!--\s*djlint\:off(.*?)--}}.*?(?={{!--\s*djlint\:on\s*--}})
{{-?\s*/\*\s*djlint\:off(.*?)\*/\s*-?}}.*?(?={{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}})
<!--\s*djlint\:off(.+?)-->.*?(?=<!--\s*djlint\:on\s*-->)
{\#\s*djlint\:\s*off(.+?)\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
H006
['H006']
{%\s*comment\s*%\}\s*djlint\:off(.*?)\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s
*djlint\:on\s*\{%\s*endcomment\s*%\})
{{!--\s*djlint\:off(.*?)--}}.*?(?={{!--\s*djlint\:on\s*--}})
{{-?\s*/\*\s*djlint\:off(.*?)\*/\s*-?}}.*?(?={{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}})
<!--\s*djlint\:off(.+?)-->.*?(?=<!--\s*djlint\:on\s*-->)
{\#\s*djlint\:\s*off(.+?)\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
H006
['H006']
{%\s*comment\s*%\}\s*djlint\:off(.*?)\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s
*djlint\:on\s*\{%\s*endcomment\s*%\})
{{!--\s*djlint\:off(.*?)--}}.*?(?={{!--\s*djlint\:on\s*--}})
{{-?\s*/\*\s*djlint\:off(.*?)\*/\s*-?}}.*?(?={{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}})
<!--\s*djlint\:off(.+?)-->.*?(?=<!--\s*djlint\:on\s*-->)
{\#\s*djlint\:\s*off(.+?)\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
H013
['H006']
{%\s*comment\s*%\}\s*djlint\:off(.*?)\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s
*djlint\:on\s*\{%\s*endcomment\s*%\})
{{!--\s*djlint\:off(.*?)--}}.*?(?={{!--\s*djlint\:on\s*--}})
{{-?\s*/\*\s*djlint\:off(.*?)\*/\s*-?}}.*?(?={{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}})

And print(inside_ignored_rule(config, html, match,rule["name"])) on lint.py (helpers.py print statements off):

False
False
False
False

@christopherpickering
Copy link
Contributor

However, does this output mean that T003 producing a H006 lint error?

It means that T003 was found, and H006 is what you were trying to ignore.

I think I have a fix on the way, thanks!

christopherpickering pushed a commit that referenced this issue Aug 24, 2022
# [1.12.0](v1.11.1...v1.12.0) (2022-08-24)

### Bug Fixes

* **h006:** prevented false positives on H006 ([215bd23](215bd23)), closes [#344](#344) [#333](#333)
* **h012:** prevent H012 from matching the contents of tags or attributes ([4480cff](4480cff)), closes [#348](#348)
* **t001:** fixed false positive on multiline template tags ([ea76672](ea76672)), closes [#350](#350)

### Features

* **h021:** allow inline styles that contain template syntax ([f1a39ed](f1a39ed)), closes [#351](#351)
* **t002:** allow variables names to be used in the {% extends tag ([a5d96e7](a5d96e7)), closes [#349](#349)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@aleprovencio
Copy link
Author

Thank you @christopherpickering !

@christopherpickering
Copy link
Contributor

No prob, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 linter 🦠 bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants