fix(h012): prevent H012 from matching the contents of tags or attributes

closes #348
This commit is contained in:
Christopher Pickering 2022-08-24 09:01:13 -05:00
parent a5d96e7a2d
commit 4480cff832
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 12 additions and 2 deletions

View file

@ -96,8 +96,8 @@
message: There should be no spaces around attribute =.
flags: re.DOTALL
patterns:
- <\w+?(?:(?!\{[%|{|#])[^\n|>])*\s+=
- <\w+?(?:(?!\{[%|{|#])[^\n|>])*=\s
- <\w+?(\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}])*\s+=
- <\w+?(\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}])*=\s
- rule:
name: H013
message: Img tag should have an alt attribute.

View file

@ -219,6 +219,16 @@ def test_H012(runner: CliRunner, tmp_file: TextIO) -> None:
assert result.exit_code == 0
assert "H012 1:" not in result.output
# space allowed inside attributes.
write_to_file(
tmp_file.name,
b"""<button x-on:click="myVariable = {{ myObj.id }}" class="text-red-600 hover:text-red-800">
<span x-text="showSource == true ? 'Hide source' : 'Show source'"></span>
<button x-on:click="open = !open" class="flex items-center mt-2">""",
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H012" not in result.output
def test_H013(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b'<img height="12" width="12"/>')