From 5cf1e1cc5bae4943ad9b322fb7faa78d8ec5664e Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 10 May 2023 16:15:57 -0500 Subject: [PATCH 1/2] fix(formatter): fixed set_ tags being broken closes #634 --- src/djlint/formatter/indent.py | 2 +- tests/test_nunjucks/test_set.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index 8c192c0c..db429695 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -368,7 +368,7 @@ def format_set(config, match): # format set contents beautified_code = re.sub( re.compile( - r"([ ]*{%-?)[ ]*(set)((?:(?!%}).)*?)(-?%})", + r"([ ]*{%-?)[ ]*(set)[ ]+?((?:(?!%}).)*?)(-?%})", flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE | re.DOTALL, ), func, diff --git a/tests/test_nunjucks/test_set.py b/tests/test_nunjucks/test_set.py index 62e03324..be78ff2d 100644 --- a/tests/test_nunjucks/test_set.py +++ b/tests/test_nunjucks/test_set.py @@ -20,6 +20,12 @@ ({}), id="set_with_sibling", ), + pytest.param( + ('{% set_title "My Title" %}'), + ('{% set_title "My Title" %}\n'), + ({}), + id="don't break underscore stuff", + ), pytest.param( ( "{% set schema=[\n" From e65558ccf30e66040349d1bdc516c1816b83c336 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 10 May 2023 16:28:03 -0500 Subject: [PATCH 2/2] fix(linter): fixed false positive on H037 thanks @kai687 closes #633 --- src/djlint/rules.yaml | 2 +- tests/test_linter/test_django_linter.py | 11 +---------- tests/test_linter/test_h037.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 79035659..8f40b0d9 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -276,4 +276,4 @@ message: Duplicate attribute found. flags: re.I patterns: - - <\w[^>]*?\s\K([a-z][a-z-]*?)(?==[^>]+?\1=[^>]*?>) + - <\w[^>]*?\s\K([a-z-][a-z-]*?)(?==[^>]+?[^-]\1=[^>]*?>) diff --git a/tests/test_linter/test_django_linter.py b/tests/test_linter/test_django_linter.py index ce083a1b..17946246 100644 --- a/tests/test_linter/test_django_linter.py +++ b/tests/test_linter/test_django_linter.py @@ -276,16 +276,7 @@ ), pytest.param( ('
'), - ( - [ - { - "code": "H037", - "line": "1:6", - "match": "action", - "message": "Duplicate attribute found.", - } - ] - ), + ([]), id="DJ018_data_action", ), pytest.param( diff --git a/tests/test_linter/test_h037.py b/tests/test_linter/test_h037.py index c6ae2db7..3ccb33f6 100644 --- a/tests/test_linter/test_h037.py +++ b/tests/test_linter/test_h037.py @@ -41,6 +41,25 @@ ([]), id="mismatch names", ), + pytest.param( + (''), + ( + [ + { + "code": "H037", + "line": "1:5", + "match": "-width", + "message": "Duplicate attribute found.", + } + ] + ), + id="leading hyphen names", + ), + pytest.param( + (''), + ([]), + id="mismatch hyphen names", + ), pytest.param( ( ''