mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-12 15:33:08 +00:00
fix(h006): prevented false positives on H006
Also other linter rules where the the error match partially overlaps the ignored block. closes #344, closes #333
This commit is contained in:
parent
4480cff832
commit
215bd23190
2 changed files with 26 additions and 3 deletions
|
|
@ -148,8 +148,14 @@ def inside_ignored_rule(config: Config, html: str, match: re.Match, rule: str) -
|
||||||
):
|
):
|
||||||
if (
|
if (
|
||||||
rule in list(set(re.split(r"\s|,", ignored_match.group(1).strip())))
|
rule in list(set(re.split(r"\s|,", ignored_match.group(1).strip())))
|
||||||
and ignored_match.start(0) <= match.start()
|
and (
|
||||||
and match.end(0) <= ignored_match.end()
|
ignored_match.start(0) <= match.start()
|
||||||
|
and match.start() <= ignored_match.end()
|
||||||
|
)
|
||||||
|
or (
|
||||||
|
ignored_match.start(0) <= match.end()
|
||||||
|
and match.end() <= ignored_match.end()
|
||||||
|
)
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ run::
|
||||||
|
|
||||||
# for a single test
|
# for a single test
|
||||||
|
|
||||||
pytest tests/test_linter/test_linter.py::test_T001
|
pytest tests/test_linter/test_linter.py::test_ignoring_rules
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# pylint: disable=C0116,C0103
|
# pylint: disable=C0116,C0103
|
||||||
|
|
@ -897,3 +897,20 @@ def test_ignoring_rules(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
)
|
)
|
||||||
result = runner.invoke(djlint, [tmp_file.name])
|
result = runner.invoke(djlint, [tmp_file.name])
|
||||||
assert "H025" not in result.output
|
assert "H025" not in result.output
|
||||||
|
|
||||||
|
# using tabs
|
||||||
|
write_to_file(
|
||||||
|
tmp_file.name,
|
||||||
|
b"""<div>
|
||||||
|
|
||||||
|
\t\t{# djlint:off H006 #}
|
||||||
|
|
||||||
|
\t\t<img src="{{ kira_variable }}.webp" alt="Kira Goddess!" />
|
||||||
|
|
||||||
|
\t\t{# djlint:on #}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name])
|
||||||
|
assert "H006" not in result.output
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue