Skip to content

Commit

Permalink
fix(linter): fix missed H025 for double closing
Browse files Browse the repository at this point in the history
Closes #786
  • Loading branch information
MrkGrgsn committed Nov 13, 2023
1 parent 2761307 commit cf52faf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/djlint/rules/H025.py
Expand Up @@ -25,6 +25,8 @@ def run(
"""Check for orphans html tags."""
errors: List[Dict[str, str]] = []
open_tags: List[re.Match] = []
orphan_tags: List[re.Match] = []

for match in re.finditer(
re.compile(
r"<(/?(\w+))\s*(" + config.attribute_pattern + r"|\s*)*\s*?>",
Expand All @@ -46,9 +48,9 @@ def run(
break
else:
# there was no open tag matching the close tag
open_tags.insert(0, match)
orphan_tags.append(match)

Check warning on line 51 in src/djlint/rules/H025.py

View check run for this annotation

Codecov / codecov/patch

src/djlint/rules/H025.py#L51

Added line #L51 was not covered by tests

for match in open_tags:
for match in open_tags + orphan_tags:
if (
overlaps_ignored_block(config, html, match) is False
and inside_ignored_rule(config, html, match, rule["name"]) is False
Expand Down
12 changes: 12 additions & 0 deletions tests/test_linter/test_linter.py
Expand Up @@ -390,6 +390,18 @@ def test_H025(runner: CliRunner, tmp_file: TextIO) -> None:
)
assert "H025" not in result.output

write_to_file(tmp_file.name, b"</p></p>")
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "H025 1:0" in result.output
assert "H025 1:4" in result.output

write_to_file(tmp_file.name, b"</p><p></p></p>")
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "H025 1:0" in result.output
assert "H025 1:11" in result.output


def test_T027(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<a href=\"{{- blah 'asdf' }}\">")
Expand Down

0 comments on commit cf52faf

Please sign in to comment.