Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missed H025 for double closing HTML tags #788

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/djlint/rules/H025.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"""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 @@
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
Original file line number Diff line number Diff line change
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