a11y/no-redundant-roles
Disallow redundant ARIA roles.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
Yes | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The native button already has the button role, so role="button" repeats its implicit semantics.
<template>
<button role="button">Save</button>
</template>
Good
Removing the repeated role keeps the button semantics supplied by HTML.
<template>
<button>Save</button>
</template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"a11y/no-redundant-roles": "warn"
}
},
});
Then run vp run lint.
Differences from eslint-plugin-vuejs-accessibility
An img with an empty alt has the implicit role presentation in HTML-ARIA, so role="img" on that image is kept. eslint-plugin-vuejs-accessibility treats the implicit role of img as img regardless of alt and reports that attribute. A :role binding whose expression is a string literal is read as that static role. A binding that is not a string literal stays unreported.