fix(dj018): fix rule DJ018 for special attrib names

fixes #248
This commit is contained in:
Christopher Pickering 2022-05-18 08:46:48 -05:00
parent e906b3e30a
commit f63cc4d8ea
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 13 additions and 4 deletions

View file

@ -133,14 +133,14 @@
message: (Django) Internal links should use the {% url ... %} pattern.
flags: re.DOTALL|re.I
patterns:
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- <(?:a|div|span|input)\b[^>]*?\s(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- <form\s+?[^>]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- rule:
name: J018
message: (Jinja) Internal links should use the {{ url_for() ... }} pattern.
flags: re.DOTALL|re.I
patterns:
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- <(?:a|div|span|input)\b[^>]*?\s(?:href|data-url|data-src|action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- <form\s+?[^>]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:|mailto:)[\w|/]+
- rule:
name: H019

View file

@ -7,8 +7,7 @@ run::
# for a single test
pytest tests/test_linter.py::test_H021 --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_linter/test_linter.py::test_DJ018
"""
# pylint: disable=C0116,C0103
@ -296,6 +295,16 @@ def test_DJ018(runner: CliRunner, tmp_file: TextIO) -> None:
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 0
# test attribute names
write_to_file(
tmp_file.name,
b'<div data-row-selection-action="highlight"></div>',
)
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
assert result.exit_code == 0
result = runner.invoke(djlint, [tmp_file.name, "--profile", "jinja"])
assert result.exit_code == 0
def test_H019(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<a href='javascript:abc()'>asdf</a>")