Skip to content

Commit

Permalink
Merge pull request #743 from Mouarius/rule-ignore-data-action
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherpickering authored Sep 18, 2023
2 parents 4a7bef5 + 7c96cc6 commit 8ec158a
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 43 deletions.
Binary file modified docs/src/static/py/PyYAML-99-py3-none-any.whl
Binary file not shown.
Binary file modified docs/src/static/py/click-99-py3-none-any.whl
Binary file not shown.
Binary file modified docs/src/static/py/cssbeautifier-99-py3-none-any.whl
Binary file not shown.
Binary file modified docs/src/static/py/djlint-99-py3-none-any.whl
Binary file not shown.
Binary file modified docs/src/static/py/jsbeautifier-99-py3-none-any.whl
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"scripts": {
"format": "prettier --config .prettierrc \"{bin,docs}/**/*.{ts,css,less,scss,js,json,md,yaml,html}\" --write",
"postinstall": "python3 -m pip install --upgrade djlint==1.31.1",
"postinstall": "python3 -m pip install --upgrade djlint==1.32.1",
"pre-commit": "lint-staged",
"commit": "git add . && pre-commit run; git add . && npm run pre-commit && cz --no-verify",
"test": "xo"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name="djlint"
version="1.31.1"
version="1.32.1"
description="HTML Template Linter and Formatter"
license="GPL-3.0-or-later"
authors=["Christopher Pickering <cpickering@rhc.net>"]
Expand Down
4 changes: 2 additions & 2 deletions src/djlint/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@
name: H033
message: Extra whitespace found in form action.
patterns:
- <form[^>]+?action=['|"]\s
- <form[^>]+?action=(['|"])({{(?:(?!}}).)*}}|{%(?:(?!%}).)*%}|([^"'{]))*\s+?\1
- <form[^>]*\saction=['|"]\s
- <form[^>]*\saction=(['|"])({{(?:(?!}}).)*}}|{%(?:(?!%}).)*%}|([^"'{]))*\s+?\1
- rule:
name: T034
message: Did you intend to use {% ... %} instead of {% ... }%?
Expand Down
162 changes: 162 additions & 0 deletions tests/test_linter/test_h033.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""Test form action tags.
poetry run pytest tests/test_linter/test_h033.py
"""
import pytest

from src.djlint.lint import linter
from tests.conftest import lint_printer

test_data = [
pytest.param(
("<form action=\" {% url 'foo:bar' %} \" ...>...</form>"),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="',
"message": "Extra whitespace found in form action.",
},
{
"code": "H033",
"line": "1:0",
"match": '<form action=" {% ur',
"message": "Extra whitespace found in form action.",
},
]
),
id="one",
),
pytest.param(
("<form action=\"{% url 'foo:bar' %}\" ...>...</form>"),
([]),
id="one - no error",
),
pytest.param(
("<form action=\" {% url 'foo:bar' %} {{ asdf}} \" ...>...</form>"),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="',
"message": "Extra whitespace found in form action.",
},
{
"code": "H033",
"line": "1:0",
"match": '<form action=" {% ur',
"message": "Extra whitespace found in form action.",
},
]
),
id="two",
),
pytest.param(
("<form action=\"{% url 'foo:bar' %} {{ asdf}}\" ...>...</form>"),
([]),
id="two - no error",
),
pytest.param(
("<form action=\" {% url 'foo:bar' %} \" ...>...</form>"),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="',
"message": "Extra whitespace found in form action.",
},
{
"code": "H033",
"line": "1:0",
"match": '<form action=" {% ur',
"message": "Extra whitespace found in form action.",
},
]
),
id="three",
),
pytest.param(
('<form action=" {{ asdf}} " ...>...</form>'),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="',
"message": "Extra whitespace found in form action.",
},
{
"code": "H033",
"line": "1:0",
"match": '<form action=" {{ as',
"message": "Extra whitespace found in form action.",
},
]
),
id="four",
),
pytest.param(
("<form action=\"{% url 'foo:bar' %} \" ...>...</form>"),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="{% url',
"message": "Extra whitespace found in form action.",
}
]
),
id="five",
),
pytest.param(
('<form action="asdf " ...>...</form>'),
(
[
{
"code": "H033",
"line": "1:0",
"match": '<form action="asdf "',
"message": "Extra whitespace found in form action.",
}
]
),
id="six",
),
pytest.param(
('<form action="asdf" ...>...</form>'),
([]),
id="six - no error",
),
pytest.param(
(
'<form action="#"\n'
' method="get"\n'
' data-action="\n'
" submit:my-custom-element#handleFormSubmit\n"
" click:my-custom-element#handleClick\n"
' some-event:my-custom-element#handleSomething" >\n'
" <!-- some content -->\n"
"</form>"
),
([]),
id="gh pr #743",
),
]


@pytest.mark.parametrize(("source", "expected"), test_data)
def test_base(source, expected, basic_config):
filename = "test.html"
output = linter(basic_config, source, filename, filename)

lint_printer(source, expected, output[filename])

mismatch = list(filter(lambda x: x not in expected, output[filename])) + list(
filter(lambda x: x not in output[filename], expected)
)

assert len(mismatch) == 0
39 changes: 0 additions & 39 deletions tests/test_linter/test_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,45 +438,6 @@ def test_H031(runner: CliRunner, tmp_file: TextIO) -> None:
assert "H031" not in result.output


def test_H033(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name, b"<form action=\" {% url 'foo:bar' %} \" ...>...</form>"
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(
tmp_file.name,
b"<form action=\" {% url 'foo:bar' %} {{ asdf}} \" ...>...</form>",
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(
tmp_file.name, b"<form action=\" {% url 'foo:bar' %} \" ...>...</form>"
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(tmp_file.name, b'<form action=" {{ asdf}} " ...>...</form>')
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(
tmp_file.name, b"<form action=\"{% url 'foo:bar' %} \" ...>...</form>"
)
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(tmp_file.name, b'<form action="asdf " ...>...</form>')
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output

write_to_file(tmp_file.name, b'<form action=" asdf " ...>...</form>')
result = runner.invoke(djlint, [tmp_file.name])
assert "H033" in result.output


def test_H035(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<meta this >")
result = runner.invoke(djlint, [tmp_file.name])
Expand Down

0 comments on commit 8ec158a

Please sign in to comment.