Skip to content
← Back to rules

jsx-a11y/no-redundant-roles Correctness

🛠️ An auto-fix is available for this rule.

What it does

Enforces that code does not include a redundant role property, in the case that it's identical to the implicit role property of the element type.

Why is this bad?

Redundant roles can lead to confusion and verbosity in the codebase.

Examples

This rule applies for the following elements and their implicit roles:

  • <button>: button

Examples of incorrect code for this rule:

jsx
<button role="button"></button>

Examples of correct code for this rule:

jsx
<button></button>

Options

This rule takes an object whose keys are element names and whose values are arrays of redundant roles to allow on that element. Providing an entry overrides the default exceptions for that element.

By default role="navigation" is allowed on <nav>. Additional roles can be allowed, for example to keep explicit list semantics that some browsers drop when list-style: none is applied:

json
{
  "jsx-a11y/no-redundant-roles": ["error", { "ul": ["list"], "ol": ["list"], "li": ["listitem"] }]
}

Configuration

This rule accepts a configuration object with the following properties:

type: Record<string, array>

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/no-redundant-roles": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsx-a11y"],
  rules: {
    "jsx-a11y/no-redundant-roles": "error",
  },
});
bash
oxlint --deny jsx-a11y/no-redundant-roles --jsx-a11y-plugin

Version

This rule was added in v0.2.1.

References