diff --git a/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S1451.json b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S1451.json index 4e576d3d835..1eb1eb93541 100644 --- a/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S1451.json +++ b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S1451.json @@ -185,6 +185,9 @@ "file-for-rules:S6807.js": [ 0 ], +"file-for-rules:S6824.js": [ +0 +], "file-for-rules:boundOrAssignedEvalOrArguments.js": [ 0 ] diff --git a/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S3798.json b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S3798.json index f5e6a8158e8..38627967854 100644 --- a/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S3798.json +++ b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S3798.json @@ -62,6 +62,9 @@ "file-for-rules:S6807.js": [ 2 ], +"file-for-rules:S6824.js": [ +2 +], "file-for-rules:boundOrAssignedEvalOrArguments.js": [ 2, 8 diff --git a/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S6824.json b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S6824.json new file mode 100644 index 00000000000..835c848ed1f --- /dev/null +++ b/its/ruling/src/test/expected/jsts/file-for-rules/javascript-S6824.json @@ -0,0 +1,5 @@ +{ +"file-for-rules:S6824.js": [ +4 +] +} diff --git a/its/sources/jsts/custom/S6824.js b/its/sources/jsts/custom/S6824.js new file mode 100644 index 00000000000..729716d72fb --- /dev/null +++ b/its/sources/jsts/custom/S6824.js @@ -0,0 +1,6 @@ +import React from 'react'; +function MyComponent(){ + return ( + My beautiful web page + ); +} diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/AriaUnsupportedElementsCheck.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/AriaUnsupportedElementsCheck.java new file mode 100644 index 00000000000..f2dedcbdfa9 --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/AriaUnsupportedElementsCheck.java @@ -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"; + } +} diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CheckList.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CheckList.java index 1c347003d0a..004fe3aaf43 100644 --- a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CheckList.java +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/CheckList.java @@ -67,6 +67,7 @@ public static List> getAllChecks() { ArgumentsUsageCheck.class, AriaProptypesCheck.class, AriaRoleCheck.class, + AriaUnsupportedElementsCheck.class, ArithmeticOperationReturningNanCheck.class, ArrayCallbackWithoutReturnCheck.class, ArrayConstructorsCheck.class, diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.html new file mode 100644 index 00000000000..25c017f54f2 --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.html @@ -0,0 +1,30 @@ +

Why is this an issue?

+

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.

+

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".

+

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).

+

This rules checks that each element with a defined ARIA role also has all required attributes.

+

How to fix it in JSX

+

Check that each element with a defined ARIA role also has all required attributes.

+
+<div role="checkbox">Unchecked</div> {/* Noncompliant: aria-checked is missing */}
+
+

To fix the code add missing aria-* attributes.

+
+<div role="checkbox" aria-checked={isChecked}>Unchecked</div>
+
+

Resources

+

Documentation

+ +

Standards

+ + diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.json new file mode 100644 index 00000000000..e0b8c4da2c9 --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6824.json @@ -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" + ] +} diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/Sonar_way_profile.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/Sonar_way_profile.json index 687a17a6a1b..be9a5206d84 100644 --- a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/Sonar_way_profile.json +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/Sonar_way_profile.json @@ -295,6 +295,7 @@ "S6807", "S6811", "S6819", - "S6821" + "S6821", + "S6824" ] }