mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-17 05:50:24 +00:00
feat(linter t034): added linter T034 to check for {% ... }% typo
closes #385
This commit is contained in:
parent
4ac5fd0da8
commit
ecb95bbee0
6 changed files with 23 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ djlint /path/to/this.html.j2 --profile=jinja
|
|||
| H031 | Рассмотрите возможность добавления мета-ключевых слов. |
|
||||
| T032 | В тегах шаблона обнаружены лишние пробелы. |
|
||||
| H033 | В действии формы обнаружен лишний пробел. |
|
||||
| T034 | Вы намеревались использовать {% ... %} вместо {% ... }%? |
|
||||
|
||||
### Добавление правил
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
- '{%(?:(?!%}).)*}%'
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue