Skip to content

Commit

Permalink
fix(linter): fixed false positive on T002. Added tests
Browse files Browse the repository at this point in the history
closes #405
  • Loading branch information
christopherpickering committed Sep 26, 2022
1 parent 228a380 commit 67e8c64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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)[\\s]+?(?:[^']+?=)?'[^']*?'(?:(?!%}).)*?%}"
- "{%[ \t]*?(?:trans(?:late)?|with|extends|include|now)[\\s]+?(?:(?:(?!%}|').)+?=)?'(?:(?!%}|').)*?'(?:(?!%}).)*?%}"
- rule:
name: T003
message: 'Endblock should have name. Ex: {% endblock body %}.'
Expand Down
16 changes: 14 additions & 2 deletions tests/test_linter/test_linter.py
Expand Up @@ -10,7 +10,7 @@
pytest tests/test_linter/test_linter.py::test_T034
"""
# pylint: disable=C0116,C0103
# pylint: disable=C0116,C0103,C0302

from typing import TextIO

Expand Down Expand Up @@ -108,7 +108,9 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""{% extends "layout.h" %}
<div class="card" data-list='{"name": "blah"}'>""",
<div class="card" data-list='{"name": "blah"}'>
{% include "template.html" %}
<div {% fpr %} data-{{ name }}='{{ value }}'{% endfor %}/>""",
)
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert "T002" not in result.output
Expand All @@ -124,6 +126,16 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert "T002" not in result.output

# verify correct line is returned
write_to_file(
tmp_file.name,
b"""{% include "template.html" %}
{% include "template.html" with type='mono' %}""",
)
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002 2:" 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 67e8c64

Please sign in to comment.