menu
prefer-self-closing-tree
Prefer self-closing tree elements without children
Separate opening and closing tags imply that a tree element contains children even when its body is empty. Instead, you SHOULD write an element without children as one self-closing tag.
Reported
1import { TreeBuilder } from "destack:tree";2 3class Panel {4 id: int32 = 0;5}6 7extension of Panel implements TreeBuilder {8 type Tags = { hr: {} };9 10 static element<const Tag: keyof this.Tags, Children: (...unknown[],)>(11 tag: Tag,12 attributes: this.Tags[Tag],13 children: Children,14 ): Panel {15 return new Panel();16 }17 18 static fragment<Children: (...unknown[],)>(children: Children): Panel {19 return new Panel();20 }21}22 23function render(): Panel {24 return <hr></hr>;25}Accepted
1import { TreeBuilder } from "destack:tree";2 3class Panel {4 id: int32 = 0;5}6 7extension of Panel implements TreeBuilder {8 type Tags = { hr: {} };9 10 static element<const Tag: keyof this.Tags, Children: (...unknown[],)>(11 tag: Tag,12 attributes: this.Tags[Tag],13 children: Children,14 ): Panel {15 return new Panel();16 }17 18 static fragment<Children: (...unknown[],)>(children: Children): Panel {19 return new Panel();20 }21}22 23function render(): Panel {24 return <hr />;25}