noMisplacedListElements (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.5.15 - Diagnostic Category:
lint/nursery/noMisplacedListElements - This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Inspired from
@html-eslint/require-li-container
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noMisplacedListElements": "error" } } }}Description
Section titled “Description”Require <li> elements with an HTML element parent to be children of <ul>, <ol>, or <menu>.
List items need a list container to define their relationship to the other items. Placing a list item outside a list container produces invalid HTML.
The parent is the element the item is rendered into. Fragments, conditional and
logical expressions, arrays, and callbacks passed to map, flatMap, or Array.from
are looked through to find it.
List items without an HTML element parent are ignored, including standalone items, items returned from components, items stored in variables, and component children. Their container may be supplied where they are rendered.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<div><li>Item</li></div>code-block.jsx:1:6 lint/nursery/noMisplacedListElements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This <li> element is outside a list container.
> 1 │ <div><li>Item</li></div>
│ ^^^^
2 │
ℹ List items need a list container to form a valid HTML list.
ℹ Make this element a direct child of <ul>, <ol>, or <menu>.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<ul><div><li /></div></ul>code-block.jsx:1:10 lint/nursery/noMisplacedListElements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This <li> element is outside a list container.
> 1 │ <ul><div><li /></div></ul>
│ ^^^^^^
2 │
ℹ List items need a list container to form a valid HTML list.
ℹ Make this element a direct child of <ul>, <ol>, or <menu>.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<div>{items.map((item) => <li key={item}>{item}</li>)}</div>code-block.jsx:1:27 lint/nursery/noMisplacedListElements ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This <li> element is outside a list container.
> 1 │ <div>{items.map((item) => <li key={item}>{item}</li>)}</div>
│ ^^^^^^^^^^^^^^^
2 │
ℹ List items need a list container to form a valid HTML list.
ℹ Make this element a direct child of <ul>, <ol>, or <menu>.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
<> <ul><li>Item</li></ul> <ol><li>Item</li></ol> <menu><li /></menu></><ul>{items.map((item) => <li key={item}>{item}</li>)}</ul><li>Item rendered in a list elsewhere</li>const item = <li>Item rendered in a list elsewhere</li>;function Item() { return <li>Item rendered in a list elsewhere</li>;}<List><li>Component child</li></List>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.