fix: relax no-redundant-roles implementation (#8536)

Deals with the no-redundant-roles part of #8529

There was an erroneous check which compares the element name with the current role. This fix brings no-redundant-roles closer to the original eslint-jsx implementation
pull/8540/head
Nguyen Tran 2 years ago committed by GitHub
parent 6ba2f72251
commit f064c39d5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -121,6 +121,7 @@ const a11y_implicit_semantics = new Map([
['details', 'group'], ['details', 'group'],
['dt', 'term'], ['dt', 'term'],
['fieldset', 'group'], ['fieldset', 'group'],
['figure', 'figure'],
['form', 'form'], ['form', 'form'],
['h1', 'heading'], ['h1', 'heading'],
['h2', 'heading'], ['h2', 'heading'],
@ -132,6 +133,7 @@ const a11y_implicit_semantics = new Map([
['img', 'img'], ['img', 'img'],
['li', 'listitem'], ['li', 'listitem'],
['link', 'link'], ['link', 'link'],
['main', 'main'],
['menu', 'list'], ['menu', 'list'],
['meter', 'progressbar'], ['meter', 'progressbar'],
['nav', 'navigation'], ['nav', 'navigation'],
@ -142,6 +144,7 @@ const a11y_implicit_semantics = new Map([
['progress', 'progressbar'], ['progress', 'progressbar'],
['section', 'region'], ['section', 'region'],
['summary', 'button'], ['summary', 'button'],
['table', 'table'],
['tbody', 'rowgroup'], ['tbody', 'rowgroup'],
['textarea', 'textbox'], ['textarea', 'textbox'],
['tfoot', 'rowgroup'], ['tfoot', 'rowgroup'],
@ -631,9 +634,7 @@ export default class Element extends Node {
} }
// no-redundant-roles // no-redundant-roles
const has_redundant_role = current_role === get_implicit_role(this.name, attribute_map); if (current_role === get_implicit_role(this.name, attribute_map)) {
if (this.name === current_role || has_redundant_role) {
component.warn(attribute, compiler_warnings.a11y_no_redundant_roles(current_role)); component.warn(attribute, compiler_warnings.a11y_no_redundant_roles(current_role));
} }

@ -41,4 +41,8 @@
<!-- Tested header/footer not nested in section/article --> <!-- Tested header/footer not nested in section/article -->
<header role="banner"></header> <header role="banner"></header>
<footer role="contentinfo"></footer> <footer role="contentinfo"></footer>
<!-- Allowed -->
<!-- svelte-ignore a11y-no-noninteractive-element-to-interactive-role -->
<menu role="menu" />

Loading…
Cancel
Save