diff --git a/its/ruling/src/test/expected/jsts/console/typescript-S6854.json b/its/ruling/src/test/expected/jsts/console/typescript-S6854.json new file mode 100644 index 00000000000..f901ce1a2c8 --- /dev/null +++ b/its/ruling/src/test/expected/jsts/console/typescript-S6854.json @@ -0,0 +1,5 @@ +{ +"console:src/views/CLIAuthView/CLIAuthSuccessInitView/Left.tsx": [ +70 +] +} diff --git a/its/ruling/src/test/expected/jsts/courselit/javascript-S6854.json b/its/ruling/src/test/expected/jsts/courselit/javascript-S6854.json new file mode 100644 index 00000000000..c4e1b0927ce --- /dev/null +++ b/its/ruling/src/test/expected/jsts/courselit/javascript-S6854.json @@ -0,0 +1,5 @@ +{ +"courselit:packages/rich-text/src/Decorators/YouTube.js": [ +52 +] +} diff --git a/its/ruling/src/test/expected/jsts/courselit/typescript-S6854.json b/its/ruling/src/test/expected/jsts/courselit/typescript-S6854.json new file mode 100644 index 00000000000..6592cd4f399 --- /dev/null +++ b/its/ruling/src/test/expected/jsts/courselit/typescript-S6854.json @@ -0,0 +1,5 @@ +{ +"courselit:apps/web/components/public/lesson-viewer.tsx": [ +214 +] +} diff --git a/its/ruling/src/test/expected/jsts/desktop/typescript-S6854.json b/its/ruling/src/test/expected/jsts/desktop/typescript-S6854.json new file mode 100644 index 00000000000..23e728c559f --- /dev/null +++ b/its/ruling/src/test/expected/jsts/desktop/typescript-S6854.json @@ -0,0 +1,5 @@ +{ +"desktop:app/src/ui/lib/sandboxed-markdown.tsx": [ +369 +] +} diff --git a/its/ruling/src/test/expected/jsts/searchkit/javascript-S6854.json b/its/ruling/src/test/expected/jsts/searchkit/javascript-S6854.json new file mode 100644 index 00000000000..ac57d50ff44 --- /dev/null +++ b/its/ruling/src/test/expected/jsts/searchkit/javascript-S6854.json @@ -0,0 +1,5 @@ +{ +"searchkit:docs/src/pages/index.js": [ +398 +] +} 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 0bc6d1e1004..185d72b9c04 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 @@ -195,6 +195,7 @@ public static List> getAllChecks() { HtmlHasLangCheck.class, IdenticalExpressionOnBinaryOperatorCheck.class, IdenticalFunctionsCheck.class, + IframeHasTitleCheck.class, IgnoredReturnCheck.class, ImgRedundantAltCheck.class, ImmediatelyReturnedVariableCheck.class, @@ -205,8 +206,8 @@ public static List> getAllChecks() { IndexOfCompareToPositiveNumberCheck.class, InsecureCookieCheck.class, InsecureJwtTokenCheck.class, - InteractiveElementsShouldBeFocusableCheck.class, InstanceofInMisuseCheck.class, + InteractiveElementsShouldBeFocusableCheck.class, IntrusivePermissionsCheck.class, InvariantReturnCheck.class, InvertedAssertionArgumentsCheck.class, @@ -299,9 +300,9 @@ public static List> getAllChecks() { NoNestedSwitchCheck.class, NoNestedTemplateLiteralsCheck.class, NoNewNativeNonconstructorCheck.class, + NoNonInteractiveElementsWithHandlersCheck.class, NoNonNullAssertionCheck.class, NoNoninteractiveElementToInteractiveRoleCheck.class, - NoNonInteractiveElementsWithHandlersCheck.class, NoNoninteractiveTabindexCheck.class, NoOctalEscapeCheck.class, NoOneIterationLoopCheck.class, diff --git a/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/IframeHasTitleCheck.java b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/IframeHasTitleCheck.java new file mode 100644 index 00000000000..de139dda7fa --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/java/org/sonar/javascript/checks/IframeHasTitleCheck.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; + +@JavaScriptRule +@TypeScriptRule +@Rule(key = "S6854") +public class IframeHasTitleCheck implements EslintBasedCheck { + + @Override + public String eslintKey() { + return "iframe-has-title"; + } +} diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.html b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.html new file mode 100644 index 00000000000..5ac17a3d087 --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.html @@ -0,0 +1,34 @@ +

Why is this an issue?

+

An iframe, or inline frame, is an HTML document embedded inside another HTML document on a website. The iframe HTML element is often used to insert +content from another source, such as an advertisement, into a web page.

+

In the context of web accessibility, <iframe>'s should have a title attribute. This is because screen readers for +the visually impaired use this title to help users understand the content of the iframe.

+

Without a title, it can be difficult for these users to understand the context or purpose of the iframe’s content.

+

How to fix it

+

To fix missing iframe titles, you simply need to add a title attribute to your <iframe> element. The value of this +attribute should be a brief description of the iframe’s content.

+

Code examples

+

Noncompliant code example

+
+function iframe() {
+    return (
+        <iframe src="https://openweathermap.org"></iframe> // Noncompliant
+    );
+}
+
+

Compliant solution

+
+function iframe() {
+    return (
+        <iframe src="https://openweathermap.org" title="Weather forecasts, nowcasts and history"></iframe>
+    );
+}
+
+

Resources

+

Documentation

+ + diff --git a/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.json b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.json new file mode 100644 index 00000000000..2071054db29 --- /dev/null +++ b/sonar-plugin/javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6854.json @@ -0,0 +1,28 @@ +{ + "title": "iFrames must have a title", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + "accessibility", + "react" + ], + "defaultSeverity": "Minor", + "ruleSpecification": "RSPEC-6854", + "sqKey": "S6854", + "scope": "All", + "quickfix": "infeasible", + "code": { + "impacts": { + "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 978762e3fcd..be3f4d9fe96 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 @@ -320,6 +320,7 @@ "S6849", "S6850", "S6851", - "S6852" + "S6852", + "S6854" ] }