Skip to content

noUnknownAttribute

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"nursery": {
"noUnknownAttribute": "error"
}
}
}
}

¥Description

禁止使用未知的 DOM 属性。

¥Disallow unknown DOM properties.

在 JSX 中,大多数 DOM 属性和特性应该使用驼峰命名法,以符合标准的 JavaScript 风格。如果你习惯编写纯 HTML,这可能会导致错误。只有 data-*aria-* 属性才允许在 JSX 中使用连字符和小写字母。

¥In JSX, most DOM properties and attributes should be camelCased to be consistent with standard JavaScript style. This can be a possible source of error if you are used to writing plain HTML. Only data-* and aria-* attributes are allowed to use hyphens and lowercase letters in JSX.

¥Examples

¥Invalid

<div allowTransparency="true" />
code-block.jsx:1:6 lint/nursery/noUnknownAttribute ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The property ‘allowTransparency’ is not a valid DOM attribute.

> 1 │ <div allowTransparency=“true” />
^^^^^^^^^^^^^^^^^^^^^^^^
2 │

This property is not recognized as a valid HTML/DOM attribute or React prop.

Check the spelling or consider using a valid data-* attribute for custom properties.

<div onclick={() => {}} />
code-block.jsx:1:6 lint/nursery/noUnknownAttribute ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Property ‘onclick’ is not a valid React prop name.

> 1 │ <div onclick={() => {}} />
^^^^^^^^^^^^^^^^^^
2 │

React uses camelCased props, while HTML uses kebab-cased attributes.

Use ‘onClick’ instead of ‘onclick’ for React components.

<div for="bar" />
code-block.jsx:1:6 lint/nursery/noUnknownAttribute ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Property ‘for’ is not a valid React prop name.

> 1 │ <div for=“bar” />
^^^^^^^^^
2 │

React uses camelCased props, while HTML uses kebab-cased attributes.

Use ‘htmlFor’ instead of ‘for’ for React components.

¥Valid

<div className="foo" />
<div onClick={() => {}} />
<div htmlFor="bar" />
<div data-foo="bar" />
<div aria-label="Close" />

¥Options

验证过程中要忽略的属性和特性名称数组。

¥An array of property and attribute names to ignore during validation.

{
"noUnknownAttribute": {
"options": {
"ignore": ["custom-attribute", "non-standard-prop"]
}
}
}

¥Related links