Skip to content

Commit

Permalink
Update RSPEC (#6899)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsolt-kolbay-sonarsource authored Apr 18, 2023
1 parent 44ebcdf commit c16cb57
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions analyzers/rspec/cs/S3655_c#.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Nullable value types can hold either a value or <code>null</code>. The value held in the nullable type can be accessed with the <code>Value</code>
property or by casting it to the underlying type, but both operations throw an <code>InvalidOperationException</code> when the value is
<code>null</code>. To avoid the exception, a nullable type should always be tested before the value is accessed.</p>
property or by casting it to the underlying type. Still, both operations throw an <code>InvalidOperationException</code> when the value is
<code>null</code>. A nullable type should always be tested before the value is accessed to avoid the exception.</p>
<h2>Noncompliant Code Example</h2>
<pre>
public void Sample(bool condition)
Expand Down
2 changes: 1 addition & 1 deletion analyzers/rspec/cs/S3900_c#.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2>Compliant Solution</h2>

private void Xyzzy(MyOtherClass other)
{
this.other = other; // Compliant: method is not publicly accessible
this.other = other.Clone(); // Compliant: method is not publicly accessible
}
}
</pre>
Expand Down
40 changes: 19 additions & 21 deletions analyzers/rspec/vbnet/S3655_vb.net.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<p>Nullable value types can hold either a value or <code>Nothing</code>. The value stored in the nullable type can be accessed with the
<code>Value</code> property or by casting it to the underlying type. Still, both operations throw an <code>InvalidOperationException</code> when the
value is <code>Nothing</code>. A nullable type should always be tested before <code>Value</code> is accessed to avoid the exception.</p>
value is <code>Nothing</code>. A nullable type should always be tested before the value is accessed to avoid the exception.</p>
<h2>Noncompliant Code Example</h2>
<pre>
Dim nullable As Integer? = Nothing
Console.WriteLine(nullable.Value)
</pre>
<p>or</p>
<pre>
Dim nullable As Integer? = Nothing
Console.WriteLine(CType(nullable, Integer))
Sub Sample(condition As Boolean)
Dim nullableValue As Integer? = If(condition, 42, Nothing)
Console.WriteLine(nullableValue.Value) ' Noncompliant

Dim nullableCast As Integer? = If(condition, 42, Nothing)
Console.WriteLine(CType(nullableCast, Integer)) ' Noncompliant
End Sub
</pre>
<h2>Compliant Solution</h2>
<pre>
Dim nullable As Integer? = Nothing
If nullable.HasValue Then
Console.WriteLine(nullable.Value)
Console.WriteLine(CType(nullable, Integer))
End If
</pre>
<p>or</p>
<pre>
Dim nullable As Integer? = Nothing
If nullable &lt;&gt; Nothing Then
Console.WriteLine(nullable.Value)
Console.WriteLine(CType(nullable, Integer))
End If
Sub Sample(condition As Boolean)
Dim nullableValue As Integer? = If(condition, 42, Nothing)
If nullableValue.HasValue Then
Console.WriteLine(nullableValue.Value)
End If

Dim nullableCast As Integer? = If(condition, 42, Nothing)
If nullableCast.HasValue Then
Console.WriteLine(CType(nullableCast, Integer))
End If
End Sub
</pre>
<h2>See</h2>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion analyzers/src/SonarAnalyzer.CSharp/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"languages": [
"CSH"
],
"latest-update": "2023-04-14T14:24:26.209592400Z"
"latest-update": "2023-04-18T08:05:49.922275800Z"
}
2 changes: 1 addition & 1 deletion analyzers/src/SonarAnalyzer.VisualBasic/sonarpedia.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"languages": [
"VBNET"
],
"latest-update": "2023-04-14T14:24:45.993980100Z"
"latest-update": "2023-04-18T08:05:22.393227400Z"
}

0 comments on commit c16cb57

Please sign in to comment.