html/id-duplication
Disallow duplicate element IDs.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
essential, happy-path, nuxt, ecosystem, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
Both the input and help paragraph declare id="email", so the label target is ambiguous.
<template>
<label for="email">Email</label>
<input id="email" />
<p id="email">Required</p>
</template>
Good
The input keeps email; the help paragraph uses email-help, and aria-describedby refers to that distinct ID.
<template>
<label for="email">Email</label>
<input id="email" aria-describedby="email-help" />
<p id="email-help">Required</p>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"html/id-duplication": "error"
}
},
});
Then run vp run lint.