From 78d81dc1ee12159d8a3b6cb8fdba0a7dd94e43f3 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 18 Sep 2023 09:56:29 +0200 Subject: [PATCH] fix(linter): fixed false positive on DJ018 Thanks @danigm closes #755 --- src/djlint/rules.yaml | 4 ++-- tests/test_linter/test_django_linter.py | 5 +++++ tests/test_linter/test_jinja_linter.py | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index dc794259..e32ed564 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -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|/]+ - - ]*?(?:\saction)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/]+ + - |\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|/]+ - - ]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/]+ + - |\saction=(?:\"[^\"]*\"|'[^']*')).)*?\saction=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:|tel:)[\w|/|\s]+ - rule: name: H019 message: Replace 'javascript:abc()' with on_ event and real url. diff --git a/tests/test_linter/test_django_linter.py b/tests/test_linter/test_django_linter.py index 46a80d6b..da73d588 100644 --- a/tests/test_linter/test_django_linter.py +++ b/tests/test_linter/test_django_linter.py @@ -279,6 +279,11 @@ ([]), id="DJ018_data_action", ), + pytest.param( + ('
'), + ([]), + id="DJ018_action_attr_url", + ), pytest.param( ("{% blah 'asdf %}"), ( diff --git a/tests/test_linter/test_jinja_linter.py b/tests/test_linter/test_jinja_linter.py index f57f2c22..3523ffa6 100644 --- a/tests/test_linter/test_jinja_linter.py +++ b/tests/test_linter/test_jinja_linter.py @@ -134,6 +134,11 @@ ([]), id="J018_attributes", ), + pytest.param( + ('
'), + ([]), + id="J018_action_attr_url", + ), pytest.param( ( "{% macro rendersubmit(buttons=[], class=\"\", index='', url='', that=\"\" , test='') -%}"