Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formatter): added option to add blank line before tags
closes #307
- Loading branch information
Christopher Pickering
committed
Jul 28, 2022
1 parent
ee87ef7
commit b2bd1ea
Showing
14 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends "nothing.html" %}{% load stuff %}{% load stuff 2 %}{% include "html_two.html" %}<div></div> |
3 changes: 3 additions & 0 deletions
3
tests/test_config/test_blank_lines_before_tag/html_eight.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% extends nothing %} | ||
|
||
<div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<tr> | ||
<td rowspan="{{ quality.row_span }}"> | ||
|
||
{% include "common/pdfs/partials/display_quality_improvements.html" %} | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% block this %} | ||
{% load i18n %} | ||
{% endblock this %} |
6 changes: 6 additions & 0 deletions
6
tests/test_config/test_blank_lines_before_tag/html_seven.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% blocktrans %}my words{% endblocktrans %} | ||
{% block body %} | ||
<div></div> | ||
|
||
{% endblock body %} | ||
{% block js %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{% block include %} | ||
{# {% include 'common/sticky-topbar-hidden-nav.html' %}#} | ||
|
||
{% endblock %} |
8 changes: 8 additions & 0 deletions
8
tests/test_config/test_blank_lines_before_tag/html_three.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="tab-cnt"> | ||
<div class="tab-dta active" id="details"> | ||
<div class="em-grid"> | ||
|
||
{% include "pages/task/details_source.html.j2" %} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% load stuff %} | ||
<div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[tool] | ||
[tool.djlint] | ||
blank_line_before_tag = "load, extends, include ,endblock " |
101 changes: 101 additions & 0 deletions
101
tests/test_config/test_blank_lines_before_tag/test_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""Djlint tests specific to pyproject.toml configuration. | ||
run:: | ||
pytest tests/test_config/test_blank_lines_before_tag/test_config.py --cov=src/djlint --cov-branch \ | ||
--cov-report xml:coverage.xml --cov-report term-missing | ||
for a single test, run:: | ||
pytest tests/test_config.py::test_custom_html --cov=src/djlint \ | ||
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing | ||
""" | ||
# pylint: disable=C0116 | ||
|
||
from click.testing import CliRunner | ||
|
||
from src.djlint import main as djlint | ||
|
||
|
||
def test_blank_lines_before_tag(runner: CliRunner) -> None: | ||
result = runner.invoke( | ||
djlint, ["tests/test_config/test_blank_lines_before_tag/html.html", "--check"] | ||
) | ||
|
||
assert ( | ||
"""+{% extends "nothing.html" %} | ||
+ | ||
+{% load stuff %} | ||
+{% load stuff 2 %} | ||
+ | ||
+{% include "html_two.html" %} | ||
+<div></div>""" | ||
in result.output | ||
) | ||
assert """1 file would be updated.""" in result.output | ||
assert result.exit_code == 1 | ||
|
||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_two.html", "--check"], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# check blocks that do not start on a newline - they should be left as is. | ||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_three.html", "--check"], | ||
) | ||
|
||
assert """0 files would be updated.""" in result.output | ||
assert result.exit_code == 0 | ||
|
||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_four.html", "--check"], | ||
) | ||
|
||
assert result.exit_code == 1 | ||
assert ( | ||
""" {% block this %} | ||
-{% load i18n %} | ||
+ | ||
+ {% load i18n %} | ||
+ | ||
{% endblock this %} | ||
""" | ||
in result.output | ||
) | ||
|
||
# something perfect should stay perfect :) | ||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_five.html", "--check"], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# something perfect should stay perfect :) | ||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_six.html", "--check"], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# make sure endblock doesn't pick up endblocktrans :) | ||
result = runner.invoke( | ||
djlint, | ||
["tests/test_config/test_blank_lines_before_tag/html_seven.html", "--check"], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# check that multiple blank lines are not added | ||
result = runner.invoke( | ||
djlint, | ||
[ | ||
"tests/test_config/test_blank_lines_before_tag/html_eight.html", | ||
"--preserve-blank-lines", | ||
"--check", | ||
], | ||
) | ||
assert result.exit_code == 0 |