added rstrip to attributes after formatting. updated tests. closes #69

This commit is contained in:
Christopher Pickering 2021-10-07 08:22:29 +02:00
parent 863efbf116
commit d6c6e49f19
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 7 additions and 3 deletions

View file

@ -157,4 +157,7 @@ def format_attributes(config: Config, match: re.match) -> str:
# format template tags
attributes = format_template_tags(config, attributes)
# clean trailing spaces added by breaks
attributes = "\n".join([x.rstrip() for x in attributes.splitlines()])
return f"{attributes}"

View file

@ -7,7 +7,7 @@ run::
for a single test, run::
pytest tests/test_django.py::test_empty_tags_on_one_line --cov=src/djlint \
pytest tests/test_django.py::test_complex_attributes --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
@ -312,13 +312,14 @@ def test_complex_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<a class="{% if favorite == "yes" %}favorite{% endif %} has-tooltip-arrow has-tooltip-right" data-tooltip="{% if favorite == "yes" %}Remove from Favorites {% else %}Add to Favorites{% endif %}" fav-type="report" object-id="{{ report.report_id }}"><span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span></a>""",
b"""<a class="asdf {% if favorite == "yes" %}favorite{% endif %} has-tooltip-arrow has-tooltip-right" data-tooltip="{% if favorite == "yes" %}Remove from Favorites {% else %}Add to Favorites{% endif %}" fav-type="report" object-id="{{ report.report_id }}"><span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span></a>""",
)
assert output["exit_code"] == 1
assert (
output["text"]
== r"""<a class="{% if favorite == "yes" %}
== r"""<a class="asdf
{% if favorite == "yes" %}
favorite
{% endif %}
has-tooltip-arrow has-tooltip-right"