diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 226fe5f8..f949d17a 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -180,8 +180,8 @@ message: Empty id and class tags can be removed. flags: re.I patterns: - - <\w+\b[^(?:{(?:%|{|#))>]*?\b(class|id)\b=(\"\"|'') - - <\w+\b[^(?:{(?:%|{|#))>-]*?\b(class|id)\b[^=\"-] + - <\w+\b[^(?:{(?:%|{|#))>]*?\s(class|id)\b=(\"\"|'') + - <\w+\b[^(?:{(?:%|{|#))>-]*?\s(class|id)\b[^=\"-] - rule: name: T027 message: Unclosed string found in template syntax. diff --git a/tests/test_linter/test_h026.py b/tests/test_linter/test_h026.py new file mode 100644 index 00000000..a46893ba --- /dev/null +++ b/tests/test_linter/test_h026.py @@ -0,0 +1,102 @@ +"""Test linter code H026. + +poetry run pytest tests/test_linter/test_h026.py +""" +import pytest + +from src.djlint.lint import linter +from tests.conftest import lint_printer + +test_data = [ + pytest.param( + (''), + ( + [ + { + "code": "H025", + "line": "1:0", + "match": '', + "message": "Tag seems to be an orphan.", + }, + { + "code": "H026", + "line": "1:0", + "match": '"), + ( + [ + { + "code": "H025", + "line": "1:0", + "match": "", + "message": "Tag seems to be an orphan.", + }, + { + "code": "H026", + "line": "1:0", + "match": "'), + ( + [ + { + "code": "H025", + "line": "1:0", + "match": '', + "message": "Tag seems to be an orphan.", + }, + { + "code": "H026", + "line": "1:0", + "match": ''), + ([]), + id="class in tag", + ), + pytest.param( + ("
"), + ([]), + id="prefix and suffix", + ), + pytest.param( + ( + '
' + ), + ([]), + id="prefix and suffix quoted", + ), +] + + +@pytest.mark.parametrize(("source", "expected"), test_data) +def test_base(source, expected, basic_config): + filename = "test.html" + output = linter(basic_config, source, filename, filename) + + lint_printer(source, expected, output[filename]) + + mismatch = list(filter(lambda x: x not in expected, output[filename])) + list( + filter(lambda x: x not in output[filename], expected) + ) + + assert len(mismatch) == 0 diff --git a/tests/test_linter/test_linter.py b/tests/test_linter/test_linter.py index d2c72ccb..a9c6ce92 100644 --- a/tests/test_linter/test_linter.py +++ b/tests/test_linter/test_linter.py @@ -391,32 +391,6 @@ def test_H025(runner: CliRunner, tmp_file: TextIO) -> None: assert "H025" not in result.output -def test_H026(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file(tmp_file.name, b'') - result = runner.invoke(djlint, [tmp_file.name]) - 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 == 1 - assert "H026" in result.output - - write_to_file(tmp_file.name, b'') - result = runner.invoke(djlint, [tmp_file.name]) - 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 - - write_to_file(tmp_file.name, b"
") - result = runner.invoke(djlint, [tmp_file.name]) - assert "H026" not in result.output - - def test_T027(runner: CliRunner, tmp_file: TextIO) -> None: write_to_file(tmp_file.name, b"") result = runner.invoke(djlint, [tmp_file.name])