{"record":{"id":"e8a7c50896f11b85","repo":"oxc-project/oxc","slug":"the-element-element-has-an-implicit-role-of","errorCode":null,"errorMessage":"The `{element}` element has an implicit role of `{role}`. Defining this explicitly is redundant and should be avoided.","messagePattern":"The `(.+?)` element has an implicit role of `(.+?)`\\. Defining this explicitly is redundant and should be avoided\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs","lineNumber":25,"sourceCode":"    ast::{Expression, JSXAttributeItem, JSXAttributeValue, JSXOpeningElement},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::{\n        get_element_implicit_roles, get_element_type, get_prop_value,\n        get_string_literal_prop_value, has_jsx_prop_ignore_case, parse_jsx_value,\n    },\n};\n\nfn no_redundant_roles_diagnostic(span: Span, element: &str, role: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"The `{element}` element has an implicit role of `{role}`. Defining this explicitly is redundant and should be avoided.\"\n    ))\n    .with_help(format!(\"Remove the redundant role `{role}` from the element `{element}`.\"))\n    .with_label(span)\n}\n\n/// Redundant roles that are allowed by default unless overridden by the\n/// `allowedRedundantRoles` option, mirroring eslint-plugin-jsx-a11y's\n/// `DEFAULT_ROLE_EXCEPTIONS`.\nconst DEFAULT_ROLE_EXCEPTIONS: &[(&str, &str)] = &[(\"nav\", \"navigation\")];\n\n#[derive(Debug, Clone, Default, Deserialize)]\npub struct NoRedundantRoles(Box<NoRedundantRolesConfig>);\n\n#[derive(Debug, Clone, Default, Deserialize, JsonSchema)]\npub struct NoRedundantRolesConfig {\n    /// A mapping of element names to the redundant roles that are explicitly\n    /// allowed on them. Providing an entry overrides the default exceptions for","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/no_redundant_roles.rs#L7-L43","documentation":"This is the `jsx_a11y/no-redundant-roles` rule in oxlint. It fires when an element's explicit `role` prop duplicates an implicit role that the element already has (computed via `get_element_implicit_roles`), e.g. `<button role=\"button\">`. The redundancy adds noise and can confuse tooling; the only default exception is `nav` -> `navigation` (see `DEFAULT_ROLE_EXCEPTIONS`), allowed unless removed via `allowedRedundantRoles` config.","triggerScenarios":"A JSX element with a literal `role` string that equals one of its implicit ARIA roles and is not whitelisted by `DEFAULT_ROLE_EXCEPTIONS` or the rule's `allowedRedundantRoles` option.","commonSituations":"Developers adding roles 'to be explicit' on `<button>`, `<nav>`, `<main>`, `<header>`; code migrated from strict-ARIA codebases; template snippets that pre-fill roles; refactors that changed tags without dropping their old role attributes.","solutions":["Delete the redundant `role` attribute and rely on the element's implicit semantics.","If you intentionally want the redundancy documented (like `nav role=\"navigation\"`), confirm it is in `allowedRedundantRoles`.","Audit for other copy-pasted roles in the same file."],"exampleFix":"// before\n<button role=\"button\" onClick={fn}>Save</button>\n\n// after\n<button onClick={fn}>Save</button>","handlingStrategy":"validation","validationCode":"npx oxlint --jsx-a11y/no-redundant-roles src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trust implicit semantics; do not restate roles the tag already has.","During code review, delete role attributes that duplicate the element name.","Maintain allowedRedundantRoles only for documented exceptions like nav/navigation."],"tags":["jsx-a11y","react","accessibility","aria-roles","lint"],"backgroundTag":"redundant-aria-role","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}