mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-16 03:20:58 +00:00
parent
d01f866a29
commit
bdc3645415
3 changed files with 41 additions and 6 deletions
|
|
@ -45,6 +45,8 @@ Codes
|
|||
+--------+-------------------------------------------------------------------------+
|
||||
| J018 | (Jinja) Internal links should use the {% url ... %} pattern. |
|
||||
+--------+-------------------------------------------------------------------------+
|
||||
| H019 | Replace 'javascript:abc()' with on_ event and real url. |
|
||||
+--------+-------------------------------------------------------------------------+
|
||||
|
||||
Adding Rules
|
||||
------------
|
||||
|
|
|
|||
|
|
@ -247,12 +247,19 @@
|
|||
message: (Django) Internal links should use the {% url ... %} pattern.
|
||||
flags: re.DOTALL|re.I
|
||||
patterns:
|
||||
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url)=[\"|'](?!https?://)[\w|/]+
|
||||
- <form\s+?[^>]*?(?:action)=[\"|'](?!https?://)[\w|/]+
|
||||
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url)=[\"|'](?!(?:https?://)|javascript:|on\w+:)[\w|/]+
|
||||
- <form\s+?[^>]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:)[\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)=[\"|'](?!https?://)[\w|/]+
|
||||
- <form\s+?[^>]*?(?:action)=[\"|'](?!https?://)[\w|/]+
|
||||
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url)=[\"|'](?!(?:https?://)|javascript:|on\w+:)[\w|/]+
|
||||
- <form\s+?[^>]*?(?:action)=[\"|'](?!(?:https?://)|javascript:|on\w+:)[\w|/]+
|
||||
- rule:
|
||||
name: H019
|
||||
message: Replace 'javascript:abc()' with on_ event and real url.
|
||||
flags: re.DOTALL|re.I
|
||||
patterns:
|
||||
- <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url)=[\"|']javascript:[\w|/]+
|
||||
- <form\s+?[^>]*?(?:action)=[\"|']javascript:[\w|/]+
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ run::
|
|||
|
||||
# for a single test
|
||||
|
||||
pytest tests/test_linter.py::test_H011 --cov=src/djlint --cov-branch \
|
||||
pytest tests/test_linter.py::test_DJ018 --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
"""
|
||||
|
|
@ -203,12 +203,38 @@ def test_H017(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
def test_DJ018(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b'<a class="drop-link" href="/Collections?handler=RemoveAgreement&id=@a.Id">',
|
||||
b'<a href="/Collections?handler=RemoveAgreement&id=@a.Id">\n<form action="/Collections">',
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 1
|
||||
assert "D018 1:" in result.output
|
||||
assert "J018 1:" in result.output
|
||||
assert "D018 2:" in result.output
|
||||
assert "J018 2:" in result.output
|
||||
|
||||
# test javascript functions
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b'<a href="javascript:abc()">\n<form action="javascript:abc()">',
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
# don't check status code. will fail on other rules here.
|
||||
assert "D018 1:" not in result.output
|
||||
assert "J018 1:" not in result.output
|
||||
assert "D018 2:" not in result.output
|
||||
assert "J018 2:" not in result.output
|
||||
|
||||
# test on_ events
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b'<a href="onclick:abc()">\n<form action="onclick:abc()">',
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
assert result.exit_code == 0
|
||||
assert "D018 1:" not in result.output
|
||||
assert "J018 1:" not in result.output
|
||||
assert "D018 2:" not in result.output
|
||||
assert "J018 2:" not in result.output
|
||||
|
||||
|
||||
def test_rules_not_matched_in_ignored_block(
|
||||
|
|
|
|||
Loading…
Reference in a new issue