fixes #143, added test

This commit is contained in:
Christopher Pickering 2021-11-23 10:06:38 +01:00
parent 3af4517ce7
commit d2a42f2be0
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 9 additions and 1 deletions

View file

@ -206,6 +206,8 @@
- rule:
name: T028
message: Consider using spaceless tags inside attribute values. {%- if/for -%}
exclude:
- django
patterns:
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?({%)[^-])\s*?(?:if|for|else|end)
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?{%(?:(?!%}).)*(?:if|else|for|end)(?:(?!%}).)*[^-](%}))

View file

@ -7,7 +7,7 @@ run::
# for a single test
pytest tests/test_linter.py::test_H017 --cov=src/djlint --cov-branch \
pytest tests/test_linter.py::test_T028 --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
"""
@ -476,6 +476,12 @@ def test_T028(runner: CliRunner, tmp_file: TextIO) -> None:
assert result.exit_code == 1
assert "T028" in result.output
# django should not trigger
write_to_file(tmp_file.name, b"<a href=\"{%- if 'asdf' %}\">")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 1
assert "T028" not in result.output
write_to_file(tmp_file.name, b"<a href=\"{{- blah 'asdf' }}\">")
result = runner.invoke(djlint, [tmp_file.name])
assert "T028" not in result.output