Skip to content

useVueHyphenatedAttributes

¥Summary

¥How to configure

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

¥Description

强制 Vue 模板中的属性名称使用连字符(kebab-case)。

¥Enforce hyphenated (kebab-case) attribute names in Vue templates.

Vue 风格指南建议在模板中使用连字符连接的属性(和 prop)名称,以保持一致性,并将其与使用驼峰式/帕斯卡式命名的 JavaScript 标识符区分开来。

¥Vue style guide recommends using hyphenated attribute (and prop) names in templates to keep them consistent and distinguish them from JavaScript identifiers written in camelCase/PascalCase.

此规则标记被检测为驼峰式命名法 (camelCase)、帕斯卡式命名法 (PascalCase)、常量式命名法 (CONSTANT_CASE)、蛇形命名法 (snake_case) 或包含任何大写 ASCII 字母的属性。它使用 Biome 的内部 Case::identify 辅助函数。

¥This rule flags attributes that are detected as camelCase, PascalCase, CONSTANT_CASE, snake_case or that contain any uppercase ASCII letter. It uses Biome’s internal Case::identify helper.

允许:

¥Allowed:

  • kebab-case 属性(例如 data-test-id

    ¥kebab-case attributes (e.g. data-test-id)

  • 纯小写单字属性(例如 classid

    ¥pure lowercase single word attributes (e.g. class, id)

¥Examples

¥Invalid

<div fooBar="x"></div>
<MyComp :someProp="x" />

¥Valid

<div data-test-id="x"></div>
<div class="foo"></div>
<MyComp :some-prop="x" />

¥Options

该规则支持以下选项:

¥The rule supports the following options:

规则应忽略的属性名称列表(无需连字符)。当你有意允许使用一组固定的驼峰式/帕斯卡式 prop 名称时,请使用此选项。

¥A list of attribute names that should be ignored by the rule (they won’t be required to be hyphenated). Use this when you have a fixed set of camelCase / PascalCase prop names you intentionally allow.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueHyphenatedAttributes": {
"options": {
"ignore": [
"someProp",
"fooBar"
]
}
}
}
}
}
}

¥Valid (using ignore)

<div fooBar="x"></div>

应完全跳过其属性的标签名称列表。这对于故意暴露非连字符属性名称的第三方或内部组件非常有用。

¥A list of tag names whose attributes should be skipped entirely. This is useful for third-party or internal components that deliberately expose non‑hyphenated prop names.

biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueHyphenatedAttributes": {
"options": {
"ignoreTags": [
"MyComp",
"AnotherWidget"
]
}
}
}
}
}
}

¥Valid (using ignoreTags)

<MyComp :someProp="x" />

¥Related links