Skip to content
← Back to rules

jsx-a11y/scope Correctness

🛠️ An auto-fix is available for this rule.

用途

scope 属性应仅用于 <th> 元素。

为什么这不好?

scope 属性使屏幕阅读器用户更容易浏览表格,前提是正确使用它。 如果使用不当,scope 会让表格导航变得困难得多,也更低效。 屏幕阅读器的工作方式是假设表格有一个标题,并且该标题指定了一个作用域。由于屏幕阅读器的工作原理,拥有准确的标题会让表格对使用该设备的人来说更易访问,也更高效。

示例

以下是此规则的错误代码示例:

jsx
<div scope />

以下是此规则的正确代码示例:

jsx
<th scope="col" />
<th scope={scope} />

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/scope": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsx-a11y"],
  rules: {
    "jsx-a11y/scope": "error",
  },
});
bash
oxlint --deny jsx-a11y/scope --jsx-a11y-plugin

版本

此规则于 v0.0.19 中添加。

参考资料