fix(linter): disabling linter rules should not disable formatting

closes #316
This commit is contained in:
Christopher Pickering 2022-08-01 07:32:20 -05:00
parent f0e9a02655
commit 69ef16afa8
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 30 additions and 5 deletions

View file

@ -355,8 +355,8 @@ class Config:
| <\?php
| <script
| <!--
| [^\{]{\#(?!\s*djlint\:\s*on)
| ^{\#(?!\s*djlint\:\s*on)
| [^\{]{\#(?!\s*djlint\:\s*(?:on|off))
| ^{\#(?!\s*djlint\:\s*(?:on|off))
| <pre
| <textarea
| {%[ ]*?blocktrans(?:late)?[^(?:%})]*?%}

View file

@ -0,0 +1,7 @@
{# djlint:off H021 #}
<div>
<div>
{{ test }}
</div>
</div>
{# djlint:on #}

View file

@ -2,12 +2,12 @@
run::
pytest tests/test_config.py --cov=src/djlint --cov-branch \
pytest tests/test_config/test_ignores/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 \
pytest tests/test_config/test_ignores/test_config.py::test_custom_html --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
@ -20,6 +20,24 @@ from src.djlint import main as djlint
def test_ignores(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["tests/test_config/test_ignores"])
result = runner.invoke(djlint, ["tests/test_config/test_ignores/html.html"])
assert """Linted 1 file, found 0 errors.""" in result.output
assert result.exit_code == 0
def test_ignored_rule_does_not_disable_formatting(runner: CliRunner) -> None:
result = runner.invoke(
djlint, ["tests/test_config/test_ignores/html_two.html", "--check"]
)
print(result.output)
assert (
""" {# djlint:off H021 #}
<div>
-<div>
-{{ test }}
-</div>
+ <div>{{ test }}</div>
</div>
{# djlint:on #}"""
in result.output
)