Skip to content

Commit

Permalink
fix(linter): t002
Browse files Browse the repository at this point in the history
Fixed bad match on t002.
  • Loading branch information
christopherpickering committed Sep 19, 2022
1 parent 223200f commit 190ad01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/djlint/rules.yaml
Expand Up @@ -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 %}.'
Expand Down Expand Up @@ -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|%}).)*?)%}"
Expand Down
9 changes: 9 additions & 0 deletions tests/test_linter/test_linter.py
Expand Up @@ -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 %}")
Expand Down

0 comments on commit 190ad01

Please sign in to comment.