-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RSPEC before 9.2 release (#7297)
- Loading branch information
1 parent
d2ca13a
commit 9d55571
Showing
8 changed files
with
28 additions
and
40 deletions.
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 |
---|---|---|
@@ -1,23 +1,14 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>The size of a collection and the length of an array are always greater than or equal to zero. So testing that a size or 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 or array instead.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>The size of a collection and the length of an array are always greater than or equal to zero. Testing it doesn’t make sense, since the result is | ||
always <code>true</code>.</p> | ||
<pre> | ||
if(collection.Count >= 0){...} | ||
if(collection.Count >= 0){...} // Noncompliant: always true | ||
|
||
if(enumerable.Count() < 0){...} | ||
|
||
if(array.Length >= 0){...} | ||
|
||
bool result = array.Length >=0; | ||
if(array.Length >= 0){...} // Noncompliant: always true | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<p>Similarly testing that it is less than zero will always return <code>false</code>.</p> | ||
<pre> | ||
if (list.Any()) { ... } | ||
|
||
if (list.Count > 0) { ... } | ||
|
||
if (array.Length >= 42) { ... } | ||
if(enumerable.Count() < 0){...} // Noncompliant: always false | ||
</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
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 |
---|---|---|
|
@@ -208,6 +208,7 @@ | |
"S3926", | ||
"S3927", | ||
"S3928", | ||
"S3949", | ||
"S3963", | ||
"S3966", | ||
"S3971", | ||
|
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,20 +1,16 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>The size of a collection and the length of an array are always greater than or equal to zero. So testing that a size or 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 or array instead.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>The size of a collection and the length of an array are always greater than or equal to zero. Testing it doesn’t make sense, since the result is | ||
always <code>true</code>.</p> | ||
<pre> | ||
If Collection.Count >= 0 Then ... | ||
If Collection.Count >= 0 Then ... 'Noncompliant always true | ||
|
||
If Enumerable.Count < 0 Then ... | ||
|
||
If array.Length >= 0 Then ... | ||
|
||
Dim result As Boolean = Array.Length >= 0 | ||
If array.Length >= 0 Then ... 'Noncompliant always true | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<p>Similarly testing that it is less than zero will always return <code>false</code>.</p> | ||
<pre> | ||
If list.Count = 0 Then ... | ||
If array.Length >= 42 Then ... | ||
If Enumerable.Count < 0 Then ... 'Noncompliant always false | ||
|
||
Dim result As Boolean = Array.Length >= 0 'Noncompliant always true | ||
</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
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