added rule H029, closes #125

This commit is contained in:
Christopher Pickering 2021-11-16 11:28:35 +01:00
parent 19acc02cda
commit 7c7cac916f
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
4 changed files with 24 additions and 1 deletions

View file

@ -4,6 +4,8 @@ Changelog
next_release
------------
- Added rule T027 to check for unclosed in template syntax
- Added rule T028 to check for missing spaceless tags in attributes
- Added rule H029 to check for lowercase form method
0.5.9a
------

View file

@ -67,7 +67,8 @@ Codes
+--------+-------------------------------------------------------------------------+
| T028 | Consider using spaceless tags inside attribute values. |
+--------+-------------------------------------------------------------------------+
| H029 | Consider using lowercase form method values. |
+--------+-------------------------------------------------------------------------+
Adding Rules

View file

@ -205,3 +205,8 @@
patterns:
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?({%|{{)[^-])
- <(?:/?(?:\w+)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*=([\"'])(?:(?!\1).)*?[^-](%}|}}))
- rule:
name: H029
message: Consider using lowercase form method values.
patterns:
- <[fF][oO][rR][mM]\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}/])*([mM][eE][tT][hH][oO][dD])=(([\"'])[a-zA-Z]*?[A-Z][a-zA-Z]*?\3)

View file

@ -483,6 +483,21 @@ def test_T028(runner: CliRunner, tmp_file: TextIO) -> None:
assert "T028" not in result.output
def test_H029(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b'<forM method="Post">')
result = runner.invoke(djlint, [tmp_file.name])
assert result.exit_code == 1
assert "H029" in result.output
write_to_file(tmp_file.name, b'<forM method="post">')
result = runner.invoke(djlint, [tmp_file.name])
assert "H029" not in result.output
write_to_file(tmp_file.name, b'<a method="post">')
result = runner.invoke(djlint, [tmp_file.name])
assert "H029" not in result.output
def test_rules_not_matched_in_ignored_block(
runner: CliRunner, tmp_file: TextIO
) -> None: