fix(linter): fixed false positive on T027

closes #301
This commit is contained in:
Christopher Pickering 2022-07-26 12:21:41 -05:00
parent 4089cb841e
commit 946b8ad715
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 27 additions and 4 deletions

View file

@ -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 -%}

View file

@ -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"<a href=\"{% blah 'asdf' -%}\">")