fix(linter): t002

Fixed bad match on t002.
This commit is contained in:
Christopher Pickering 2022-09-19 10:00:32 +02:00
parent 223200fe57
commit 190ad01ff3
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 12 additions and 3 deletions

View file

@ -26,7 +26,7 @@
message: Double quotes should be used in tags.
flags: re.DOTALL
patterns:
- "{%[ \t]*?(?:trans(?:late)?|with|extends|include|now)?[ \t]+?(?:[^']+?=)?'[^']*'"
- "{%[ \t]*?(?:trans(?:late)?|with|extends|include|now)?[ \t]+?(?:[^']+?=)?'[^']*?'(?:(?!%}).)*?%}"
- rule:
name: T003
message: 'Endblock should have name. Ex: {% endblock body %}.'
@ -203,12 +203,12 @@
# for single quotes
- "{%((?:(?!'|%}).)*?(')(?:(?!\\2|%}).)*?\\2(?:(?!\\2|%}).)*?)*\\2(?:(?!\\2|%}).)*?%}"
# for double quotes
- "{%((?:(?!\"|%}).)*?(\")(?:(?!\\2|%}).)*?\\2(?:(?!\\2|%}).)*?)*\\2(?:(?!\\2|%}).)*?%}"
- '{%((?:(?!"|%}).)*?(")(?:(?!\2|%}).)*?\2(?:(?!\2|%}).)*?)*\2(?:(?!\2|%}).)*?%}'
# for single quotes
- "{{((?:(?!'|}}).)*?(')(?:(?!\\2|}}).)*?\\2(?:(?!\\2|}}).)*?)*\\2(?:(?!\\2|}}).)*?}}"
# for double quotes
- "{{((?:(?!\"|}}).)*?(\")(?:(?!\\2|}}).)*?\\2(?:(?!\\2|}}).)*?)*\\2(?:(?!\\2|}}).)*?}}"
- '{{((?:(?!"|}}).)*?(")(?:(?!\2|}}).)*?\2(?:(?!\2|}}).)*?)*\2(?:(?!\2|}}).)*?}}'
# for tags with a single quote
- "{%((?:(?!'|\"|%}).)*?('|\")(?:(?!\\2|%}).)*?)%}"

View file

@ -104,6 +104,15 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
assert result.exit_code == 1
assert "T002" in result.output
# verify regex doesn't over grab
write_to_file(
tmp_file.name,
b"""{% extends "layout.h" %}
<div class="card" data-list='{"name": "blah"}'>""",
)
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert "T002" not in result.output
def test_T003(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"{% endblock %}")