跳转到内容

useSemanticElements

Diagnostic Category: lint/a11y/useSemanticElements

Since: v1.8.0

Sources:

It detects the use of role attributes in JSX elements and suggests using semantic elements instead.

The role attribute is used to define the purpose of an element, but it should be used as a last resort. Using semantic elements like <button>, <nav> and others are more accessible and provide better semantics.

<div role="checkbox">
code-block.jsx:2:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

expected &lt; but instead the file ends

1 │ <div role=“checkbox”>
> 2 │


the file ends here

1 │ <div role=“checkbox”>
> 2 │


<div role="img">
code-block.jsx:2:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

expected &lt; but instead the file ends

1 │ <div role=“img”>
> 2 │


the file ends here

1 │ <div role=“img”>
> 2 │


<>
<div></div>
<header></header>
<img alt="" src="image.jpg" />
</>