-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule S6750 (
no-render-return-value
): The return value of \"Reac…
…tDOM.render\" should not be used
- Loading branch information
1 parent
2afbb04
commit 31ac005
Showing
6 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"Joust:ts/Launcher.tsx": [ | ||
432 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...javascript-checks/src/main/java/org/sonar/javascript/checks/NoRenderReturnValueCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "S6750") | ||
public class NoRenderReturnValueCheck implements EslintBasedCheck { | ||
|
||
@Override | ||
public String eslintKey() { | ||
return "no-render-return-value"; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...avascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6750.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>In React, the <code>ReactDOM.render()</code> method is used to render a React component into a DOM element. It has a return value, but it’s | ||
generally recommended not to use it. The method might return a reference to the root <code>ReactComponent</code> instance, but it can be unpredictable | ||
and may not always be useful. Indeed, the return value can vary depending on the version of React you’re using and the specific circumstances in which | ||
it’s called.</p> | ||
<pre> | ||
const instance = ReactDOM.render(<App />, document.body); // Noncompliant: using the return value of 'ReactDOM.render' | ||
doSomething(instance); | ||
</pre> | ||
<pre> | ||
ReactDOM.render(<App />, document.body); | ||
</pre> | ||
<p>Alternatively, if you really need a reference to the root <code>ReactComponent</code> instance, the preferred solution is to attach a "callback | ||
ref" to the root element.</p> | ||
<pre> | ||
ReactDOM.render(<App />, document.body, callbackRef); | ||
</pre> | ||
<h2>Resources</h2> | ||
<h3>Documentation</h3> | ||
<ul> | ||
<li> <a href="https://legacy.reactjs.org/docs/react-dom.html#render">React - ReactDom#render</a> </li> | ||
<li> <a href="https://legacy.reactjs.org/docs/refs-and-the-dom.html#callback-refs">React - Callback Refs</a> </li> | ||
</ul> | ||
|
29 changes: 29 additions & 0 deletions
29
...avascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S6750.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"title": "The return value of \"ReactDOM.render\" should not be used", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"react" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6750", | ||
"sqKey": "S6750", | ||
"scope": "All", | ||
"quickfix": "infeasible", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "HIGH", | ||
"RELIABILITY": "MEDIUM", | ||
"SECURITY": "LOW" | ||
}, | ||
"attribute": "CONVENTIONAL" | ||
}, | ||
"compatibleLanguages": [ | ||
"JAVASCRIPT", | ||
"TYPESCRIPT" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,7 @@ | |
"S6746", | ||
"S6747", | ||
"S6748", | ||
"S6749" | ||
"S6749", | ||
"S6750" | ||
] | ||
} |