mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-17 01:21:06 +00:00
fixed #94, added tests
This commit is contained in:
parent
086f9dad34
commit
1c7f1d654d
6 changed files with 26 additions and 21 deletions
|
|
@ -43,4 +43,16 @@ def compress_html(html: str, config: Config) -> str:
|
|||
html,
|
||||
)
|
||||
|
||||
# should we add blank lines after load tags?
|
||||
if config.blank_line_after_tag:
|
||||
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]:
|
||||
html = re.sub(
|
||||
re.compile(
|
||||
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
|
||||
re.IGNORECASE | re.MULTILINE | re.DOTALL,
|
||||
),
|
||||
r"\1\n",
|
||||
html,
|
||||
)
|
||||
|
||||
return html
|
||||
|
|
|
|||
|
|
@ -110,13 +110,9 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
elif is_raw_first_line is True:
|
||||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
||||
elif is_block_raw is True:
|
||||
elif is_block_raw is True or item.strip() == "":
|
||||
tmp = item + "\n"
|
||||
|
||||
# if just a blank line
|
||||
elif item.strip() == "":
|
||||
tmp = item.strip()
|
||||
|
||||
# otherwise, just leave same level
|
||||
else:
|
||||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
|
@ -160,16 +156,4 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
|
||||
beautified_code = beautified_code + tmp
|
||||
|
||||
# should we add blank lines after load tags?
|
||||
if config.blank_line_after_tag:
|
||||
for tag in [x.strip() for x in config.blank_line_after_tag.split(",")]:
|
||||
beautified_code = re.sub(
|
||||
re.compile(
|
||||
fr"((?:{{%\s*?{tag}[^}}]+?%}}\n?)+)",
|
||||
re.IGNORECASE | re.MULTILINE | re.DOTALL,
|
||||
),
|
||||
r"\1\n",
|
||||
beautified_code,
|
||||
)
|
||||
|
||||
return beautified_code.strip() + "\n"
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ def lint_file(config: Config, this_file: Path) -> Dict:
|
|||
|
||||
# rule H025 is a special case where the output must be an even num.
|
||||
if rule["name"] == "H025":
|
||||
open_tags = []
|
||||
open_tags: List[re.Match] = []
|
||||
|
||||
for match in re.finditer(
|
||||
re.compile(
|
||||
|
|
|
|||
4
tests/config_blank_lines_after_tag/html_five.html
Normal file
4
tests/config_blank_lines_after_tag/html_five.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<tr>
|
||||
<td rowspan="{{ quality.row_span }}">{% include "common/pdfs/partials/display_quality_improvements.html" %}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<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>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
for a single test, run::
|
||||
|
||||
pytest tests/test_config.py::test_indent --cov=src/djlint \
|
||||
pytest tests/test_config.py::test_blank_lines_after_tag --cov=src/djlint \
|
||||
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
"""
|
||||
|
|
@ -91,7 +91,6 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None:
|
|||
result = runner.invoke(
|
||||
djlint, ["tests/config_blank_lines_after_tag/html.html", "--check"]
|
||||
)
|
||||
|
||||
assert (
|
||||
"""+{% extends "nothing.html" %}
|
||||
+
|
||||
|
|
@ -141,6 +140,12 @@ def test_blank_lines_after_tag(runner: CliRunner) -> None:
|
|||
in result.output
|
||||
)
|
||||
|
||||
# something perfect should stay perfect :)
|
||||
result = runner.invoke(
|
||||
djlint, ["tests/config_blank_lines_after_tag/html_five.html", "--check"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
def test_profile(runner: CliRunner) -> None:
|
||||
result = runner.invoke(djlint, ["tests/config_profile/html.html"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue