fix(linter): fixed false positive on T002. Added tests

closes #405
This commit is contained in:
Christopher Pickering 2022-09-26 09:02:07 +02:00
parent 228a3809e1
commit 67e8c64762
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 15 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)[\\s]+?(?:[^']+?=)?'[^']*?'(?:(?!%}).)*?%}"
- "{%[ \t]*?(?:trans(?:late)?|with|extends|include|now)[\\s]+?(?:(?:(?!%}|').)+?=)?'(?:(?!%}|').)*?'(?:(?!%}).)*?%}"
- rule:
name: T003
message: 'Endblock should have name. Ex: {% endblock body %}.'

View file

@ -10,7 +10,7 @@ run::
pytest tests/test_linter/test_linter.py::test_T034
"""
# pylint: disable=C0116,C0103
# pylint: disable=C0116,C0103,C0302
from typing import TextIO
@ -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
@ -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 %}")