Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule S6824 (jsx-a11y/aria-unsupported-elements): No ARIA role or property for unsupported DOM elements #4275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
"file-for-rules:S6807.js": [
0
],
"file-for-rules:S6824.js": [
0
],
"file-for-rules:boundOrAssignedEvalOrArguments.js": [
0
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
"file-for-rules:S6807.js": [
2
],
"file-for-rules:S6824.js": [
2
],
"file-for-rules:boundOrAssignedEvalOrArguments.js": [
2,
8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"file-for-rules:S6824.js": [
4
]
}
6 changes: 6 additions & 0 deletions its/sources/jsts/custom/S6824.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
function MyComponent(){
return (
<title aria-hidden="false">My beautiful web page</title>
);
}
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 = "S6824")
public class AriaUnsupportedElementsCheck implements EslintBasedCheck {

@Override
public String eslintKey() {
return "aria-unsupported-elements";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static List<Class<? extends JavaScriptCheck>> getAllChecks() {
ArgumentsUsageCheck.class,
AriaProptypesCheck.class,
AriaRoleCheck.class,
AriaUnsupportedElementsCheck.class,
ArithmeticOperationReturningNanCheck.class,
ArrayCallbackWithoutReturnCheck.class,
ArrayConstructorsCheck.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<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>Each role in ARIA has a set of required attributes that must be included for the role to be properly understood by assistive technologies. These
attributes are known as "required aria-* properties".</p>
<p>For example, if an element has a role of "checkbox", it must also include the aria-checked property. This property indicates whether the checkbox
is checked (true), unchecked (false), or in a mixed state (mixed).</p>
<p>This rules checks that each element with a defined ARIA role also has all required attributes.</p>
<h2>How to fix it in JSX</h2>
<p>Check that each element with a defined ARIA role also has all required attributes.</p>
<pre data-diff-id="1" data-diff-type="noncompliant">
&lt;div role="checkbox"&gt;Unchecked&lt;/div&gt; {/* Noncompliant: aria-checked is missing */}
</pre>
<p>To fix the code add missing aria-* attributes.</p>
<pre data-diff-id="1" data-diff-type="compliant">
&lt;div role="checkbox" aria-checked={isChecked}&gt;Unchecked&lt;/div&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>
<li> <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes">MDN - ARIA states and properties (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,30 @@
{
"title": "No ARIA role or property for unsupported DOM elements",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"react",
"a11y"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-6824",
"sqKey": "S6824",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "targeted",
"code": {
"impacts": {
"MAINTAINABILITY": "LOW",
"RELIABILITY": "LOW"
},
"attribute": "CONVENTIONAL"
},
"compatibleLanguages": [
"JAVASCRIPT",
"TYPESCRIPT"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
"S6807",
"S6811",
"S6819",
"S6821"
"S6821",
"S6824"
]
}