-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(linter): fixed false positive on h026 data-id
closes #711
- Loading branch information
1 parent
232f4bc
commit 400882a
Showing
3 changed files
with
104 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"""Test linter code H026. | ||
poetry run pytest tests/test_linter/test_h026.py | ||
""" | ||
import pytest | ||
|
||
from src.djlint.lint import linter | ||
from tests.conftest import lint_printer | ||
|
||
test_data = [ | ||
pytest.param( | ||
('<asdf id="" >'), | ||
( | ||
[ | ||
{ | ||
"code": "H025", | ||
"line": "1:0", | ||
"match": '<asdf id="" >', | ||
"message": "Tag seems to be an orphan.", | ||
}, | ||
{ | ||
"code": "H026", | ||
"line": "1:0", | ||
"match": '<asdf id=""', | ||
"message": "Empty id and class tags can be removed.", | ||
}, | ||
] | ||
), | ||
id="empted quotes", | ||
), | ||
pytest.param( | ||
("<asdf id >"), | ||
( | ||
[ | ||
{ | ||
"code": "H025", | ||
"line": "1:0", | ||
"match": "<asdf id >", | ||
"message": "Tag seems to be an orphan.", | ||
}, | ||
{ | ||
"code": "H026", | ||
"line": "1:0", | ||
"match": "<asdf id", | ||
"message": "Empty id and class tags can be removed.", | ||
}, | ||
] | ||
), | ||
id="no quotes", | ||
), | ||
pytest.param( | ||
('<asdf class="" >'), | ||
( | ||
[ | ||
{ | ||
"code": "H025", | ||
"line": "1:0", | ||
"match": '<asdf class="" >', | ||
"message": "Tag seems to be an orphan.", | ||
}, | ||
{ | ||
"code": "H026", | ||
"line": "1:0", | ||
"match": '<asdf class=""', | ||
"message": "Empty id and class tags can be removed.", | ||
}, | ||
] | ||
), | ||
id="class", | ||
), | ||
pytest.param( | ||
('<asdf {% class="" %}></asdf>'), | ||
([]), | ||
id="class in tag", | ||
), | ||
pytest.param( | ||
("<div x-id-y></div><div id-y></div><div x-id></div>"), | ||
([]), | ||
id="prefix and suffix", | ||
), | ||
pytest.param( | ||
( | ||
'<div x-id-y=""></div><div id-y=""></div><div x-id=""></div><div data-id=""></div>' | ||
), | ||
([]), | ||
id="prefix and suffix quoted", | ||
), | ||
] | ||
|
||
|
||
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters