added rule T027. closes #134

This commit is contained in:
Christopher Pickering 2021-11-15 16:47:36 +01:00
parent 5eddca90fe
commit c39693c7df
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
5 changed files with 32 additions and 2 deletions

View file

@ -1,6 +1,10 @@
Changelog
=========
next_release
------------
- Added rule T027 to check for unclosed in template syntax
0.5.9a
------
- Added test support for python 3.10

View file

@ -63,6 +63,9 @@ Codes
+--------+-------------------------------------------------------------------------+
| H026 | Emtpy id and class tags can be removed. |
+--------+-------------------------------------------------------------------------+
| T027 | Unclosed string found in template syntax. |
+--------+-------------------------------------------------------------------------+
Adding Rules
------------

View file

@ -192,3 +192,10 @@
patterns:
- <\w+\b[^(?:{(?:%|{|#))>]*?\b(class|id)\b=(\"\"|'')
- <\w+\b[^(?:{(?:%|{|#))>]*?\b(class|id)\b[^=\"]
- rule:
name: T027
message: Unclosed string found in template syntax.
flags: re.I
patterns:
- "{%(?:(?!'|\"|%}).)*((?:'|\")(?:(?!'|\"|%}).)*(?:'|\")(?:(?!'|\"|%}).)*)*(?:'|\")(?:(?!'|\"|%}).)*%}"
- "{{(?:(?!'|\"|}}).)*((?:'|\")(?:(?!'|\"|}}).)*(?:'|\")(?:(?!'|\"|}}).)*)*(?:'|\")(?:(?!'|\"|}}).)*}}"

View file

@ -636,7 +636,7 @@ class Config:
| {{-?\s*/\*\s*djlint\:off\s*\*/\s*-?}}.*?{{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}
| <!--.*?-->
| <\?php.*?\?>
| {\%[ ]trans[ ][^}]*?\%}
# | {\%[ ]trans[ ][^}]*?\%}
| {%[ ]+?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]+?endcomment[ ]+?%}
"""

View file

@ -7,7 +7,7 @@ run::
# for a single test
pytest tests/test_linter.py::test_output_order --cov=src/djlint --cov-branch \
pytest tests/test_linter.py::test_T027 --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
"""
@ -433,6 +433,22 @@ def test_H026(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H026" not in result.output
def test_T027(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"{% blah 'asdf %}")
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "T027" in result.output
write_to_file(tmp_file.name, b"{% blah 'asdf' %}{{ blah \"asdf\" }}")
result = runner.invoke(djlint, [tmp_file.name])
assert "T027" not in result.output
write_to_file(tmp_file.name, b"{% blah 'asdf' 'blah %}")
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "T027" in result.output
def test_rules_not_matched_in_ignored_block(
runner: CliRunner, tmp_file: TextIO
) -> None: