mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-27 08:24:46 +00:00
fixes #140, added test.
This commit is contained in:
parent
85284228a2
commit
9296dfaceb
4 changed files with 21 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -683,6 +683,11 @@ class Config:
|
|||
| br
|
||||
| input
|
||||
| hr
|
||||
| area
|
||||
| col
|
||||
| embed
|
||||
| track
|
||||
| wbr
|
||||
"""
|
||||
|
||||
self.optional_single_line_template_tags: str = r"""
|
||||
|
|
|
|||
|
|
@ -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="" >')
|
||||
|
|
|
|||
Loading…
Reference in a new issue