mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-09 06:14:42 +00:00
fix(t001): fixed false positive on T001 with Jinja {{- and {{+ tags
closes #354
This commit is contained in:
parent
215bd23190
commit
c57e9444a1
2 changed files with 23 additions and 17 deletions
|
|
@ -7,19 +7,20 @@
|
||||||
- golang
|
- golang
|
||||||
patterns:
|
patterns:
|
||||||
# open
|
# open
|
||||||
- '{{[^\s#/@^]+'
|
- '{{[^\s#/@^\-\+]+'
|
||||||
- '{%-[^\s]+'
|
- '{%[\-\+][^\s]+'
|
||||||
- '{%[^\s|\-]+'
|
- '{%[^\s|\-|\+]+'
|
||||||
# handlebars
|
# handlebars
|
||||||
- '[^{]{#[^\s-]+|^{#[^\s-]+'
|
- '[^{]{#[^\s-]+|^{#[^\s-]+'
|
||||||
- '[^{]{#-[^\s]+|^{#-[^\s]+'
|
- '[^{]{#-[^\s]+|^{#-[^\s]+'
|
||||||
- '[^{]{\/[^\s]+|^{\/[^\s]+'
|
- '[^{]{\/[^\s]+|^{\/[^\s]+'
|
||||||
- '[^{]{\@[^\s]+|^{\@[^\s]+'
|
- '[^{]{\@[^\s]+|^{\@[^\s]+'
|
||||||
# close
|
# close
|
||||||
- '[^(\s|^|\-)]+[}|%|#]}'
|
- '[^(\s|^|\-|\+)]+[}|%|#]}'
|
||||||
- '[^(\s|^)]+\-[}|%|#]}'
|
- '[^(\s|^)]+\-[}|%|#]}'
|
||||||
- '[^\s][ ]{2,}[}|%|#]}'
|
- '[^(\s|^)]+\+[}|%|#]}'
|
||||||
- '{[{|%|#]-?[ ]{2,}'
|
- '[^\s\-\+][ ]{2,}[}|%|#]}'
|
||||||
|
- '{[{|%|#]\-?\+?[ ]{2,}'
|
||||||
- rule:
|
- rule:
|
||||||
name: T002
|
name: T002
|
||||||
message: Double quotes should be used in tags.
|
message: Double quotes should be used in tags.
|
||||||
|
|
|
||||||
|
|
@ -55,13 +55,18 @@ def test_T001(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
tmp_file.name,
|
tmp_file.name,
|
||||||
b"""<div>
|
b"""<div>
|
||||||
{%
|
{%
|
||||||
("SashaNose", "1"),
|
("something", "1"),
|
||||||
%}
|
%}
|
||||||
</div>""",
|
</div>""",
|
||||||
)
|
)
|
||||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||||
assert "T001" not in result.output
|
assert "T001" not in result.output
|
||||||
|
|
||||||
|
# allow jinja spaceless tags
|
||||||
|
write_to_file(tmp_file.name, b"{{- foo }}{{+ bar }}{{ biz -}}{{ baz +}}")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||||
|
assert "T001" not in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
write_to_file(tmp_file.name, b"{% extends 'this' %}")
|
write_to_file(tmp_file.name, b"{% extends 'this' %}")
|
||||||
|
|
@ -114,7 +119,7 @@ def test_H006(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
b"""{# [INFO][JINJA] I use syntax "{% if <img alt=\""",
|
b"""{# [INFO][JINJA] I use syntax "{% if <img alt=\""",
|
||||||
if I want that something happened solely if "img" exists in the content of my articles #}
|
if I want that something happened solely if "img" exists in the content of my articles #}
|
||||||
|
|
||||||
<script src="KiraJS.js" defer></script>
|
<script src="script.js" defer></script>
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
result = runner.invoke(djlint, [tmp_file.name])
|
result = runner.invoke(djlint, [tmp_file.name])
|
||||||
|
|
@ -136,7 +141,7 @@ def test_H008(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
write_to_file(
|
write_to_file(
|
||||||
tmp_file.name,
|
tmp_file.name,
|
||||||
b"""<link rel="stylesheet" href="KiraCSS.css" media="print" onload="this.media='all'" media=''/>""",
|
b"""<link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'" media=''/>""",
|
||||||
)
|
)
|
||||||
result = runner.invoke(djlint, [tmp_file.name])
|
result = runner.invoke(djlint, [tmp_file.name])
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
|
|
@ -144,7 +149,7 @@ def test_H008(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
write_to_file(
|
write_to_file(
|
||||||
tmp_file.name,
|
tmp_file.name,
|
||||||
b"""<link rel="stylesheet" href="KiraCSS.css" media="print" onload="this.media='all'"/>""",
|
b"""<link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'"/>""",
|
||||||
)
|
)
|
||||||
result = runner.invoke(djlint, [tmp_file.name])
|
result = runner.invoke(djlint, [tmp_file.name])
|
||||||
assert "H008 1:" not in result.output
|
assert "H008 1:" not in result.output
|
||||||
|
|
@ -777,15 +782,15 @@ def test_T032(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
write_to_file(
|
write_to_file(
|
||||||
tmp_file.name,
|
tmp_file.name,
|
||||||
b"""{# [INFO] Simple example #}
|
b"""{# [INFO] Simple example #}
|
||||||
{% set kira = [
|
{% set stuff = [
|
||||||
'Goddess', 'Genius'
|
'value', 'value'
|
||||||
] %}
|
] %}
|
||||||
|
|
||||||
{# [INFO] Real example #}
|
{# [INFO] Real example #}
|
||||||
{% set kira_online_scaners = [
|
{% set online_scaners = [
|
||||||
('https://quttera.com/sitescan/', 'SashaButtonLightSkyBlue', 'Quttera'),
|
('https://example.com', 'blue', 'One'),
|
||||||
('https://sitecheck.sucuri.net/results/', 'SashaButtonLimeGreen', 'Sucuri'),
|
('https://example.com', 'green', 'Two'),
|
||||||
('https://www.isithacked.com/check/', 'SashaButtonPlum', 'Is It Hacked?'),
|
('https://example.com', 'plum', 'Three'),
|
||||||
] %}
|
] %}
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
@ -905,7 +910,7 @@ def test_ignoring_rules(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
\t\t{# djlint:off H006 #}
|
\t\t{# djlint:off H006 #}
|
||||||
|
|
||||||
\t\t<img src="{{ kira_variable }}.webp" alt="Kira Goddess!" />
|
\t\t<img src="{{ variable }}.webp" alt="stuff" />
|
||||||
|
|
||||||
\t\t{# djlint:on #}
|
\t\t{# djlint:on #}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue