feat(linter): t002 added a few more tags to the check

closes #386
This commit is contained in:
Christopher Pickering 2022-09-16 10:06:00 +02:00
parent ecb95bbee0
commit 532c5b8d94
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 26 additions and 1 deletions

View file

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

View file

@ -79,6 +79,31 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert "T002" not in result.output
write_to_file(tmp_file.name, b"{% with a='this' %}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002" in result.output
write_to_file(tmp_file.name, b"{% trans 'this' %}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002" in result.output
write_to_file(tmp_file.name, b"{% translate 'this' %}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002" in result.output
write_to_file(tmp_file.name, b"{% include 'this' %}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002" in result.output
write_to_file(tmp_file.name, b"{% now 'Y-m-d G:i:s' %}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T002" in result.output
def test_T003(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"{% endblock %}")