Skip to content

Commit

Permalink
Add rule S6822 (jsx-a11y/no-redundant-roles): No redundant ARIA role (
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sonar authored Oct 16, 2023
1 parent ffc53a9 commit 021ccd2
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"vuetify:packages/vuetify/src/labs/VDataTable/VDataTableServer.tsx": [
121,
132
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static List<Class<? extends JavaScriptCheck>> getAllChecks() {
NoProtoCheck.class,
NoRedundantJumpCheck.class,
NoRedundantOptionalCheck.class,
NoRedundantRolesCheck.class,
NoRedundantShouldComponentUpdateCheck.class,
NoRedundantTypeConstituentsCheck.class,
NoReferrerPolicyCheck.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@TypeScriptRule
@JavaScriptRule
@Rule(key = "S6822")
public class NoRedundantRolesCheck implements EslintBasedCheck {

@Override
public String eslintKey() {
return "no-redundant-roles";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<h2>Why is this an issue?</h2>
<p>ARIA (Accessible Rich Internet Applications) attributes are used to enhance the accessibility of web content and web applications. These attributes
provide additional information about an element’s role, state, properties, and values to assistive technologies like screen readers.</p>
<p>In HTML, certain elements have default roles. Default roles, also known as implicit roles, are roles that are inherently associated with certain
HTML elements. These roles provide information about what an element does or the type of content it contains, which is especially useful for assistive
technologies like screen readers.</p>
<p>For example, a <code>&lt;button&gt;</code> element has a default role of <code>button</code>. If you explicitly define the role of a
<code>&lt;button&gt;</code> element as <code>button</code>, it’s considered redundant because it’s the default role of that element.</p>
<h2>How to fix it in JSX</h2>
<p>Remove redundant ARIA role attribute.</p>
<h3>Code examples</h3>
<h4>Noncompliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
&lt;button role="button" onClick={handleClick}&gt;OK&lt;/button&gt;
</pre>
<h4>Compliant solution</h4>
<pre data-diff-id="1" data-diff-type="compliant">
&lt;button onClick={handleClick}&gt;OK&lt;/button&gt;
</pre>
<h2>Resources</h2>
<h3>Documentation</h3>
<ul>
<li> <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques">MDN - Using ARIA: Roles, states, and properties</a>
</li>
<li> <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles">MDN - ARIA roles (Reference)</a> </li>
</ul>
<h3>Standards</h3>
<ul>
<li> <a href="https://www.w3.org/TR/wai-aria-1.2/">W3C - Accessible Rich Internet Applications (WAI-ARIA) 1.2</a> </li>
</ul>

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"title": "No redundant ARIA role",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"a11y",
"react"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6822",
"sqKey": "S6822",
"scope": "All",
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
"S6811",
"S6819",
"S6821",
"S6822",
"S6824"
]
}

0 comments on commit 021ccd2

Please sign in to comment.