File tree 4 files changed +79
-11
lines changed
tests/validator/samples/invalid-self-closing-tag
4 files changed +79
-11
lines changed Original file line number Diff line number Diff line change @@ -676,11 +676,21 @@ const validation = {
676
676
error ( node , 'invalid-style-directive-modifier' ) ;
677
677
}
678
678
} ,
679
- SvelteHead ( node ) {
679
+ SvelteHead ( node , context ) {
680
680
const attribute = node . attributes [ 0 ] ;
681
681
if ( attribute ) {
682
682
error ( attribute , 'illegal-svelte-head-attribute' ) ;
683
683
}
684
+
685
+ if ( context . state . analysis . source [ node . end - 2 ] === '/' ) {
686
+ warn (
687
+ context . state . analysis . warnings ,
688
+ node ,
689
+ context . path ,
690
+ 'invalid-self-closing-tag' ,
691
+ node . name
692
+ ) ;
693
+ }
684
694
} ,
685
695
SvelteElement ( node , context ) {
686
696
validate_element ( node , context ) ;
@@ -704,6 +714,16 @@ const validation = {
704
714
error ( attribute , 'invalid-svelte-fragment-attribute' ) ;
705
715
}
706
716
}
717
+
718
+ if ( context . state . analysis . source [ node . end - 2 ] === '/' ) {
719
+ warn (
720
+ context . state . analysis . warnings ,
721
+ node ,
722
+ context . path ,
723
+ 'invalid-self-closing-tag' ,
724
+ node . name
725
+ ) ;
726
+ }
707
727
} ,
708
728
SlotElement ( node ) {
709
729
for ( const attribute of node . attributes ) {
Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ const options = {
253
253
const misc = {
254
254
/** @param {string } name */
255
255
'invalid-self-closing-tag' : ( name ) =>
256
- `Self-closing HTML tags for non-void elements are ambiguous — use <${ name } ...></${ name } > rather than <${ name } ... />`
256
+ `Self-closing tags for non-void elements are ambiguous — use <${ name } ...></${ name } > rather than <${ name } ... />`
257
257
} ;
258
258
259
259
/** @satisfies {Warnings } */
Original file line number Diff line number Diff line change 1
- <!-- valid -->
2
- <link />
1
+ <!-- valid - foreign namespace -->
3
2
<svg ><g /></svg >
4
3
5
- <!-- invalid -->
4
+ <!-- not reported - void tags -->
5
+ <link />
6
+ <br />
7
+ <svelte:options />
8
+ <svelte:window on:event ={() => null } />
9
+ <svelte:document on:event ={() => null } />
10
+ <svelte:body on:event ={() => null } />
11
+
12
+ <!-- not reported - deprecated -->
13
+ <slot />
14
+
15
+ <!-- not reported - components -->
16
+ {#if true }
17
+ <svelte:self />
18
+ {/if }
19
+ <Foo />
20
+ <svelte:component this ={" foo" } />
21
+
22
+ <!-- not reported - `this` can be bound to both void and non-void tags -->
23
+ <svelte:element this =" dif" />
24
+
25
+ <!-- invalid and reported -->
6
26
<div />
7
27
<my-thing />
28
+ <svelte:head />
29
+ <Foo >
30
+ <svelte:fragment slot =" footer" />
31
+ </Foo >
Original file line number Diff line number Diff line change 1
1
[
2
2
{
3
3
"code" : " invalid-self-closing-tag" ,
4
- "message" : " Self-closing HTML tags for non-void elements are ambiguous — use <div ...></div> rather than <div ... />" ,
4
+ "message" : " Self-closing tags for non-void elements are ambiguous — use <div ...></div> rather than <div ... />" ,
5
5
"start" : {
6
- "line" : 6 ,
6
+ "line" : 26 ,
7
7
"column" : 0
8
8
},
9
9
"end" : {
10
- "line" : 6 ,
10
+ "line" : 26 ,
11
11
"column" : 7
12
12
}
13
13
},
14
14
{
15
15
"code" : " invalid-self-closing-tag" ,
16
- "message" : " Self-closing HTML tags for non-void elements are ambiguous — use <my-thing ...></my-thing> rather than <my-thing ... />" ,
16
+ "message" : " Self-closing tags for non-void elements are ambiguous — use <my-thing ...></my-thing> rather than <my-thing ... />" ,
17
17
"start" : {
18
- "line" : 7 ,
18
+ "line" : 27 ,
19
19
"column" : 0
20
20
},
21
21
"end" : {
22
- "line" : 7 ,
22
+ "line" : 27 ,
23
23
"column" : 12
24
24
}
25
+ },
26
+ {
27
+ "code" : " invalid-self-closing-tag" ,
28
+ "message" : " Self-closing tags for non-void elements are ambiguous — use <svelte:head ...></svelte:head> rather than <svelte:head ... />" ,
29
+ "start" : {
30
+ "line" : 28 ,
31
+ "column" : 0
32
+ },
33
+ "end" : {
34
+ "line" : 28 ,
35
+ "column" : 15
36
+ }
37
+ },
38
+ {
39
+ "code" : " invalid-self-closing-tag" ,
40
+ "message" : " Self-closing tags for non-void elements are ambiguous — use <svelte:fragment ...></svelte:fragment> rather than <svelte:fragment ... />" ,
41
+ "start" : {
42
+ "line" : 30 ,
43
+ "column" : 1
44
+ },
45
+ "end" : {
46
+ "line" : 30 ,
47
+ "column" : 34
48
+ }
25
49
}
26
50
]
You can’t perform that action at this time.
0 commit comments