require-li-container
This rule enforces that <li> elements must be children of <ul>, <ol> or <menu>.
How to use
// eslint.config.js (flat config)
import angularTemplate from "@html-eslint/eslint-plugin-angular-template";
import templateParser from "@angular-eslint/template-parser";
export default [
{
files: ["**/*.html"],
languageOptions: {
parser: templateParser,
},
plugins: {
"@html-eslint/angular-template": angularTemplate,
},
rules: {
"@html-eslint/angular-template/require-li-container": "error",
},
},
];
Rule Details
The <li> tag should be contained in a parent element: <ol>, <ul> or <menu>.
Note: A <li> nested inside a custom element (names containing -, including Angular components/directives and built-ins like <ng-container>/<ng-template>), or with no enclosing element at all (e.g. a template meant to be projected into a list via <ng-content>), is allowed since the actual rendered container can't be statically verified.
Examples
Examples of incorrect code for this rule:
<div>
<li>item 1</li>
<li>item 2</li>
</div>
Examples of correct code for this rule:
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
<ol>
@for (item of items; track item.id) {
<li [textContent]="item.name"></li>
}
</ol>
<app-custom-list>
<li>item</li>
</app-custom-list>