diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 42a868b..908b63c 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -190,4 +190,5 @@ message: Emtpy id and class tags can be removed. flags: re.I patterns: - - <(?:\w+)(?:\s(?:(?:{%[^(?:%})]*?%})|(?:{{[^(?:}})]*?}})|[^<>])*)(id|class)(?:(?:=(?:\"{2})|(?:'{2}))|\s) + - <\w+\b[^(?:{(?:%|{|#))>]*?\b(class|id)\b=(\"\"|'') + - <\w+\b[^(?:{(?:%|{|#))>]*?\b(class|id)\b[^=] diff --git a/tests/test_linter.py b/tests/test_linter.py index 522db30..fa4aaa5 100644 --- a/tests/test_linter.py +++ b/tests/test_linter.py @@ -7,7 +7,7 @@ run:: # for a single test - pytest tests/test_linter.py::test_H025 --cov=src/djlint --cov-branch \ + pytest tests/test_linter.py::test_H026 --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing """ @@ -396,6 +396,11 @@ def test_H026(runner: CliRunner, tmp_file: TextIO) -> None: assert result.exit_code == 1 assert "H026" in result.output + write_to_file(tmp_file.name, b'') + result = runner.invoke(djlint, [tmp_file.name]) + assert result.exit_code == 0 + assert "H026" not in result.output + def test_rules_not_matched_in_ignored_block( runner: CliRunner, tmp_file: TextIO