-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83b1d7a
commit c223d40
Showing
27 changed files
with
712 additions
and
382 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/LineLength.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Having to scroll horizontally makes it harder to get a quick overview and understanding of any piece of code.</p> | ||
<p>Scrolling horizontally to see a full line of code lowers the code readability.</p> | ||
|
7 changes: 3 additions & 4 deletions
7
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/OneStatementPerLine.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
11 changes: 5 additions & 6 deletions
11
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S100.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
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
7 changes: 4 additions & 3 deletions
7
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S104.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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to | ||
maintain. Above a specific threshold, it is strongly advised to refactor it into smaller pieces of code which focus on well defined tasks. Those | ||
smaller files will not only be easier to understand but also probably easier to test.</p> | ||
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and, therefore, to | ||
maintain.</p> | ||
<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 | ||
understand and easier to test.</p> | ||
|
10 changes: 6 additions & 4 deletions
10
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S108.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<h2>Why is this an issue?</h2> | ||
<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> | ||
<h3>Noncompliant code example</h3> | ||
<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 | ||
incomplete.</p> | ||
<pre> | ||
# Noncompliant: is the block empty on purpose, or is code missing? | ||
for i in range(3): | ||
pass | ||
</pre> | ||
<h3>Exceptions</h3> | ||
<p>When a block contains a comment, this block is not considered to be empty.</p> | ||
<p>Removing or filling the empty code blocks takes away ambiguity and generally results in a more straightforward and less surprising code. === | ||
Exceptions</p> | ||
<p>The rule ignores code blocks that contain comments.</p> | ||
|
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
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 |
---|---|---|
|
@@ -18,5 +18,5 @@ | |
546 | ||
] | ||
}, | ||
"quickfix": "unknown" | ||
"quickfix": "infeasible" | ||
} |
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
25 changes: 15 additions & 10 deletions
25
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2757.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 |
---|---|---|
@@ -1,22 +1,27 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>The use of operators pairs ( <code>=+</code> or <code>=-</code>) where the reversed, single operator was meant (<code>+=</code> or <code>-=</code>) | ||
will run fine, but not produce the expected results.</p> | ||
<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 | ||
one whitespace character after.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>Using operator pairs (<code>=+</code> or <code>=-</code>) that look like reversed single operators (<code>+=</code> or <code>-=</code>) is | ||
confusing. They compile and run but do not produce the same result as their mirrored counterpart.</p> | ||
<pre> | ||
target = -5 | ||
num = 3 | ||
|
||
target =- num # Noncompliant; target = -3. Is that really what's meant? | ||
target =+ num # Noncompliant; target = 3 | ||
target =- num # Noncompliant: target = -3. Is that really what's meant? | ||
target =+ num # Noncompliant: target = 3 | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<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 | ||
whitespace after.</p> | ||
<p>Replace the operators with a single one if that is the intention</p> | ||
<pre> | ||
target = -5 | ||
num = 3 | ||
|
||
target = -num # Compliant; intent to assign inverse value of num is clear | ||
target += num | ||
target -= num # target = -8 | ||
</pre> | ||
<p>Or fix the spacing to avoid confusion</p> | ||
<pre> | ||
target = -5 | ||
num = 3 | ||
|
||
target = -num # target = -3 | ||
</pre> | ||
|
2 changes: 1 addition & 1 deletion
2
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2757.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
23 changes: 7 additions & 16 deletions
23
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2761.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 |
---|---|---|
@@ -1,25 +1,16 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>Calling the <code>not</code> or <code>~</code> prefix operator twice might be redundant: the second invocation undoes the first. Such mistakes are | ||
typically caused by accidentally double-tapping the key in question without noticing. Either this is a bug, if the operator was actually meant to be | ||
called once, or misleading if done on purpose. Calling <code>not</code> twice is commonly done instead of using the dedicated "bool()" builtin | ||
function. However, the latter one increases the code readability and should be used.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>The repetition of a prefix operator (<code>not</code> or <code>~</code>) is usually a typo. The second operator invalidates the first one:</p> | ||
<pre> | ||
a = 0 | ||
b = False | ||
|
||
c = not not a # Noncompliant | ||
d = ~~b # Noncompliant | ||
a = False | ||
b = ~~a # Noncompliant: equivalent to "a" | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<p>While calling <code>not</code> twice is equivalent to calling the <code>bool()</code> built-in function, the latter increases the code readability, | ||
so it should be preferred.</p> | ||
<pre> | ||
a = 0 | ||
b = False | ||
|
||
c = bool(a) | ||
d = ~b | ||
b = not not a # Noncompliant: use bool() | ||
</pre> | ||
<h3>Exceptions</h3> | ||
<p>If the <code>~</code> function has been overloaded in a customised class and has been called twice, no warning is raised as it is assumed to be an | ||
expected usage.</p> | ||
<p>The rule does not raise an issue if the <code>~</code> function is overloaded in a customized class, as it is assumed to be the expected usage.</p> | ||
|
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
5 changes: 3 additions & 2 deletions
5
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S3776.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
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
21 changes: 7 additions & 14 deletions
21
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S3981.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 |
---|---|---|
@@ -1,23 +1,16 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>The length of a collection is always greater than or equal to zero. So testing that a length is greater than or equal to zero doesn’t make sense, | ||
since the result is always <code>true</code>. Similarly testing that it is less than zero will always return <code>false</code>. Perhaps the intent | ||
was to check the non-emptiness of the collection instead.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>The length of a collection is always greater than or equal to zero. Testing it doesn’t make sense, since the result is always | ||
<code>true</code>.</p> | ||
<pre> | ||
mylist = [] | ||
if len(myList) >= 0: # Noncompliant | ||
pass | ||
|
||
if len(myList) < 0: # Noncompliant | ||
if len(myList) >= 0: # Noncompliant: always true | ||
pass | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<p>Similarly testing that it is less than zero will always return <code>false</code>.</p> | ||
<pre> | ||
mylist = [] | ||
if len(myList) >= 42: | ||
pass | ||
|
||
if len(myList) == 0: | ||
if len(myList) < 0: # Noncompliant: always false | ||
pass | ||
---- | ||
</pre> | ||
<p>Fix the code to properly check for emptiness if it was the intent, or remove the redundant code to keep the current behavior.</p> | ||
|
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
21 changes: 10 additions & 11 deletions
21
python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S4144.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
Oops, something went wrong.