mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-05 04:14:51 +00:00
parent
c709efd658
commit
f38328c829
4 changed files with 14 additions and 5 deletions
|
|
@ -112,7 +112,6 @@ def lint_file(config: Config, this_file: Path) -> Dict:
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
for match in re.finditer(
|
for match in re.finditer(
|
||||||
re.compile(
|
re.compile(
|
||||||
pattern, flags=build_flags(rule.get("flags", "re.DOTALL"))
|
pattern, flags=build_flags(rule.get("flags", "re.DOTALL"))
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,15 @@
|
||||||
- '{%-[^\s]+'
|
- '{%-[^\s]+'
|
||||||
- '{%[^\s|\-]+'
|
- '{%[^\s|\-]+'
|
||||||
# handlebars
|
# handlebars
|
||||||
- '[^{]{#[^\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,}'
|
- '{[{|%|#]-?\s{2,}'
|
||||||
- rule:
|
- rule:
|
||||||
name: T002
|
name: T002
|
||||||
message: Double quotes should be used in tags.
|
message: Double quotes should be used in tags.
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,7 @@ class Config:
|
||||||
| {\#\s*djlint\:\s*off\s*\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
|
| {\#\s*djlint\:\s*off\s*\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
|
||||||
| {%\s*comment\s*%\}\s*djlint\:off\s*\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s*djlint\:on\s*\{%\s*endcomment\s*%\})
|
| {%\s*comment\s*%\}\s*djlint\:off\s*\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s*djlint\:on\s*\{%\s*endcomment\s*%\})
|
||||||
# inline jinja comments
|
# inline jinja comments
|
||||||
| {\#(?!\s*djlint\:\s*(?:off|on)).*?\#}
|
# | {\#(?!\s*djlint\:\s*(?:off|on)).*?\#}
|
||||||
# handlebars
|
# handlebars
|
||||||
| {{!--\s*djlint\:off\s*--}}.*?(?={{!--\s*djlint\:on\s*--}})
|
| {{!--\s*djlint\:off\s*--}}.*?(?={{!--\s*djlint\:on\s*--}})
|
||||||
# golang
|
# golang
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ run::
|
||||||
|
|
||||||
# for a single test
|
# for a single test
|
||||||
|
|
||||||
pytest tests/test_linter/test_linter.py::test_DJ018
|
pytest tests/test_linter/test_linter.py::test_T001
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# pylint: disable=C0116,C0103
|
# pylint: disable=C0116,C0103
|
||||||
|
|
@ -41,6 +41,15 @@ def test_T001(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "nunjucks"])
|
result = runner.invoke(djlint, [tmp_file.name, "--profile", "nunjucks"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
# this test will pass, because the jinja comment is an ignored block
|
||||||
|
write_to_file(tmp_file.name, b"{#-test -#}")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
write_to_file(tmp_file.name, b"{#- test -#}")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
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' %}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue