From 2aa39f41998e205b3703c827089498750fd05011 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Tue, 3 Aug 2021 09:35:01 -0500 Subject: [PATCH] updated rule for img tag, and links in other tags --- docs/djlint/rules.rst | 2 ++ src/djlint/rules.yaml | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/djlint/rules.rst b/docs/djlint/rules.rst index f11fd3f..9878a55 100644 --- a/docs/djlint/rules.rst +++ b/docs/djlint/rules.rst @@ -48,6 +48,8 @@ Warning Codes +--------+----------------------------------------------------------------+ | W017 | Tag should be self closing. | +--------+----------------------------------------------------------------+ +| W018 | Internal links should use the {% url ... %} pattern. | ++--------+----------------------------------------------------------------+ Adding Rules ------------ diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 737e30e..8cd3f05 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -44,7 +44,9 @@ message: Img tag should have alt, height and width attributes. flags: re.DOTALL|re.I patterns: - - + - + - + - - rule: name: W007 message: should be present before the html tag. @@ -71,10 +73,10 @@ - (?:CLASS|ID|SRC|WIDTH|HEIGHT|ALT|STYLE|LANG|TITLE)= - rule: name: W011 - message: Attirbute values should be quoted. + message: Attribute values should be quoted. flags: re.DOTALL|re.I patterns: - - "[^(?:\"|')](?:class|id|src|width|height|alt|style|lang|title)=[a-zA-Z]+" + - "[^(?:\"|')]\\s+?(?:class|id|src|width|height|alt|style|lang|title|href|action|method)=[a-zA-Z]+" - rule: name: W012 message: There should be no spaces around attribute =. @@ -117,5 +119,5 @@ message: Internal links should use the {% url ... %} pattern. flags: re.DOTALL|re.I patterns: - - ]*?(?:href|data-url)=[\"|'](?!https?://)[\w|/]+ + - <(?:a|div|span|input)\s+?[^>]*?(?:href|data-url|data-ajax)=[\"|'](?!https?://)[\w|/]+ - ]*?(?:action)=[\"|'](?!https?://)[\w|/]+