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] H025 False positive when trans tag contains one single quote #447

Closed
3 tasks done
a-edakin opened this issue Nov 5, 2022 · 5 comments
Closed
3 tasks done
Labels
🔍 linter 🦠 bug Something isn't working released

Comments

@a-edakin
Copy link

a-edakin commented Nov 5, 2022

  • I'm on the latest version of djLint
  • I've searched the issues I hope I checked all issues related to H025 if it's duplicate sorry:(
  • I've read the docs

System Info

  • OS: I don't think it's relevent because I could reproduce it on any OS
  • Python Version: 3.10.2
  • djLint Version: 1.19.4
  • template language: django

Issue

False positive H025 issue if HTML's tag attribute contains {% trans "some text with ONE single ' quote" %}.

But if I would use second quote then everything would be fine {% trans "some text with TWO single '' quote" %}.

How To Reproduce

HTML file to reproduce:

<button title="{% trans "text with ONE single ' quote" %}">
</button>

<a title="{% trans "text with ONE single ' quote" %}">
</a>

Command: djlint -

Console output:

templates/test_tag_trans.html
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
H025 1:0 Tag seems to be an orphan. <button title="{% tr
H025 5:0 Tag seems to be an orphan. </a>

Linted 34 files, found 2 errors.

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

[tool.djlint]
profile="django"
indent = 4
max_line_length=120
blank_line_before_tag="include,for,block"
blank_line_after_tag="load,include,endfor,endblock"
ignore="H021,H022,H006"
files = ["templates"]
@a-edakin a-edakin added 🔍 linter 🦠 bug Something isn't working labels Nov 5, 2022
@christopherpickering
Copy link
Contributor

Attribute parsing is gonna kill me lol. I'll put out a fix shortly. I'm working hard on an update that will get rid of most regex 😅

@a-edakin
Copy link
Author

a-edakin commented Nov 7, 2022

To fix this issue I just moved trans tag out of attributes

{% trans "text with ONE single ' quote" as tanslated_text %}
<button title="{{ tanslated_text }}">
</button>

@SebastiaanZ
Copy link

SebastiaanZ commented Nov 7, 2022

You've probably already know this, but it's not limited to the trans tag:

     <p>
         <some-tag
-                    onclick="window.location.href = '{% url 'app:view' %}'">
+                    onclick="window.location.href = '{% url 'app:view' %}">
         </some-tag>
     </p>

Although my guess is that you use a generic, not tag/filter specific, method of counting nested quotation marks.

@christopherpickering
Copy link
Contributor

@SebastiaanZ @a-edakin thanks! I should have a release out shortly that covers both cases.

christopherpickering pushed a commit that referenced this issue Nov 7, 2022
## [1.19.5](v1.19.4...v1.19.5) (2022-11-07)

### Bug Fixes

* **linter:** make attribute pattern on H025 more accepting. Prevent false positive ([1bd0bf7](1bd0bf7)), closes [#447](#447)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.19.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

3 participants