mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-17 05:50:24 +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 (
|
||||
rule in list(set(re.split(r"\s|,", ignored_match.group(1).strip())))
|
||||
and ignored_match.start(0) <= match.start()
|
||||
and match.end(0) <= ignored_match.end()
|
||||
and (
|
||||
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 False
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
# 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
|
||||
|
|
@ -897,3 +897,20 @@ def test_ignoring_rules(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
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