fixes #140, added test.

This commit is contained in:
Christopher Pickering 2021-11-22 15:21:18 +01:00
parent 85284228a2
commit 9296dfaceb
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 21 additions and 7 deletions

View file

@ -69,20 +69,20 @@ def lint_file(config: Config, this_file: Path) -> Dict:
),
html,
):
if match.group(1) and not re.match(
if match.group(2) and not re.search(
re.compile(
fr"^/?{config.always_self_closing_html_tags}", re.I | re.X
fr"^/?{config.always_self_closing_html_tags}\b", re.I | re.X
),
re.split(r"\s+", match.group(1))[0],
match.group(2),
):
# close tags should equal open tags
if re.split(r"\s+", match.group(1))[0][0] != "/":
if match.group(2)[0] != "/":
open_tags.insert(0, match)
else:
for i, tag in enumerate(copy.deepcopy(open_tags)):
if (
re.split(r"\s+", tag.group(1))[0]
== re.split(r"\s+", match.group(1))[0][1:]
== match.group(2)[1:]
):
open_tags.pop(i)
break

View file

@ -184,7 +184,7 @@
message: Tag seems to be an orphan.
flags: re.I|re.DOTALL
patterns:
- <(/?(?:\w+)\b(\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*)>
- <((/?\w+)\b(\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*)>
- rule:
name: H026
message: Emtpy id and class tags can be removed.

View file

@ -683,6 +683,11 @@ class Config:
| br
| input
| hr
| area
| col
| embed
| track
| wbr
"""
self.optional_single_line_template_tags: str = r"""

View file

@ -7,7 +7,7 @@ run::
# for a single test
pytest tests/test_linter.py::test_T028 --cov=src/djlint --cov-branch \
pytest tests/test_linter.py::test_H017 --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
"""
@ -214,6 +214,7 @@ def test_H017(runner: CliRunner, tmp_file: TextIO) -> None:
# test colgroup tag
write_to_file(tmp_file.name, b"<colgroup><colgroup asdf></colgroup></colgroup>")
result = runner.invoke(djlint, [tmp_file.name])
print(result.output)
assert result.exit_code == 0
assert "H017 1:" not in result.output
@ -410,6 +411,14 @@ def test_H025(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name])
assert "H025" not in result.output
write_to_file(tmp_file.name, b"<col>")
result = runner.invoke(djlint, [tmp_file.name])
assert "H025" not in result.output
write_to_file(tmp_file.name, b"<col />")
result = runner.invoke(djlint, [tmp_file.name])
assert "H025" not in result.output
def test_H026(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b'<asdf id="" >')