feat: added new rule “attr-space-between”
Consider the following the HTML:
<div id="bar"class="foo"></div>
The following error is what I get in the current version of HTMLHint.
Special characters must be escaped : [ < ].
Special characters must be escaped : [ > ].
Tag must be paired, no start tag: [ </div> ]
The attr-space-between rule ensures HTML tags with attributes must have spaces between them. Without this change, tags with attributes without the required space results in the parser interpreting the tag as text. The new error would be:
Attribute "class" must be separated with a space
Proposed changes:
Change this Regex in htmlparser.ts:
const regTag =
// eslint-disable-next-line no-control-regex
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
To the following:
const regTag =
// eslint-disable-next-line no-control-regex
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g
I also added the attr-space-between rule. The name of this rule could be subject to change, but this was the best I came up with. All tests pass with these changes, and docs were updated accordingly. Let me know what you think, and if I should make any additional changes.
Thanks for the PR! It looks good to me at a glance and could be an helpful addition to HTMLHint.
We need @thedaviddias to review it.
I didn't see this reply before. Thanks for looking into this. I'd love to get this approved in a new release so I don't have to use my fork in production.
I didn't see this reply before. Thanks for looking into this. I'd love to get this approved in a new release so I don't have to use my fork in production.
No problem. I'd like to see this added too but we need @thedaviddias to review it as he is the project owner but he hasn't been active here for a couple of years.
There are conflicts in the branch now so moving this to Draft status.