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"")