feat(linter t034): added linter T034 to check for {% ... }% typo

closes #385
This commit is contained in:
Christopher Pickering 2022-09-16 09:54:17 +02:00
parent 4ac5fd0da8
commit ecb95bbee0
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
6 changed files with 23 additions and 4 deletions

View file

@ -76,6 +76,7 @@ A good rule follows this pattern:
| H031 | Consider adding meta keywords. |
| T032 | Extra whitespace found in template tags. |
| H033 | Extra whitespace found in form action. |
| T034 | Did you intend to use {% ... %} instead of {% ... }%? |
### Adding Rules

View file

@ -76,6 +76,7 @@ Une bonne règle suit ce modèle :
| H031 | Pensez à ajouter des méta keywords. |
| T032 | Espace blanc supplémentaire trouvé dans les balises du modèle. |
| H033 | Espace supplémentaire dans l'action du formulaire. |
| T034 | Aviez-vous l'intention d'utiliser {% ... %} au lieu de {% ... }% ? |
### Ajout de règles

View file

@ -76,6 +76,7 @@ djlint /path/to/this.html.j2 --profile=jinja
| H031 | Рассмотрите возможность добавления мета-ключевых слов. |
| T032 | В тегах шаблона обнаружены лишние пробелы. |
| H033 | В действии формы обнаружен лишний пробел. |
| T034 | Вы намеревались использовать {% ... %} вместо {% ... }%? |
### Добавление правил

View file

@ -18,7 +18,7 @@ iniconfig==1.1.1; python_version >= "3.7"
isort==5.10.1; python_full_version >= "3.6.1" and python_version < "4.0"
jsbeautifier==1.14.6
lazy-object-proxy==1.7.1; python_version >= "3.6" and python_full_version >= "3.7.2"
mccabe==0.7.0; python_full_version >= "3.7.2" and python_version >= "3.7"
mccabe==0.6.1; python_full_version >= "3.7.2" and python_version >= "3.7"
mypy-extensions==0.4.3; python_full_version >= "3.6.2" and python_version >= "3.6"
mypy==0.971; python_version >= "3.6"
packaging==21.3; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
@ -27,8 +27,8 @@ pep8-naming==0.13.2; python_version >= "3.7"
platformdirs==2.5.2; python_version >= "3.7" and python_full_version >= "3.7.2" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7")
pluggy==1.0.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
py==1.11.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
pycodestyle==2.9.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
pyflakes==2.5.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
pycodestyle==2.7.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
pyflakes==2.3.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
pylint==2.15.2; python_full_version >= "3.7.2"
pyparsing==3.0.9; python_full_version >= "3.6.8" and python_version >= "3.7"
pytest-cov==3.0.0; python_version >= "3.6"

View file

@ -251,3 +251,9 @@
patterns:
- <form[^>]+?action=['|"]\s
- <form[^>]+?action=(['|"])({{(?:(?!}}).)*}}|{%(?:(?!%}).)*%}|([^"'{]))*\s+?\1
- rule:
name: T034
message: Did you intend to use {% ... %} instead of {% ... }%?
flags: re.DOTALL
patterns:
- '{%(?:(?!%}).)*}%'

View file

@ -7,7 +7,7 @@ run::
# for a single test
pytest tests/test_linter/test_linter.py::test_ignoring_rules
pytest tests/test_linter/test_linter.py::test_T034
"""
# pylint: disable=C0116,C0103
@ -837,6 +837,16 @@ def test_H033(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H033" in result.output
def test_T034(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"{% not ok }%")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert "T034" in result.output
write_to_file(tmp_file.name, b"{% not ok \n%}")
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert "T034" not in result.output
def test_rules_not_matched_in_ignored_block(
runner: CliRunner, tmp_file: TextIO
) -> None: