Skip to content

Commit

Permalink
fix(linter): fixed false positive on DJ018
Browse files Browse the repository at this point in the history
Thanks @danigm

closes #755
  • Loading branch information
christopherpickering committed Sep 18, 2023
1 parent 183a7c0 commit 78d81dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@
flags: re.DOTALL|re.I
patterns:
- <(?:a|div|span|input)\b[^>]*?\s(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:|data:)[\w|/]+
- <form\b[^>]*?(?:\saction)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/]+
- <form(?:(?!>|\saction=(?:\"[^\"]*\"|'[^']*')).)*?\saction=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/|\s]+
- rule:
name: J018
message: (Jinja) Internal links should use the {{ url_for() ... }} pattern.
flags: re.DOTALL|re.I
patterns:
- <(?:a|div|span|input)\b[^>]*?\s(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:|data:)[\w|/]+
- <form\s+?[^>]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/]+
- <form(?:(?!>|\saction=(?:\"[^\"]*\"|'[^']*')).)*?\saction=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/|\s]+
- rule:
name: H019
message: Replace 'javascript:abc()' with on_ event and real url.
Expand Down
5 changes: 5 additions & 0 deletions tests/test_linter/test_django_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
([]),
id="DJ018_data_action",
),
pytest.param(
('<form action="{% url \'something\' action="xxx" %}"></form>'),
([]),
id="DJ018_action_attr_url",
),
pytest.param(
("{% blah 'asdf %}"),
(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_linter/test_jinja_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
([]),
id="J018_attributes",
),
pytest.param(
('<form action="{{ url_for(\'something\', action="xxx") }}"></form>'),
([]),
id="J018_action_attr_url",
),
pytest.param(
(
"{% macro rendersubmit(buttons=[], class=\"\", index='', url='', that=\"\" , test='') -%}"
Expand Down

0 comments on commit 78d81dc

Please sign in to comment.