diff --git a/src/djlint/formatter/indent_html.py b/src/djlint/formatter/indent_html.py index edab227..a6bcf32 100644 --- a/src/djlint/formatter/indent_html.py +++ b/src/djlint/formatter/indent_html.py @@ -27,7 +27,7 @@ def indent_html(rawcode: str, config: Config) -> str: slt_html = config.indent_html_tags # here using all tags cause we allow empty tags on one line - always_slt_html = config.always_single_line_html_tags + always_self_closing_html = config.always_self_closing_html_tags # here using all tags cause we allow empty tags on one line slt_template = config.single_line_template_tags @@ -65,7 +65,7 @@ def indent_html(rawcode: str, config: Config) -> str: fr"(<({slt_html})[ ].*?/>)", item, flags=re.IGNORECASE | re.VERBOSE ) or re.findall( - fr"(<({always_slt_html})[ ].*?/?>)", + fr"(<({always_self_closing_html})[ ].*?/?>)", item, flags=re.IGNORECASE | re.VERBOSE, ) diff --git a/src/djlint/lint.py b/src/djlint/lint.py index ccce438..3d3e20f 100644 --- a/src/djlint/lint.py +++ b/src/djlint/lint.py @@ -80,7 +80,13 @@ def lint_file(config: Config, this_file: Path) -> Dict: ), html, ): - if match.group(1): + + if match.group(1) and not re.match( + re.compile( + fr"^/?{config.always_self_closing_html_tags}", re.I | re.X + ), + match.group(1).split(" ")[0], + ): # close tags should equal open tags if match.group(1).split(" ")[0][0] != "/": open_tags.append(match) diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 922c031..83cf163 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -568,11 +568,12 @@ class Config: | style """ - self.always_single_line_html_tags: str = r""" + self.always_self_closing_html_tags: str = r""" link | img | meta | source + | br """ self.single_line_template_tags: str = r""" diff --git a/tests/test_linter.py b/tests/test_linter.py index 5634602..64b8644 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -336,6 +336,10 @@ def test_H025(runner: CliRunner, tmp_file: TextIO) -> None: assert result.exit_code == 0 assert "H025" not in result.output + write_to_file(tmp_file.name, b"
") + result = runner.invoke(djlint, [tmp_file.name]) + assert "H025" not in result.output + def test_rules_not_matched_in_ignored_block( runner: CliRunner, tmp_file: TextIO