Skip to content

Commit

Permalink
fix(h033): fix rull to not match data-action
Browse files Browse the repository at this point in the history
Thanks @Mouarius
  • Loading branch information
christopherpickering committed Sep 18, 2023
1 parent aa78ca7 commit f6881e0
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ select = [
"W",
]
target-version = "py311"
ignore = ["E501", "PLR0913", "PLR0915", "PLR0912", "D203", "D213"]
ignore = ["E501", "PLR0913", "PLR0915", "PLR0912", "D203", "D213", "PLW1510"]

[tool.ruff.per-file-ignores]
"tests/*" = ["N802", "D103", "T201", "D104", "PLR0915", "PLR2004"]
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 f6881e0

Please sign in to comment.