mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-03 19:34:43 +00:00
Merge pull request #390 from Riverside-Healthcare/dev
This commit is contained in:
commit
00636ce7c7
12 changed files with 169 additions and 164 deletions
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
|
@ -15,7 +15,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
python-version: [3.7, 3.8, 3.9, '3.10']
|
||||
python-version: [3.7, 3.8, 3.9, '3.10', 3.11-dev]
|
||||
fail-fast: true
|
||||
|
||||
steps:
|
||||
|
|
@ -45,7 +45,7 @@ jobs:
|
|||
# remove windows-latest, half tests seem to randomly pass
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
python-version: [3.7, 3.8, 3.9, '3.10']
|
||||
python-version: [3.7, 3.8, 3.9, '3.10', 3.11-dev]
|
||||
node: [ 12, 14, 16 ]
|
||||
fail-fast: true
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,3 @@ repos:
|
|||
args: [--autofix]
|
||||
- id: pretty-format-yaml
|
||||
args: [--autofix, --indent, '2']
|
||||
repos:
|
||||
- repo: https://github.com/christopherpickering/pre-commit-hooks
|
||||
rev: 0.0.6
|
||||
hooks:
|
||||
- id: poetry-to-requirements
|
||||
args: [--output=requirements.txt]
|
||||
|
|
@ -37,15 +37,26 @@ A good rule follows this pattern:
|
|||
- Trichotillomania
|
||||
```
|
||||
|
||||
### Code Patterns
|
||||
|
||||
The first letter of a code follows the pattern:
|
||||
|
||||
::: content
|
||||
|
||||
- D: applies specifically to Django
|
||||
- H: applies to html
|
||||
- J: applies specifically to Jinja
|
||||
- M: applies specifically to Handlebars
|
||||
- N: applies specifically to Nunjucks
|
||||
- T: applies generally to templates
|
||||
:::
|
||||
|
||||
## Rules
|
||||
|
||||
| Code | Meaning |
|
||||
| ---- | -------------------------------------------------------------------------------------------- |
|
||||
| T001 | Variables should be wrapped in a single whitespace. Ex: {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | Double quotes should be used in tags. Ex {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Endblock should have name. Ex: {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| D004 | (Django) Static urls should follow {% raw %}`{% static path/to/file %}`{% endraw %} pattern. |
|
||||
| J004 | (Jinja) Static urls should follow {% raw %}`{{ url_for('static'..) }}`{% endraw %} pattern. |
|
||||
| D018 | (Django) Internal links should use the {% raw %}`{% url ... %}`{% endraw %} pattern. |
|
||||
| H005 | Html tag should have `lang` attribute. |
|
||||
| H006 | `img` tag should have `height` and `width` attributes. |
|
||||
| H007 | `<!DOCTYPE ... >` should be present before the html tag. |
|
||||
|
|
@ -59,8 +70,6 @@ A good rule follows this pattern:
|
|||
| H015 | Follow `h` tags with a line break. |
|
||||
| H016 | Missing `title` tag in html. |
|
||||
| H017 | Tag should be self closing. |
|
||||
| D018 | (Django) Internal links should use the {% raw %}`{% url ... %}`{% endraw %} pattern. |
|
||||
| J018 | (Jinja) Internal links should use the {% raw %}`{% url ... %}`{% endraw %} pattern. |
|
||||
| H019 | Replace `javascript:abc()` with `on_` event and real url. |
|
||||
| H020 | Empty tag pair found. Consider removing. |
|
||||
| H021 | Inline styles should be avoided. |
|
||||
|
|
@ -69,13 +78,19 @@ A good rule follows this pattern:
|
|||
| H024 | Omit type on scripts and styles. |
|
||||
| H025 | Tag seems to be an orphan. |
|
||||
| H026 | Empty id and class tags can be removed. |
|
||||
| T027 | Unclosed string found in template syntax. |
|
||||
| T028 | Consider using spaceless tags inside attribute values. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| H029 | Consider using lowercase form method values. |
|
||||
| H030 | Consider adding a meta description. |
|
||||
| H031 | Consider adding meta keywords. |
|
||||
| T032 | Extra whitespace found in template tags. |
|
||||
| H033 | Extra whitespace found in form action. |
|
||||
| J004 | (Jinja) Static urls should follow {% raw %}`{{ url_for('static'..) }}`{% endraw %} pattern. |
|
||||
| J018 | (Jinja) Internal links should use the {% raw %}`{% url ... %}`{% endraw %} pattern. |
|
||||
| T001 | Variables should be wrapped in a single whitespace. Ex: {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | Double quotes should be used in tags. Ex {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Endblock should have name. Ex: {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| T027 | Unclosed string found in template syntax. |
|
||||
| T028 | Consider using spaceless tags inside attribute values. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| T032 | Extra whitespace found in template tags. |
|
||||
| T034 | Did you intend to use {% raw %}{% ... %} instead of {% ... }%? {% endraw %} |
|
||||
|
||||
### Adding Rules
|
||||
|
||||
|
|
@ -94,17 +109,3 @@ A good rule consists of
|
|||
:::
|
||||
|
||||
Please include a test to validate the rule.
|
||||
|
||||
### Code Patterns
|
||||
|
||||
The first letter of a code follows the pattern:
|
||||
|
||||
::: content
|
||||
|
||||
- T: applies generally to templates
|
||||
- H: applies to html
|
||||
- D: applies specifically to Django
|
||||
- J: applies specifically to Jinja
|
||||
- N: applies specifically to Nunjucks
|
||||
- M: applies specifically to Handlebars
|
||||
:::
|
||||
|
|
|
|||
|
|
@ -37,15 +37,26 @@ Une bonne règle suit ce modèle :
|
|||
- Trichotillomanie
|
||||
```
|
||||
|
||||
### Modèles de code
|
||||
|
||||
La première lettre d'un code suit le modèle :
|
||||
|
||||
::: content
|
||||
|
||||
- D : s'applique spécifiquement à Django
|
||||
- H : s'applique au html
|
||||
- J : s'applique spécifiquement à Jinja
|
||||
- M : s'applique spécifiquement à Handlebars
|
||||
- N : s'applique spécifiquement à Nunjucks
|
||||
- T : s'applique généralement aux modèles
|
||||
:::
|
||||
|
||||
## Rules
|
||||
|
||||
| Code | Signification |
|
||||
| ---- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| T001 | Les variables doivent être entourées d'un seul espace. Ex : {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | Les doubles quotes doivent être utilisées dans les balises. Ex : {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Le bloc de fin doit avoir un nom. Ex : {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| D004 | (Django) Les urls statiques doivent suivre le modèle {% raw %}`{% static path/to/file %}`{% endraw %}. |
|
||||
| J004 | (Jinja) Les urls statiques doivent suivre le modèle {% raw %}`{ url_for('static'..) }}`{% endraw %}. |
|
||||
| D018 | (Django) Les liens internes doivent utiliser le modèle {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| H005 | La balise Html doit avoir l'attribut `lang`. |
|
||||
| H006 | La balise `img` doit avoir les attributs `height` et `width`. |
|
||||
| H007 | LA BALISE `<!DOCTYPE ... >` doit être présent avant la balise html. |
|
||||
|
|
@ -59,8 +70,6 @@ Une bonne règle suit ce modèle :
|
|||
| H015 | Les balises "h" doivent être suivies d'un retour à la ligne. |
|
||||
| H016 | Balise `title` manquante dans le html. |
|
||||
| H017 | La balise doit se fermer automatiquement. |
|
||||
| D018 | (Django) Les liens internes doivent utiliser le modèle {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| J018 | (Jinja) Les liens internes doivent utiliser le modèle {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| H019 | Remplacez `javascript:abc()` par l'événement `on_` et l'url réelle. |
|
||||
| H020 | Couple de balises vide trouvé. Envisagez de le supprimer. |
|
||||
| H021 | Les styles en ligne doivent être évités. |
|
||||
|
|
@ -69,13 +78,19 @@ Une bonne règle suit ce modèle :
|
|||
| H024 | Omettre le type sur les scripts et les styles. |
|
||||
| H025 | La balise semble être orpheline. |
|
||||
| H026 | Les balises id et class vides peuvent être supprimées. |
|
||||
| T027 | Chaîne non fermée trouvée dans la syntaxe du modèle. |
|
||||
| T028 | Envisagez d'utiliser des balises sans espace à l'intérieur des valeurs d'attributs. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| H029 | Pensez à utiliser des valeurs de méthode de formulaire en minuscules. |
|
||||
| H030 | Pensez à ajouter une méta-description. |
|
||||
| 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. |
|
||||
| J004 | (Jinja) Les urls statiques doivent suivre le modèle {% raw %}`{ url_for('static'..) }}`{% endraw %}. |
|
||||
| J018 | (Jinja) Les liens internes doivent utiliser le modèle {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| T001 | Les variables doivent être entourées d'un seul espace. Ex : {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | Les doubles quotes doivent être utilisées dans les balises. Ex : {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Le bloc de fin doit avoir un nom. Ex : {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| T027 | Chaîne non fermée trouvée dans la syntaxe du modèle. |
|
||||
| T028 | Envisagez d'utiliser des balises sans espace à l'intérieur des valeurs d'attributs. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| T032 | Espace blanc supplémentaire trouvé dans les balises du modèle. |
|
||||
| T034 | Aviez-vous l'intention d'utiliser {% raw %}{% ... %} au lieu de {% ... }% ? {% endraw %} |
|
||||
|
||||
### Ajout de règles
|
||||
|
||||
|
|
@ -94,17 +109,3 @@ Une bonne règle consiste en
|
|||
:::
|
||||
|
||||
Veuillez inclure un test pour valider la règle.
|
||||
|
||||
### Modèles de code
|
||||
|
||||
La première lettre d'un code suit le modèle :
|
||||
|
||||
::: content
|
||||
|
||||
- T : s'applique généralement aux modèles
|
||||
- H : s'applique au html
|
||||
- D : s'applique spécifiquement à Django
|
||||
- J : s'applique spécifiquement à Jinja
|
||||
- N : s'applique spécifiquement à Nunjucks
|
||||
- M : s'applique spécifiquement à Handlebars
|
||||
:::
|
||||
|
|
|
|||
|
|
@ -37,15 +37,26 @@ djlint /path/to/this.html.j2 --profile=jinja
|
|||
- трихотилломанию
|
||||
```
|
||||
|
||||
### Кодовые шаблоны
|
||||
|
||||
Первая буква кода соответствует схеме:
|
||||
|
||||
::: content
|
||||
|
||||
- D: применяется специально для Django
|
||||
- H: применяется к html
|
||||
- J: применяется специально для Jinja
|
||||
- M: применяется специально для Handlebars
|
||||
- N: применяется специально для Nunjucks
|
||||
- T: применяется в целом к шаблонам
|
||||
:::
|
||||
|
||||
## Правила
|
||||
|
||||
| Код | Значение |
|
||||
| ---- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| T001 | Переменные должны быть заключены в один пробел. Например: {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | В тегах следует использовать двойные кавычки. Ex {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Конечный блок должен иметь имя. Например: {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| D004 | (Django) Статические урлы должны следовать шаблону {% raw %}`{% static path/to/file %}`{% endraw %}. |
|
||||
| J004 | (Jinja) Статические урлы должны следовать шаблону {% raw %}`{{ url_for('static'...)}}`{% endraw %}. |
|
||||
| D018 | (Django) Внутренние ссылки должны использовать шаблон {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| H005 | Html-тег должен иметь атрибут `lang`. |
|
||||
| H006 | Тег `img` должен иметь атрибуты `height` и `width`. |
|
||||
| H007 | `<!DOCTYPE ... >` должен присутствовать перед тегом html. |
|
||||
|
|
@ -59,8 +70,6 @@ djlint /path/to/this.html.j2 --profile=jinja
|
|||
| H015 | После тегов `h` следует перевод строки. |
|
||||
| H016 | Отсутствие тега `title` в html. |
|
||||
| H017 | Тег должен быть самозакрывающимся. |
|
||||
| D018 | (Django) Внутренние ссылки должны использовать шаблон {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| J018 | (Jinja) Внутренние ссылки должны использовать шаблон {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| H019 | Замените `javascript:abc()` на событие `on_` и реальный url. |
|
||||
| H020 | Найдена пустая пара тегов. Рассмотрите возможность удаления. |
|
||||
| H021 | Следует избегать инлайн-стилей. |
|
||||
|
|
@ -69,13 +78,19 @@ djlint /path/to/this.html.j2 --profile=jinja
|
|||
| H024 | Опускайте тип в скриптах и стилях. |
|
||||
| H025 | Тег кажется бесхозным. |
|
||||
| H026 | Пустые теги id и class могут быть удалены. |
|
||||
| T027 | В синтаксисе шаблона найдена незакрытая строка. |
|
||||
| T028 | Рассмотрите возможность использования тегов без пробелов внутри значений атрибутов. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| H029 | Рассмотрите возможность использования строчных значений метода формы. |
|
||||
| H030 | Рассмотрите возможность добавления мета-описания. |
|
||||
| H031 | Рассмотрите возможность добавления мета-ключевых слов. |
|
||||
| T032 | В тегах шаблона обнаружены лишние пробелы. |
|
||||
| H033 | В действии формы обнаружен лишний пробел. |
|
||||
| J004 | (Jinja) Статические урлы должны следовать шаблону {% raw %}`{{ url_for('static'...)}}`{% endraw %}. |
|
||||
| J018 | (Jinja) Внутренние ссылки должны использовать шаблон {% raw %}`{% url ... %}`{% endraw %}. |
|
||||
| T001 | Переменные должны быть заключены в один пробел. Например: {% raw %}`{{ this }}`{% endraw %} |
|
||||
| T002 | В тегах следует использовать двойные кавычки. Ex {% raw %}`{% extends "this.html" %}`{% endraw %} |
|
||||
| T003 | Конечный блок должен иметь имя. Например: {% raw %}`{% endblock body %}`{% endraw %}. |
|
||||
| T027 | В синтаксисе шаблона найдена незакрытая строка. |
|
||||
| T028 | Рассмотрите возможность использования тегов без пробелов внутри значений атрибутов. {% raw %}`{%- if/for -%}`{% endraw %} |
|
||||
| T032 | В тегах шаблона обнаружены лишние пробелы. |
|
||||
| T034 | Вы намеревались использовать {% raw %}{% ... %} вместо {% ... }%? {% endraw %} |
|
||||
|
||||
### Добавление правил
|
||||
|
||||
|
|
@ -94,17 +109,3 @@ djlint /path/to/this.html.j2 --profile=jinja
|
|||
:::
|
||||
|
||||
Пожалуйста, включите тест для проверки правила.
|
||||
|
||||
### Кодовые шаблоны
|
||||
|
||||
Первая буква кода соответствует схеме:
|
||||
|
||||
::: content
|
||||
|
||||
- T: применяется в целом к шаблонам
|
||||
- H: применяется к html
|
||||
- D: применяется специально для Django
|
||||
- J: применяется специально для Jinja
|
||||
- N: применяется специально для Nunjucks
|
||||
- M: применяется специально для Handlebars
|
||||
:::
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
astroid==2.12.9; python_full_version >= "3.7.2"
|
||||
attrs==22.1.0; python_version >= "3.7"
|
||||
black==22.8.0; python_full_version >= "3.6.2"
|
||||
click==8.1.3; python_version >= "3.7"
|
||||
colorama==0.4.5; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
||||
coverage==6.4.4; python_version >= "3.7"
|
||||
cssbeautifier==1.14.6
|
||||
dill==0.3.5.1; python_full_version >= "3.7.2"
|
||||
distlib==0.3.6; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
||||
editorconfig==0.12.3
|
||||
execnet==1.9.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
||||
filelock==3.8.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
|
||||
flake8==3.9.2; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
|
||||
html-tag-names==0.1.2; python_version >= "3.7" and python_version < "4.0"
|
||||
html-void-elements==0.1.0; python_version >= "3.7" and python_version < "4.0"
|
||||
importlib-metadata==4.12.0; python_version >= "3.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"
|
||||
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"
|
||||
pathspec==0.10.1; python_version >= "3.7"
|
||||
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"
|
||||
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"
|
||||
pytest-forked==1.4.0; python_version >= "3.6"
|
||||
pytest-xdist==2.5.0; python_version >= "3.6"
|
||||
pytest==7.1.3; python_version >= "3.7"
|
||||
pyyaml==6.0; python_version >= "3.6"
|
||||
regex==2022.9.11; python_version >= "3.6"
|
||||
six==1.16.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0"
|
||||
tomli==2.0.1; python_full_version <= "3.11.0a6" and python_full_version >= "3.7.2" and python_version >= "3.7" and python_version < "3.11" and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") or python_version < "3.11"
|
||||
tomlkit==0.11.4; python_version >= "3.6" and python_version < "4.0" and python_full_version >= "3.7.2"
|
||||
tox==3.26.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
||||
tqdm==4.64.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
|
||||
typed-ast==1.5.4; python_version < "3.8" and implementation_name == "cpython" and python_full_version >= "3.7.2" and python_version >= "3.6"
|
||||
types-pyyaml==6.0.11
|
||||
typing-extensions==4.3.0; python_version < "3.8" and python_version >= "3.7" and python_full_version >= "3.7.2" and (python_version >= "3.7" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.5.0" and python_version < "3.8" and python_version >= "3.7")
|
||||
virtualenv==20.16.5; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
||||
wrapt==1.14.1
|
||||
zipp==3.8.1; python_version < "3.8" and python_version >= "3.7" and (python_version >= "3.7" and python_full_version < "3.0.0" and python_version < "3.8" or python_full_version >= "3.5.0" and python_version < "3.8" and python_version >= "3.7")
|
||||
|
|
@ -62,34 +62,24 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
|
||||
# if a one-line, inline tag, just process it, only if line starts w/ it
|
||||
elif (
|
||||
re.findall(
|
||||
rf"(^<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
|
||||
item,
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
)
|
||||
or re.findall(
|
||||
re.compile(
|
||||
rf"(<({slt_html})\b.+?>)(.*?)(</(\2)>[^<]*?$)",
|
||||
(
|
||||
re.findall(
|
||||
rf"""^ # start of a line
|
||||
(?:
|
||||
(?:<({slt_html})>)(?:.*?)(?:</(?:\1)>[ \t]*?) # <span>stuff</span> >>>> match 1
|
||||
|(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:</(?:\2)>[ \t]*?) # <span stuff>stuff</span> >>> match 2
|
||||
|(?:<(?:{always_self_closing_html})\b[^>]*?/?>[ \t]*?) # <img stuff />
|
||||
|(?:<(?:{slt_html})\b[^>]*?/>[ \t]*?) # <img />
|
||||
|(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(\3)[ ]+?.*?%}}[ \t]*?) # >>> match 3
|
||||
)
|
||||
+?[^<]*?$ # with no other tags following until end of line
|
||||
""",
|
||||
item,
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
),
|
||||
item,
|
||||
)
|
||||
)
|
||||
or re.findall(
|
||||
rf"^({{%[ ]*?({slt_template})[ ]+?.*?%}})(.*?)({{%[ ]+?end(\2)[ ]+?.*?%}})",
|
||||
item,
|
||||
re.IGNORECASE | re.MULTILINE | re.VERBOSE,
|
||||
)
|
||||
or re.findall(
|
||||
rf"(<({slt_html})\b.*?/>)", item, flags=re.IGNORECASE | re.VERBOSE
|
||||
)
|
||||
or re.findall(
|
||||
re.compile(
|
||||
rf"(<({always_self_closing_html})\b.*?/?>)",
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
),
|
||||
item,
|
||||
)
|
||||
) and is_block_raw is False:
|
||||
and is_block_raw is False
|
||||
):
|
||||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
||||
# if unindent, move left
|
||||
|
|
@ -108,7 +98,7 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
)
|
||||
and not re.findall(
|
||||
rf"(<({slt_html})\\b.+?>)(.*?)(</(\2)>[^<]*?$)",
|
||||
rf"(<({slt_html})\\b[^>]+?>)(.*?)(</(\2)>[^<]*?$)",
|
||||
item,
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
)
|
||||
|
|
@ -123,7 +113,7 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
)
|
||||
or re.findall(
|
||||
re.compile(
|
||||
rf"(^<({slt_html})\b.+?>)(.*?)(</(\2)>)",
|
||||
rf"(^<({slt_html})\b[^>]+?>)(.*?)(</(\2)>)",
|
||||
re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
),
|
||||
item,
|
||||
|
|
@ -157,6 +147,17 @@ def indent_html(rawcode: str, config: Config) -> str:
|
|||
),
|
||||
item,
|
||||
)
|
||||
# # and not ending in a slt like <span><strong></strong>.
|
||||
# and not re.findall(
|
||||
# rf"(<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
|
||||
# item,
|
||||
# re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
# )
|
||||
# and not re.findall(
|
||||
# rf"(<({slt_html})\\b.+?>)(.*?)(</(\2)>[^<]*?$)",
|
||||
# item,
|
||||
# re.IGNORECASE | re.VERBOSE | re.MULTILINE,
|
||||
# )
|
||||
and is_block_raw is False
|
||||
):
|
||||
tmp = (indent * indent_level) + item + "\n"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
message: Double quotes should be used in tags.
|
||||
flags: re.DOTALL
|
||||
patterns:
|
||||
- "{%[ \t]*?extends[ \t]+?'[^']*'"
|
||||
- "{%[ \t]*?(?:trans(?:late)?|with|extends|include|now)?[ \t]+?(?:[^']+?=)?'[^']*'"
|
||||
- rule:
|
||||
name: T003
|
||||
message: 'Endblock should have name. Ex: {% endblock body %}.'
|
||||
|
|
@ -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:
|
||||
- '{%(?:(?!%}).)*}%'
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def test_config(runner: CliRunner) -> None:
|
|||
"--preserve-blank-lines",
|
||||
],
|
||||
)
|
||||
|
||||
print(result.output)
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -63,5 +63,26 @@ def test_nested_string(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
</span>
|
||||
</p>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<ul>
|
||||
<li>
|
||||
<span>C</span> <a>D</a> <strong>Q</strong>
|
||||
</li>
|
||||
</ul>
|
||||
""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<ul>
|
||||
<li>
|
||||
<span>C</span> <a>D</a> <strong>Q</strong>
|
||||
</li>
|
||||
</ul>
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -79,6 +79,31 @@ def test_T002(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert "T002" not in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% with a='this' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert result.exit_code == 1
|
||||
assert "T002" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% trans 'this' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert result.exit_code == 1
|
||||
assert "T002" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% translate 'this' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert result.exit_code == 1
|
||||
assert "T002" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% include 'this' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert result.exit_code == 1
|
||||
assert "T002" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% now 'Y-m-d G:i:s' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert result.exit_code == 1
|
||||
assert "T002" in result.output
|
||||
|
||||
|
||||
def test_T003(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"{% endblock %}")
|
||||
|
|
@ -837,6 +862,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:
|
||||
|
|
|
|||
7
tox.ini
7
tox.ini
|
|
@ -1,11 +1,10 @@
|
|||
[tox]
|
||||
envlist = py3{7,8,9,10}-test
|
||||
envlist = test
|
||||
skip_missing_interpreters = True
|
||||
isolated_build = True
|
||||
setenv =
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
|
||||
|
||||
[testenv:isort]
|
||||
commands =
|
||||
isort src/djlint
|
||||
|
|
@ -48,16 +47,12 @@ allowlist_externals =
|
|||
mypy
|
||||
pylint
|
||||
|
||||
|
||||
|
||||
[testenv]
|
||||
commands =
|
||||
pytest --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing {posargs:} -n auto --dist loadgroup
|
||||
skip_install: false
|
||||
allowlist_externals = pytest
|
||||
|
||||
|
||||
|
||||
[testenv:test-fast]
|
||||
commands =
|
||||
pytest -n 4
|
||||
|
|
|
|||
Loading…
Reference in a new issue