Skip to content

Commit

Permalink
Add invocations exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianAmbrosini committed Feb 14, 2023
1 parent 9de270d commit cc40ef6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 10 additions & 4 deletions rules/S3063/csharp/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ or
[source,csharp]
----
public void doSomething(List<string> strings) {
StringBuilder sb = new StringBuilder(); // Noncompliant
StringBuilder sb = new StringBuilder();
sb.Append("Got: ");
foreach(string str in strings) {
sb.Append(str).Append(", ");
Expand All @@ -42,7 +42,13 @@ public void doSomething(List<string> strings) {

No issue is reported when ``++StringBuilder++`` is:

* passed as method arguments, on the grounds that it will likely ``++ToString++``ed there.
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation.
[source,csharp]
----
var sb = new StringBuilder(); // Compliant
sb.GetChunks();
----
* passed as method arguments, on the grounds that it will likely be accessed there.
[source,csharp]
----
var sb = new StringBuilder(); // Compliant
Expand All @@ -66,12 +72,12 @@ var sb = GetStringBuilder(); // Compliant
StringBuilder sb = new(); // Compliant
return sb;
----
* a local variable but the .ToString() call is unreachable
* a local variable but the access invocation call is unreachable
[source,csharp]
----
StringBuilder sb = new(); // Compliant
if (false)
{
sb.ToString();
}
----
----
12 changes: 9 additions & 3 deletions rules/S3063/vbnet/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[source,vbnet]
----
Public Sub doSomething(ByVal strings As List(Of String))
Dim sb As StringBuilder = New StringBuilder()
Dim sb As StringBuilder = New StringBuilder() ' Noncompliant
sb.Append("Got: ")
For Each str As String In strings
Expand Down Expand Up @@ -42,7 +42,13 @@ End Sub

No issue is reported when ``++StringBuilder++`` is:

* passed as method arguments, on the grounds that it will likely ``++ToString++``ed there.
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation.
[source,vbnet]
----
var sb = new StringBuilder(); // Compliant
sb.GetChunks()
----
* passed as method arguments, on the grounds that it will likely be accessed there.
[source,vbnet]
----
Dim sb = New StringBuilder() ' Compliant
Expand All @@ -65,7 +71,7 @@ Dim sb As StringBuilder = GetStringBuilder() ' Compliant
Dim sb = New StringBuilder() ' Compliant
Return sb
----
* a local variable but the .ToString() call is unreachable
* a local variable but the access invocation call is unreachable
[source,vbnet]
----
Dim sb As StringBuilder = New StringBuilder() ' Compliant
Expand Down

0 comments on commit cc40ef6

Please sign in to comment.