mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-16 09:03:09 +00:00
updated rule H025 logic to ignore single line tags. added test. closes #73
This commit is contained in:
parent
adbef74d38
commit
dde4ad4a1e
4 changed files with 15 additions and 4 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
|
|
@ -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"<br>")
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue