From 67e8c647622abb655d1cd7c0ea1757262ab8b60e Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 26 Sep 2022 09:02:07 +0200 Subject: [PATCH] fix(linter): fixed false positive on T002. Added tests closes #405 --- src/djlint/rules.yaml | 2 +- tests/test_linter/test_linter.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 892a3d4..1b4b56c 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -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 %}.' diff --git a/tests/test_linter/test_linter.py b/tests/test_linter/test_linter.py index 235ff74..36a0587 100644 --- a/tests/test_linter/test_linter.py +++ b/tests/test_linter/test_linter.py @@ -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" %} -
""", +
+{% include "template.html" %} +
""", ) 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 %}")