mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-05 12:24:43 +00:00
added rule T028. closes #128
This commit is contained in:
parent
fee2c1c72b
commit
19acc02cda
3 changed files with 44 additions and 1 deletions
|
|
@ -65,6 +65,9 @@ Codes
|
|||
+--------+-------------------------------------------------------------------------+
|
||||
| T027 | Unclosed string found in template syntax. |
|
||||
+--------+-------------------------------------------------------------------------+
|
||||
| T028 | Consider using spaceless tags inside attribute values. |
|
||||
+--------+-------------------------------------------------------------------------+
|
||||
|
||||
|
||||
|
||||
Adding Rules
|
||||
|
|
|
|||
|
|
@ -199,3 +199,9 @@
|
|||
patterns:
|
||||
- "{%(?:(?!'|\"|%}).)*((?:'|\")(?:(?!'|\"|%}).)*(?:'|\")(?:(?!'|\"|%}).)*)*(?:'|\")(?:(?!'|\"|%}).)*%}"
|
||||
- "{{(?:(?!'|\"|}}).)*((?:'|\")(?:(?!'|\"|}}).)*(?:'|\")(?:(?!'|\"|}}).)*)*(?:'|\")(?:(?!'|\"|}}).)*}}"
|
||||
- rule:
|
||||
name: T028
|
||||
message: Consider using spaceless tags inside attribute values.
|
||||
patterns:
|
||||
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?({%|{{)[^-])
|
||||
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?[^-](%}|}}))
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
# for a single test
|
||||
|
||||
pytest tests/test_linter.py::test_T027 --cov=src/djlint --cov-branch \
|
||||
pytest tests/test_linter.py::test_T028 --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
"""
|
||||
|
|
@ -449,6 +449,40 @@ def test_T027(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
assert "T027" in result.output
|
||||
|
||||
|
||||
def test_T028(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(tmp_file.name, b"<a href=\"{% blah 'asdf' -%}\">")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 1
|
||||
assert "T028" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"<a href=\"{%- blah 'asdf' %}\">")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 1
|
||||
assert "T028" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"<a href=\"{{- blah 'asdf' }}\">")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 1
|
||||
assert "T028" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"<a href=\"{{ blah 'asdf' -}}\">")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 1
|
||||
assert "T028" in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"<a {{ blah 'asdf' }}>")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "T028" not in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"<a {% blah 'asdf' %}>")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "T028" not in result.output
|
||||
|
||||
write_to_file(tmp_file.name, b"{% blah 'asdf' %}")
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert "T028" not in result.output
|
||||
|
||||
|
||||
def test_rules_not_matched_in_ignored_block(
|
||||
runner: CliRunner, tmp_file: TextIO
|
||||
) -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue