react/no-unknown-property Restriction
它的作用
禁止使用未知的 DOM 属性。
为什么这不好?
DOM 属性应仅在对给定的 HTML 元素有效时使用。
示例
以下是此规则的错误代码示例:
jsx
// 未知属性
const Hello = <div class="hello">Hello World</div>;
const Alphabet = <div abc="something">Alphabet</div>;
// 无效的 aria-* 属性
const IconButton = <div aria-foo="bar" />;以下是此规则的正确代码示例:
jsx
// 未知属性
const Hello = <div className="hello">Hello World</div>;
const Alphabet = <div>Alphabet</div>;
// 无效的 aria-* 属性
const IconButton = <div aria-label="bar" />;配置
此规则接受一个包含以下属性的配置对象:
ignore
type: string[]
default: []
要忽略的属性列表。
requireDataLowercase
type: boolean
default: false
要求 data-* 属性必须为小写,例如使用 data-foobar,而不是 data-fooBar。
如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["react"],
"rules": {
"react/no-unknown-property": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["react"],
rules: {
"react/no-unknown-property": "error",
},
});bash
oxlint --deny react/no-unknown-property --react-plugin版本
此规则在 v0.2.0 中添加。
