From cf52faf1887e54d55ae02dff6d937c9205f5e533 Mon Sep 17 00:00:00 2001 From: Mark Gregson Date: Mon, 13 Nov 2023 12:11:51 +1000 Subject: [PATCH] fix(linter): fix missed H025 for double closing Closes #786 --- src/djlint/rules/H025.py | 6 ++++-- tests/test_linter/test_linter.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/djlint/rules/H025.py b/src/djlint/rules/H025.py index f22db77e..33451e8b 100644 --- a/src/djlint/rules/H025.py +++ b/src/djlint/rules/H025.py @@ -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*?>", @@ -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) - 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 diff --git a/tests/test_linter/test_linter.py b/tests/test_linter/test_linter.py index 39f30287..9d7f0f69 100644 --- a/tests/test_linter/test_linter.py +++ b/tests/test_linter/test_linter.py @@ -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"

") + 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"

") + 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"")