diff --git a/rules/S3063/csharp/rule.adoc b/rules/S3063/csharp/rule.adoc index 87b7b45eac9..f8a8d3c7ccb 100644 --- a/rules/S3063/csharp/rule.adoc +++ b/rules/S3063/csharp/rule.adoc @@ -28,7 +28,7 @@ or [source,csharp] ---- public void doSomething(List strings) { - StringBuilder sb = new StringBuilder(); // Noncompliant + StringBuilder sb = new StringBuilder(); sb.Append("Got: "); foreach(string str in strings) { sb.Append(str).Append(", "); @@ -42,7 +42,13 @@ public void doSomething(List 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 @@ -66,7 +72,7 @@ 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 @@ -74,4 +80,4 @@ if (false) { sb.ToString(); } ----- +---- \ No newline at end of file diff --git a/rules/S3063/vbnet/rule.adoc b/rules/S3063/vbnet/rule.adoc index 07a970ca7a7..9ea6ce3c05d 100644 --- a/rules/S3063/vbnet/rule.adoc +++ b/rules/S3063/vbnet/rule.adoc @@ -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 @@ -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 @@ -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