From 946b8ad7152b098ddc2489a52bc668ba48737445 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Tue, 26 Jul 2022 12:21:41 -0500 Subject: [PATCH] fix(linter): fixed false positive on T027 closes #301 --- src/djlint/rules.yaml | 23 +++++++++++++++++++---- tests/test_linter/test_linter.py | 8 ++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index be84c99..420ec44 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -199,11 +199,26 @@ flags: re.I patterns: # for tags with 3/5/7... 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|%}).)*?%}" + + # for single quotes + - "{{((?:(?!'|}}).)*?(')(?:(?!\\2|}}).)*?\\2(?:(?!\\2|}}).)*?)*\\2(?:(?!\\2|}}).)*?}}" + # for double quotes + - "{{((?:(?!\"|}}).)*?(\")(?:(?!\\2|}}).)*?\\2(?:(?!\\2|}}).)*?)*\\2(?:(?!\\2|}}).)*?}}" + # for tags with a single quote - - "{%((?:(?!'|\"|%}).)*?(\"|')(?:(?!\\2|%}).)*?)%}" - - "{{((?:(?!'|\"|}}).)*?(\"|')(?:(?!\\2|}}).)*?)}}" + # for double quotes + - "{%((?:(?!\"|%}).)*?(\")(?:(?!\\2|%}).)*?)%}" + # for single quotes + - "{%((?:(?!'|%}).)*?(')(?:(?!\\2|%}).)*?)%}" + + # for double quotes + - "{{((?:(?!\"|}}).)*?(\")(?:(?!\\2|}}).)*?)}}" + # for single quotes + - "{{((?:(?!'|}}).)*?(')(?:(?!\\2|}}).)*?)}}" - rule: name: T028 message: Consider using spaceless tags inside attribute values. {%- if/for -%} diff --git a/tests/test_linter/test_linter.py b/tests/test_linter/test_linter.py index b088d2a..f9f3081 100644 --- a/tests/test_linter/test_linter.py +++ b/tests/test_linter/test_linter.py @@ -593,6 +593,14 @@ def test_T027(runner: CliRunner, tmp_file: TextIO) -> None: result = runner.invoke(djlint, [tmp_file.name]) assert "T027" not in result.output + # test mixed quotes + write_to_file( + tmp_file.name, + b"{% macro rendersubmit(buttons=[], class=\"\", index='', url='', that=\"\" , test='') -%}", + ) + result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"]) + assert "T027" not in result.output + def test_T028(runner: CliRunner, tmp_file: TextIO) -> None: write_to_file(tmp_file.name, b"")