Skip to content

Commit

Permalink
fix(h006): prevented false positives on H006
Browse files Browse the repository at this point in the history
Also other linter rules where the the error match partially overlaps the ignored block.

closes #344, closes #333
  • Loading branch information
christopherpickering committed Aug 24, 2022
1 parent 4480cff commit 215bd23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/djlint/helpers.py
Expand Up @@ -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
19 changes: 18 additions & 1 deletion tests/test_linter/test_linter.py
Expand Up @@ -7,7 +7,7 @@
# 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
Expand Down Expand Up @@ -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

0 comments on commit 215bd23

Please sign in to comment.