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

JS-145 Fix FP S6847 (no-noninteractive-element-interactions): Reduce the set of handlers to consider #4849

Merged
merged 1 commit into from
Sep 24, 2024
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 @@ -3,7 +3,6 @@
142
],
"ant-design:site/theme/template/Content/Demo/index.jsx": [
146,
379,
396,
416,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
"ant-design:components/alert/index.tsx": [
177
],
"ant-design:components/avatar/avatar.tsx": [
168
],
"ant-design:components/checkbox/Checkbox.tsx": [
120
],
"ant-design:components/radio/radio.tsx": [
68
],
"ant-design:site/theme/template/Content/Article.tsx": [
113
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
"desktop:app/src/ui/dialog/dialog.tsx": [
593
],
"desktop:app/src/ui/diff/image-diffs/image-container.tsx": [
23
],
"desktop:app/src/ui/dropdown-select-button.tsx": [
161
],
"desktop:app/src/ui/lib/avatar.tsx": [
223
],
"desktop:app/src/ui/lib/vertical-segmented-control/vertical-segmented-control.tsx": [
197
],
Expand Down
3 changes: 0 additions & 3 deletions its/ruling/src/test/expected/jsts/redux/javascript-S6847.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"redux:examples/todomvc/components/TodoItem.js": [
43
],
"redux:examples/todos-with-undo/components/Todo.js": [
6
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"vuetify:packages/vuetify/src/components/VImg/VImg.tsx": [
206
],
"vuetify:packages/vuetify/src/components/VRating/VRating.tsx": [
181
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package org.sonar.javascript.checks;

import java.util.Collections;
import java.util.List;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.Check;
import org.sonar.plugins.javascript.api.JavaScriptRule;
Expand All @@ -29,5 +32,12 @@
@Rule(key = "S6847")
public class NoNonInteractiveElementsWithHandlersCheck extends Check {


@Override
public List<Object> configurations() {
return Collections.singletonList(new Config());
}

private static class Config {
String[] handlers = {"onClick", "onMouseDown", "onMouseUp", "onKeyPress", "onKeyDown", "onKeyUp"};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ <h2>Why is this an issue?</h2>
difficult for users with disabilities to navigate and interact with the website. Additionally, these elements may not be focusable or provide visual
feedback when interacted with, resulting in a confusing and potentially frustrating user experience. Therefore, to maintain an accessible and
user-friendly website, event handlers should be used exclusively with interactive elements.</p>
<p>The rule only considers the handlers <code>onClick</code>, <code>onMouseDown</code>, <code>onMouseUp</code>, <code>onKeyPress</code>,
<code>onKeyDown</code>, and <code>onKeyUp</code>.</p>
<h2>How to fix it</h2>
<p>To fix this issue, remove the event handler from the non-interactive element and attach it to an interactive element instead. If the element is not
interactive, it should not have an event handler.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* SonarQube JavaScript Plugin
* Copyright (C) 2011-2024 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 static org.assertj.core.api.Assertions.assertThat;

import com.google.gson.Gson;
import org.junit.jupiter.api.Test;

class NoNonInteractiveElementsWithHandlersCheckTest {

@Test
void configurations() {
var config = new Gson().toJson(new NoNonInteractiveElementsWithHandlersCheck().configurations());
assertThat(config).isEqualTo("[{\"handlers\":[\"onClick\",\"onMouseDown\",\"onMouseUp\",\"onKeyPress\",\"onKeyDown\",\"onKeyUp\"]}]");
}
}