fix: tweak element_invalid_self_closing_tag to exclude namespace (#12585)

pull/12588/head
Dominic Gannaway 2 months ago committed by GitHub
parent 621eb76e1e
commit abaa4413df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: tweak element_invalid_self_closing_tag to exclude namespace

@ -636,11 +636,14 @@ const validation = {
} }
} }
// Strip off any namespace from the beginning of the node name.
const node_name = node.name.replace(/[a-zA-Z-]*:/g, '');
if ( if (
context.state.analysis.source[node.end - 2] === '/' && context.state.analysis.source[node.end - 2] === '/' &&
context.state.options.namespace !== 'foreign' && context.state.options.namespace !== 'foreign' &&
!VoidElements.includes(node.name) && !VoidElements.includes(node_name) &&
!SVGElements.includes(node.name) !SVGElements.includes(node_name)
) { ) {
w.element_invalid_self_closing_tag(node, node.name); w.element_invalid_self_closing_tag(node, node.name);
} }

@ -1,6 +1,8 @@
<!-- valid --> <!-- valid -->
<link /> <link />
<svg><g /></svg> <svg><g /></svg>
<enhanced:img />
<!-- invalid --> <!-- invalid -->
<div /> <div />

@ -3,11 +3,11 @@
"code": "element_invalid_self_closing_tag", "code": "element_invalid_self_closing_tag",
"message": "Self-closing HTML tags for non-void elements are ambiguous — use `<div ...></div>` rather than `<div ... />`", "message": "Self-closing HTML tags for non-void elements are ambiguous — use `<div ...></div>` rather than `<div ... />`",
"start": { "start": {
"line": 6, "line": 8,
"column": 0 "column": 0
}, },
"end": { "end": {
"line": 6, "line": 8,
"column": 7 "column": 7
} }
}, },
@ -15,11 +15,11 @@
"code": "element_invalid_self_closing_tag", "code": "element_invalid_self_closing_tag",
"message": "Self-closing HTML tags for non-void elements are ambiguous — use `<my-thing ...></my-thing>` rather than `<my-thing ... />`", "message": "Self-closing HTML tags for non-void elements are ambiguous — use `<my-thing ...></my-thing>` rather than `<my-thing ... />`",
"start": { "start": {
"line": 7, "line": 9,
"column": 0 "column": 0
}, },
"end": { "end": {
"line": 7, "line": 9,
"column": 12 "column": 12
} }
} }

Loading…
Cancel
Save