djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[BUG] [Linter] Linter fails with D018 on url parameter with name = "action" #755

Closed danigm closed 1 year ago

danigm commented 1 year ago

System Info

Issue

The Linter complains with an error D018 1:0 (Django) Internal links should use the {% url ... %} pattern. if a form has a django url with a parameter named "action".

How To Reproduce

Lint the following file:

  <form method="post" class="header-form" action="{% url "web:profile_action" action="token_revoke" %}">

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

profile="django"
max_line_length = 120
welcome[bot] commented 1 year ago

Thanks for opening your first issue here!

danigm commented 1 year ago

I've a branch adding this issue to the tests: https://github.com/danigm/djLint/commit/016b7c9d2041a3c3f56af61b83d3f3a3fe263a62

I've been trying to improve the regex, but I think it's not easy to detect this condition with just a regular expression...

christopherpickering commented 1 year ago

Thanks for those tests, I'll update the regex to make them pass. The regex is not foolproof, but will pass the tests, which is what we need :)

One day all the rules should be converted to python and use the template and attribute parser packages for finding things. Wish someone from ruff would do it 😀

christopherpickering commented 1 year ago

:tada: This issue has been resolved in version 1.33.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: