Skip to content

Commit fbe6e30

Browse files
thomas-serre-sonarsourcesonartech
authored andcommitted
SONARPY-3753 Update RSPEC before 5.18 release (#868)
GitOrigin-RevId: 8d44684a869ce9601dfe0f9fc03882af9f5536b7
1 parent 759193c commit fbe6e30

File tree

295 files changed

+3899
-2892
lines changed

Some content is hidden

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

295 files changed

+3899
-2892
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ <h2>Why is this an issue?</h2>
44
3.0. Instead, the built-in <code>exec()</code> function can be used.</p>
55
<p>Use of the <code>exec</code> statement is strongly discouraged for several reasons such as:</p>
66
<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>
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 it
9+
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>
1414
</ul>
1515
<h3>Code examples</h3>
1616
<h4>Noncompliant code example</h4>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ <h4>Compliant solution</h4>
1414
<h2>Resources</h2>
1515
<h3>Documentation</h3>
1616
<ul>
17-
<li> Python Documentation: <a href="https://docs.python.org/2.7/reference/lexical_analysis.html#operators">Python 2.7 - Operators</a> </li>
17+
<li>Python Documentation: <a href="https://docs.python.org/2.7/reference/lexical_analysis.html#operators">Python 2.7 - Operators</a></li>
1818
</ul>
1919

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h2>Why is this an issue?</h2>
2929
<h2>Resources</h2>
3030
<h3>Documentation</h3>
3131
<ul>
32-
<li> <a href="https://peps.python.org/pep-0008/#class-names">PEP 8 – Style Guide for Python Code</a> </li>
33-
<li> <a href="https://en.wikipedia.org/wiki/Snake_case">Wikipedia: Snake case</a> </li>
32+
<li><a href="https://peps.python.org/pep-0008/#class-names">PEP 8 – Style Guide for Python Code</a></li>
33+
<li><a href="https://en.wikipedia.org/wiki/Snake_case">Wikipedia: Snake case</a></li>
3434
</ul>
3535

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ <h2>Why is this an issue?</h2>
33
<p>Exceptions handlers (<code>except</code>) are evaluated in the order they are written. Once a match is found, the evaluation stops.</p>
44
<p>In some contexts, an except block is dead code as it will never catch any exception:</p>
55
<ul>
6-
<li> If there is a handler for a base class followed by a handler for class derived from that base class, the second handler will never trigger: The
7-
handler for the base class will match the derived class, and will be the only executed handler. </li>
8-
<li> When multiple <code>except</code> statements try to catch the same exception class, only the first one will be executed. </li>
9-
<li> In Python 3, <code>BaseException</code> is the parent of every exception class. When a <code>BaseException</code> is caught by an
6+
<li>If there is a handler for a base class followed by a handler for class derived from that base class, the second handler will never trigger: The
7+
handler for the base class will match the derived class, and will be the only executed handler.</li>
8+
<li>When multiple <code>except</code> statements try to catch the same exception class, only the first one will be executed.</li>
9+
<li>In Python 3, <code>BaseException</code> is the parent of every exception class. When a <code>BaseException</code> is caught by an
1010
<code>except</code> clause, none of the subsequent <code>except</code> statement will catch anything. This is true as well for the bare except
11-
statement (<code>except:</code>). </li>
11+
statement (<code>except:</code>).</li>
1212
</ul>
1313
<h2>How to fix it</h2>
1414
<p>When using multiple <code>except</code> statements, make sure to:</p>
1515
<ul>
16-
<li> Order the <code>except</code> blocks from the most specialzed exception to the most generic, i.e when wanting to catch a
16+
<li>Order the <code>except</code> blocks from the most specialzed exception to the most generic, i.e when wanting to catch a
1717
<code>FloatingPointError</code> and an <code>ArithemticError</code>, as <code>FloatingPointError</code> is a subclass of
18-
<code>ArithmeticError</code>, the first <code>except</code> statement should be <code>FloatingPointError</code>. </li>
19-
<li> Catch the same exception only once. </li>
20-
<li> Catch a <code>BaseException</code> only once with either an <code>except BaseException:</code> statement or a bare <code>except:</code>
21-
statement, as the two statements are equivalent. </li>
18+
<code>ArithmeticError</code>, the first <code>except</code> statement should be <code>FloatingPointError</code>.</li>
19+
<li>Catch the same exception only once.</li>
20+
<li>Catch a <code>BaseException</code> only once with either an <code>except BaseException:</code> statement or a bare <code>except:</code>
21+
statement, as the two statements are equivalent.</li>
2222
</ul>
2323
<h3>Code examples</h3>
2424
<h4>Noncompliant code example</h4>
@@ -75,7 +75,7 @@ <h4>Compliant solution</h4>
7575
<h2>Resources</h2>
7676
<h3>Documentation</h3>
7777
<ul>
78-
<li> <a href="https://docs.python.org/3/reference/compound_stmts.html#the-try-statement">The <code>try</code> statement</a> </li>
79-
<li> <a href="https://docs.python.org/3/library/exceptions.html#exception-hierarchy">Exception hierarchy</a> </li>
78+
<li><a href="https://docs.python.org/3/reference/compound_stmts.html#the-try-statement">The <code>try</code> statement</a></li>
79+
<li><a href="https://docs.python.org/3/library/exceptions.html#exception-hierarchy">Exception hierarchy</a></li>
8080
</ul>
8181

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h2>Why is this an issue?</h2>
77
</pre>
88
<p>The solution can be to:</p>
99
<ul>
10-
<li> Split the function, method, or lambda into smaller ones </li>
10+
<li>Split the function, method, or lambda into smaller ones</li>
1111
</ul>
1212
<pre>
1313
# Each function does a part of what the original set_coordinates function was doing, so confusion risks are lower
@@ -18,7 +18,7 @@ <h2>Why is this an issue?</h2>
1818
# ...
1919
</pre>
2020
<ul>
21-
<li> Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain </li>
21+
<li>Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain</li>
2222
</ul>
2323
<pre>
2424
@dataclass

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ <h2>Why is this an issue?</h2>
1414
<h2>How to fix it</h2>
1515
<p>To fix this issue, make sure to throw specific exceptions that are relevant to the context in which they arise. It is recommended to either:</p>
1616
<ul>
17-
<li> Raise a specific <a href="https://docs.python.org/3/library/exceptions.html">Built-in exception</a> when one matches. For example
18-
<code>TypeError</code> should be raised when the type of a parameter is not the one expected. </li>
19-
<li> Create a custom exception class deriving from <code>Exception</code> or one of its subclasses. </li>
17+
<li>Raise a specific <a href="https://docs.python.org/3/library/exceptions.html">Built-in exception</a> when one matches. For example
18+
<code>TypeError</code> should be raised when the type of a parameter is not the one expected.</li>
19+
<li>Create a custom exception class deriving from <code>Exception</code> or one of its subclasses.</li>
2020
</ul>
2121
<h3>Code examples</h3>
2222
<h4>Noncompliant code example</h4>
@@ -34,7 +34,7 @@ <h4>Compliant solution</h4>
3434
<h2>Resources</h2>
3535
<h3>Documentation</h3>
3636
<ul>
37-
<li> Python Documentation - <a href="https://docs.python.org/3/library/exceptions.html#BaseException">Built-in exceptions</a> </li>
38-
<li> PEP 352 - <a href="https://www.python.org/dev/peps/pep-0352/#exception-hierarchy-changes">Required Superclass for Exceptions</a> </li>
37+
<li>Python Documentation - <a href="https://docs.python.org/3/library/exceptions.html#BaseException">Built-in exceptions</a></li>
38+
<li>PEP 352 - <a href="https://www.python.org/dev/peps/pep-0352/#exception-hierarchy-changes">Required Superclass for Exceptions</a></li>
3939
</ul>
4040

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ <h2>Why is this an issue?</h2>
99
<h2>Resources</h2>
1010
<h3>Documentation</h3>
1111
<ul>
12-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
12+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a></li>
1313
</ul>
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ <h3>Noncompliant code example</h3>
2222
</pre>
2323
<h2>Resources</h2>
2424
<ul>
25-
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a> </li>
25+
<li>CWE - <a href="https://cwe.mitre.org/data/definitions/546">CWE-546 - Suspicious Comment</a></li>
2626
</ul>
2727

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ <h3>Compliant solution</h3>
104104
</pre>
105105
<h2>Resources</h2>
106106
<ul>
107-
<li> Python documentation - <a href="https://docs.python.org/3/reference/compound_stmts.html#except">the <code>try</code> statement</a> </li>
107+
<li>Python documentation - <a href="https://docs.python.org/3/reference/compound_stmts.html#except">the <code>try</code> statement</a></li>
108108
</ul>
109109

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ <h2>Why is this an issue?</h2>
55
<p>Python has no real private methods. Every method is accessible. There are however two conventions indicating that a method is not meant to be
66
"public":</p>
77
<ul>
8-
<li> methods with a name starting with a single underscore (ex: <code>_mymethod</code>) should be seen as non-public and might change without prior
8+
<li>methods with a name starting with a single underscore (ex: <code>_mymethod</code>) should be seen as non-public and might change without prior
99
notice. They should not be used by third-party libraries or software. It is ok to use those methods inside the library defining them but it should
10-
be done with caution. </li>
11-
<li> "class-private" methods have a name which starts with at least two underscores and ends with at most one underscore. These methods' names will
10+
be done with caution.</li>
11+
<li>"class-private" methods have a name which starts with at least two underscores and ends with at most one underscore. These methods' names will
1212
be automatically mangled to avoid collision with subclasses' methods. For example <code>__mymethod</code> will be renamed as
1313
<code>_classname__mymethod</code>, where <code>classname</code> is the method’s class name without its leading underscore(s). These methods
14-
shouldn’t be used outside of their enclosing class. </li>
14+
shouldn’t be used outside of their enclosing class.</li>
1515
</ul>
1616
<p>This rule raises an issue when a class-private method (two leading underscores, max one underscore at the end) is never called inside the class.
1717
Class methods, static methods and instance methods will all raise an issue.</p>
@@ -53,7 +53,7 @@ <h4>Compliant solution</h4>
5353
</pre>
5454
<h2>Resources</h2>
5555
<ul>
56-
<li> <a href="https://docs.python.org/3.8/tutorial/classes.html#private-variables">Python documentation – Private Variables</a> </li>
57-
<li> <a href="https://www.python.org/dev/peps/pep-0008/#designing-for-inheritance">PEP8 – Designing for Inheritance</a> </li>
56+
<li><a href="https://docs.python.org/3.8/tutorial/classes.html#private-variables">Python documentation – Private Variables</a></li>
57+
<li><a href="https://www.python.org/dev/peps/pep-0008/#designing-for-inheritance">PEP8 – Designing for Inheritance</a></li>
5858
</ul>
5959

0 commit comments

Comments
 (0)