noRedundantAlt
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/a11y/noRedundantAlt -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
jsx-a11y/img-redundant-alt相同¥Same as
jsx-a11y/img-redundant-alt
-
¥How to configure
{ "linter": { "rules": { "a11y": { "noRedundantAlt": "error" } } }}¥Description
强制 img alt prop 不包含单词 “image”、“picture” 或 “photo”。
¥Enforce img alt prop does not contain the word “image”, “picture”, or “photo”.
规则将首先检查 aria-hidden 是否为真,以确定是否执行该规则。如果图片被隐藏,则规则将始终成功。
¥The rule will first check if aria-hidden is truthy to determine whether to enforce the rule. If the image is
hidden, then the rule will always succeed.
¥Examples
¥Invalid
<img src="src" alt="photo content" />;code-block.jsx:1:20 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the words “image”, “picture”, or “photo” in img element alt text.
> 1 │ <img src=“src” alt=“photo content” />;
│ ^^^^^^^^^^^^^^^
2 │
ℹ Screen readers announce img elements as “images”, so it is not necessary to redeclare this in alternative text.
<img alt={`picture doing ${things}`} {...this.props} />;code-block.jsx:1:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the words “image”, “picture”, or “photo” in img element alt text.
> 1 │ <img alt={`picture doing ${things}`} {…this.props} />;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Screen readers announce img elements as “images”, so it is not necessary to redeclare this in alternative text.
<img alt="picture of cool person" aria-hidden={false} />;code-block.jsx:1:10 lint/a11y/noRedundantAlt ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid the words “image”, “picture”, or “photo” in img element alt text.
> 1 │ <img alt=“picture of cool person” aria-hidden={false} />;
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Screen readers announce img elements as “images”, so it is not necessary to redeclare this in alternative text.
¥Valid
<> <img src="src" alt="alt" /> <img src="src" alt={photo} /> <img src="bar" aria-hidden alt="Picture of me taking a photo of an image" /></>¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号