Skip to content

Commit 22c0e14

Browse files
authored
SONARPY-1425: Update rules metadata (#1542)
1 parent 769dba1 commit 22c0e14

File tree

270 files changed

+2106
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+2106
-529
lines changed

python-checks/src/main/java/org/sonar/python/checks/NoSonarCommentCheck.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
import static org.sonar.python.metrics.FileLinesVisitor.containsNoSonarComment;
2929

3030

31+
/*
32+
* When updating this rule through the rule-api the sqKey present in the NoSonar.json file
33+
* should be kept to `NoSonar` instead of `S1291`
34+
*/
3135
@Rule(key = "NoSonar")
32-
3336
public class NoSonarCommentCheck extends PythonSubscriptionCheck {
3437

3538
private static final String MESSAGE = "Is #NOSONAR used to exclude false-positive or to hide real quality flaw?";

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/BackticksUsage.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
<p>This rule raises an issue when backticks are used instead of <code>repr</code>.</p>
12
<h2>Why is this an issue?</h2>
2-
<p>Backticks are a deprecated alias for <code>repr()</code>. Don’t use them any more, the syntax was removed in Python 3.0.</p>
3+
<p>In Python 2, backticks are a deprecated alias for <code>repr()</code>. The syntax was removed in Python 3. To make the transition to Python 3
4+
easier, they should not be used anymore.</p>
35
<h3>Noncompliant code example</h3>
46
<pre>
57
return `num` # Noncompliant

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/BackticksUsage.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "Backticks should not be used",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "HIGH"
7+
},
8+
"attribute": "CONVENTIONAL"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Constant\/Issue",

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/CommentRegularExpression.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "Track comments matching a regular expression",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "MEDIUM"
7+
},
8+
"attribute": "CONVENTIONAL"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Constant\/Issue",
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
<p>This rule raises an issue when the exec statement is used.</p>
12
<h2>Why is this an issue?</h2>
23
<p>Use of the <code>exec</code> statement could be dangerous, and should be avoided. Moreover, the <code>exec</code> statement was removed in Python
34
3.0. Instead, the built-in <code>exec()</code> function can be used.</p>
4-
<h3>Noncompliant code example</h3>
5-
<pre>
5+
<p>Use of the <code>exec</code> statement is strongly discouraged for several reasons such as:</p>
6+
<ul>
7+
<li> <strong>Security Risks:</strong> Executing code from a string opens up the possibility of code injection attacks. </li>
8+
<li> <strong>Readability and Maintainability:</strong> Code executed with <code>exec</code> statement is often harder to read and understand since
9+
it is not explicitly written in the source code. </li>
10+
<li> <strong>Performance Implications:</strong> The use of <code>exec</code> statement can have performance implications since the code is compiled
11+
and executed at runtime. </li>
12+
<li> <strong>Limited Static Analysis:</strong> Since the code executed with <code>exec</code> statement is only known at runtime, static code
13+
analysis tools may not be able to catch certain errors or issues, leading to potential bugs. </li>
14+
</ul>
15+
<h3>Code examples</h3>
16+
<h4>Noncompliant code example</h4>
17+
<pre data-diff-id="1" data-diff-type="noncompliant">
618
exec 'print 1' # Noncompliant
719
</pre>
8-
<h3>Compliant solution</h3>
9-
<pre>
20+
<h4>Compliant solution</h4>
21+
<pre data-diff-id="1" data-diff-type="compliant">
1022
exec('print 1')
1123
</pre>
1224

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/ExecStatementUsage.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "The \"exec\" statement should not be used",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "HIGH"
7+
},
8+
"attribute": "CONVENTIONAL"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Constant\/Issue",

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/FunctionComplexity.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "Cyclomatic Complexity of functions should not be too high",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "HIGH"
7+
},
8+
"attribute": "FOCUSED"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Linear with offset",
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
<p>This rule raises an issue when the inequality operator <code>&lt;&gt;</code> is used.</p>
12
<h2>Why is this an issue?</h2>
2-
<p>The forms <code>&lt;&gt;</code> and <code>!=</code> are equivalent. But in Python 2.7.3 the <code>&lt;&gt;</code> form is considered obsolete.</p>
3-
<h3>Noncompliant code example</h3>
4-
<pre>
5-
return a &lt;&gt; b # Noncompliant
3+
<p>The operators <code>&lt;&gt;</code> and <code>!=</code> are equivalent. However, the <code>&lt;&gt;</code> operator is considered obsolete in
4+
Python 2.7 and has been removed from Python 3. Therefore, it is recommended to use <code>!=</code> instead.</p>
5+
<h3>Code examples</h3>
6+
<h4>Noncompliant code example</h4>
7+
<pre data-diff-id="1" data-diff-type="noncompliant">
8+
return a &lt;&gt; b # Noncompliant: the operator "&lt;&gt;" is deprecated.
69
</pre>
7-
<h3>Compliant solution</h3>
8-
<pre>
10+
<h4>Compliant solution</h4>
11+
<pre data-diff-id="1" data-diff-type="compliant">
912
return a != b
1013
</pre>
14+
<h2>Resources</h2>
15+
<h3>Documentation</h3>
16+
<ul>
17+
<li> Python Documentation: <a href="https://docs.python.org/2.7/reference/lexical_analysis.html#operators">Python 2.7 - Operators</a> </li>
18+
</ul>
1119

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/InequalityUsage.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "\"\u003c\u003e\" should not be used to test inequality",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "MEDIUM"
7+
},
8+
"attribute": "CONVENTIONAL"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Constant\/Issue",

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/LineLength.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"title": "Lines should not be too long",
33
"type": "CODE_SMELL",
4+
"code": {
5+
"impacts": {
6+
"MAINTAINABILITY": "MEDIUM"
7+
},
8+
"attribute": "FORMATTED"
9+
},
410
"status": "ready",
511
"remediation": {
612
"func": "Constant\/Issue",

0 commit comments

Comments
 (0)