mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-17 17:41:06 +00:00
Merge pull request #352 from Riverside-Healthcare/dev
This commit is contained in:
commit
7e6d64bab8
3 changed files with 64 additions and 9 deletions
|
|
@ -148,8 +148,14 @@ def inside_ignored_rule(config: Config, html: str, match: re.Match, rule: str) -
|
|||
):
|
||||
if (
|
||||
rule in list(set(re.split(r"\s|,", ignored_match.group(1).strip())))
|
||||
and ignored_match.start(0) <= match.start()
|
||||
and match.end(0) <= ignored_match.end()
|
||||
and (
|
||||
ignored_match.start(0) <= match.start()
|
||||
and match.start() <= ignored_match.end()
|
||||
)
|
||||
or (
|
||||
ignored_match.start(0) <= match.end()
|
||||
and match.end() <= ignored_match.end()
|
||||
)
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@
|
|||
# close
|
||||
- '[^(\s|^|\-)]+[}|%|#]}'
|
||||
- '[^(\s|^)]+\-[}|%|#]}'
|
||||
- \s{2,}[}|%|#]}
|
||||
- '{[{|%|#]-?\s{2,}'
|
||||
- '[^\s][ ]{2,}[}|%|#]}'
|
||||
- '{[{|%|#]-?[ ]{2,}'
|
||||
- rule:
|
||||
name: T002
|
||||
message: Double quotes should be used in tags.
|
||||
flags: re.DOTALL
|
||||
patterns:
|
||||
- '{%.?extends\s+?[^\"]\w+'
|
||||
- "{%[ \t]*?extends[ \t]+?'[^']*'"
|
||||
- rule:
|
||||
name: T003
|
||||
message: 'Endblock should have name. Ex: {% endblock body %}.'
|
||||
|
|
@ -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.
|
||||
|
|
@ -161,7 +161,7 @@
|
|||
message: Inline styles should be avoided.
|
||||
flags: re.I
|
||||
patterns:
|
||||
- <\w+\s(?:[^>]*\s)?style=(?=[^>]*>)
|
||||
- <\w+\s(?:[^>]*\s)?style=(?=((?!>|{{|{%).)*>)
|
||||
- rule:
|
||||
name: H022
|
||||
message: Use HTTPS for external links.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
# for a single test
|
||||
|
||||
pytest tests/test_linter/test_linter.py::test_T001
|
||||
pytest tests/test_linter/test_linter.py::test_ignoring_rules
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116,C0103
|
||||
|
|
@ -50,6 +50,18 @@ def test_T001(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
# test line break around tag
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>
|
||||
{%
|
||||
("SashaNose", "1"),
|
||||
%}
|
||||
</div>""",
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||
assert "T001" not in result.output
|
||||
|
||||
|
||||
def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"{% extends 'this' %}")
|
||||
|
|
@ -57,6 +69,11 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
assert result.exit_code == 1
|
||||
assert "T002 1:" in result.output
|
||||
|
||||
# allow variable names (unquoted)
|
||||
write_to_file(tmp_file.name, b"{% extends this %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert "T002" not in result.output
|
||||
|
||||
|
||||
def test_T003(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"{% endblock %}")
|
||||
|
|
@ -202,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"/>')
|
||||
|
|
@ -393,6 +420,11 @@ def test_H021(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
assert result.exit_code == 0
|
||||
assert "H021" not in result.output
|
||||
|
||||
# allow template syntax inside styles
|
||||
write_to_file(tmp_file.name, b'<div style="test {%"><div style="test {{">')
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "H021" not in result.output
|
||||
|
||||
|
||||
def test_H022(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b'<a href="http://">')
|
||||
|
|
@ -865,3 +897,20 @@ def test_ignoring_rules(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "H025" not in result.output
|
||||
|
||||
# using tabs
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>
|
||||
|
||||
\t\t{# djlint:off H006 #}
|
||||
|
||||
\t\t<img src="{{ kira_variable }}.webp" alt="Kira Goddess!" />
|
||||
|
||||
\t\t{# djlint:on #}
|
||||
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "H006" not in result.output
|
||||
|
|
|
|||
Loading…
Reference in a new issue