Skip to content

Commit c223d40

Browse files
Update rules metadata (#1497)
1 parent 83b1d7a commit c223d40

27 files changed

+712
-382
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Having to scroll horizontally makes it harder to get a quick overview and understanding of any piece of code.</p>
2+
<p>Scrolling horizontally to see a full line of code lowers the code readability.</p>
33

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<h2>Why is this an issue?</h2>
2-
<p>For better readability, do not put more than one statement on a single line.</p>
3-
<h3>Noncompliant code example</h3>
2+
<p>Putting multiple statements on a single line lowers the code readability and makes debugging the code more complex.</p>
43
<pre>
5-
if (True): print("hello")
4+
if (True): print("hello") # Noncompliant
65
</pre>
7-
<h3>Compliant solution</h3>
6+
<p>Write one statement per line to improve readability.</p>
87
<pre>
98
if (True):
109
print("hello")

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Sharing some naming conventions is a key point to make it possible for a team to efficiently collaborate. This rule allows to check that all method
3-
names match a provided regular expression.</p>
4-
<h3>Noncompliant code example</h3>
5-
<p>With default provided regular expression: <code>^[a-z_][a-z0-9_]*$</code></p>
2+
<p>Shared naming conventions allow teams to collaborate efficiently.</p>
3+
<p>This rule raises an issue when a method name does not match a provided regular expression.</p>
4+
<p>For example, with the default provided regular expression <code>^[a-z_][a-z0-9_]*$</code>, the method:</p>
65
<pre>
76
class MyClass:
8-
def MyMethod(a,b):
7+
def MyMethod(a,b): # Noncompliant
98
...
109
</pre>
11-
<h3>Compliant solution</h3>
10+
<p>should be renamed to</p>
1211
<pre>
1312
class MyClass:
1413
def my_method(a,b):
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Shared coding conventions allow teams to collaborate effectively. This rule allows to check that all class names match a provided regular
3-
expression.</p>
4-
<p>The default regular expression is based on PEP-8 standard. It allows "CapWords" convention and "snake_case" in lowercase. The "snake_case"
5-
convention is accepted by PEP-8 when the class is primarily used as a callable (ex: decorator, context manager, etc…​). However the "CapWords"
6-
convention is recommended in every case.</p>
7-
<h3>Noncompliant code example</h3>
8-
<p>With default provided regular expression <code>^_?([A-Z_][a-zA-Z0-9]*|[a-z_][a-z0-9_]*)$</code>:</p>
2+
<p>Shared naming conventions allow teams to collaborate efficiently.</p>
3+
<p>This rule raises an issue when a class name does not match a provided regular expression.</p>
4+
<p>The default regular expression allows the "CapWords" convention and the "snake_case" in lowercase. The style guide PEP-8 recommends using the
5+
"CapWords" convention in every case but also accepts the "snake_case" convention when the class is primarily used as a callable (ex: decorator,
6+
context manager, etc…​).</p>
7+
<p>For example, with the default provided regular expression <code>^_?([A-Z_][a-zA-Z0-9]*|[a-z_][a-z0-9_]*)$</code>, the classes:</p>
98
<pre>
109
class myClass: # Noncompliant
1110
...
@@ -16,7 +15,7 @@ <h3>Noncompliant code example</h3>
1615
def __exit__(self, type, value, traceback):
1716
pass
1817
</pre>
19-
<h3>Compliant solution</h3>
18+
<p>should be renamed to</p>
2019
<pre>
2120
class MyClass:
2221
...
@@ -27,4 +26,10 @@ <h3>Compliant solution</h3>
2726
def __exit__(self, type, value, traceback):
2827
pass
2928
</pre>
29+
<h2>Resources</h2>
30+
<h3>Documentation</h3>
31+
<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>
34+
</ul>
3035

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<h2>Why is this an issue?</h2>
2-
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to
3-
maintain. Above a specific threshold, it is strongly advised to refactor it into smaller pieces of code which focus on well defined tasks. Those
4-
smaller files will not only be easier to understand but also probably easier to test.</p>
2+
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and, therefore, to
3+
maintain.</p>
4+
<p>Above a specific threshold, refactor the file into smaller files whose code focuses on well-defined tasks. Those smaller files will be easier to
5+
understand and easier to test.</p>
56

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.</p>
3-
<h3>Noncompliant code example</h3>
2+
<p>An empty code block is confusing. It will require some effort from maintainers to determine if it is intentional or indicates the implementation is
3+
incomplete.</p>
44
<pre>
5+
# Noncompliant: is the block empty on purpose, or is code missing?
56
for i in range(3):
67
pass
78
</pre>
8-
<h3>Exceptions</h3>
9-
<p>When a block contains a comment, this block is not considered to be empty.</p>
9+
<p>Removing or filling the empty code blocks takes away ambiguity and generally results in a more straightforward and less surprising code. ===
10+
Exceptions</p>
11+
<p>The rule ignores code blocks that contain comments.</p>
1012

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ <h2>Why is this an issue?</h2>
22
<p><code>FIXME</code> tags are commonly used to mark places where a bug is suspected, but which the developer wants to deal with later.</p>
33
<p>Sometimes the developer will not have the time or will simply forget to get back to that tag.</p>
44
<p>This rule is meant to track those tags and to ensure that they do not go unnoticed.</p>
5-
<h3>Noncompliant code example</h3>
65
<pre>
76
def divide(numerator, denominator):
87
return numerator / denominator # FIXME denominator value might be 0
98
</pre>
109
<h2>Resources</h2>
10+
<h3>Documentation</h3>
1111
<ul>
12-
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546</a> - Suspicious Comment </li>
12+
<li> <a href="https://cwe.mitre.org/data/definitions/546">MITRE, CWE-546 - Suspicious Comment</a> </li>
1313
</ul>
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
546
1919
]
2020
},
21-
"quickfix": "unknown"
21+
"quickfix": "infeasible"
2222
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"ruleSpecification": "RSPEC-2190",
1414
"sqKey": "S2190",
1515
"scope": "All",
16-
"quickfix": "unknown"
16+
"quickfix": "infeasible"
1717
}
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
<h2>Why is this an issue?</h2>
2-
<p>The use of operators pairs ( <code>=+</code> or <code>=-</code>) where the reversed, single operator was meant (<code>+=</code> or <code>-=</code>)
3-
will run fine, but not produce the expected results.</p>
4-
<p>This rule raises an issue when <code>=+</code> or <code>=-</code> is used without any spacing between the two operators and when there is at least
5-
one whitespace character after.</p>
6-
<h3>Noncompliant code example</h3>
2+
<p>Using operator pairs (<code>=+</code> or <code>=-</code>) that look like reversed single operators (<code>+=</code> or <code>-=</code>) is
3+
confusing. They compile and run but do not produce the same result as their mirrored counterpart.</p>
74
<pre>
85
target = -5
96
num = 3
107

11-
target =- num # Noncompliant; target = -3. Is that really what's meant?
12-
target =+ num # Noncompliant; target = 3
8+
target =- num # Noncompliant: target = -3. Is that really what's meant?
9+
target =+ num # Noncompliant: target = 3
1310
</pre>
14-
<h3>Compliant solution</h3>
11+
<p>This rule raises an issue when <code>=+</code> or <code>=-</code> are used without any space between the operators and when there is at least one
12+
whitespace after.</p>
13+
<p>Replace the operators with a single one if that is the intention</p>
1514
<pre>
1615
target = -5
1716
num = 3
1817

19-
target = -num # Compliant; intent to assign inverse value of num is clear
20-
target += num
18+
target -= num # target = -8
19+
</pre>
20+
<p>Or fix the spacing to avoid confusion</p>
21+
<pre>
22+
target = -5
23+
num = 3
24+
25+
target = -num # target = -3
2126
</pre>
2227

0 commit comments

Comments
 (0)