-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create rule S3063: Add vbnet language #1524
Conversation
SonarQube Quality Gate for 'rspec-tools' |
SonarQube Quality Gate for 'rspec-frontend' |
f03ca8b
to
cc40ef6
Compare
rules/S3063/csharp/rule.adoc
Outdated
@@ -1,16 +1,77 @@ | |||
include::../rule.adoc[] | |||
``++StringBuilder++`` instances that are never ``++ToString++``ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing ``++ToString++`` call added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``++StringBuilder++`` instances that are never ``++ToString++``ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing ``++ToString++`` call added. | |
`StringBuilder` instances that are never `ToString`ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing `ToString` call added. |
rules/S3063/csharp/rule.adoc
Outdated
(visible only on this page) | ||
[source,csharp] | ||
---- | ||
public void doSomething(List<string> strings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void doSomething(List<string> strings) { | |
public void DoSomething(List<string> strings) { |
rules/S3063/csharp/rule.adoc
Outdated
(visible only on this page) | ||
[source,csharp] | ||
---- | ||
public void doSomething(List<string> strings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void doSomething(List<string> strings) { | |
public void DoSomething(List<string> strings) { |
rules/S3063/csharp/rule.adoc
Outdated
or | ||
[source,csharp] | ||
---- | ||
public void doSomething(List<string> strings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void doSomething(List<string> strings) { | |
public void DoSomething(List<string> strings) { |
rules/S3063/csharp/rule.adoc
Outdated
[source,csharp] | ||
---- | ||
public void doSomething(List<string> strings) { | ||
StringBuilder sb = new StringBuilder(); // Noncompliant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringBuilder sb = new StringBuilder(); // Noncompliant | |
StringBuilder sb = new StringBuilder(); |
rules/S3063/vbnet/rule.adoc
Outdated
@@ -0,0 +1,75 @@ | |||
``++StringBuilder++`` instances that are never ``++ToString++``ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing ``++ToString++`` call added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``++StringBuilder++`` instances that are never ``++ToString++``ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing ``++ToString++`` call added. | |
`StringBuilder` instances that are never `ToString`ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing `ToString` call added. |
rules/S3063/vbnet/rule.adoc
Outdated
|
||
[source,vbnet] | ||
---- | ||
Public Sub doSomething(ByVal strings As List(Of String)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public Sub doSomething(ByVal strings As List(Of String)) | |
Public Sub DoSomething(ByVal strings As List(Of String)) |
rules/S3063/vbnet/rule.adoc
Outdated
|
||
[source,vbnet] | ||
---- | ||
Public Sub doSomething(ByVal strings As List(Of String)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public Sub doSomething(ByVal strings As List(Of String)) | |
Public Sub DoSomething(ByVal strings As List(Of String)) |
rules/S3063/vbnet/rule.adoc
Outdated
or | ||
[source,vbnet] | ||
---- | ||
Public Sub doSomething(ByVal strings As List(Of String)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public Sub doSomething(ByVal strings As List(Of String)) | |
Public Sub DoSomething(ByVal strings As List(Of String)) |
rules/S3063/vbnet/rule.adoc
Outdated
No issue is reported when ``++StringBuilder++`` is: | ||
|
||
* passed as method arguments, on the grounds that it will likely ``++ToString++``ed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issue is reported when ``++StringBuilder++`` is: | |
* passed as method arguments, on the grounds that it will likely ``++ToString++``ed there. | |
No issue is reported when `StringBuilder` is: | |
* passed as method arguments, on the grounds that it will likely `ToString`ed there. |
rules/S3063/csharp/rule.adoc
Outdated
@@ -1,16 +1,58 @@ | |||
include::../rule.adoc[] | |||
`StringBuilder` instances that are never `ToString`ed needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing `ToString` call added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://discuss.sonarsource.com/t/csharpsquid-s3063-description-seems-weird/13189 is complaining about
ToString
ed
being odd and I agree. Can you find a better wording?
rules/S3063/csharp/rule.adoc
Outdated
var sb = new StringBuilder(); // Compliant | ||
sb.GetChunks(); | ||
---- | ||
* passed as method argument, on the grounds that it will likely `ToString`ed there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToString
ed
rules/S3063/csharp/rule.adoc
Outdated
|
||
No issue is reported when `StringBuilder` is: | ||
|
||
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. | |
* accessed through a `CopyTo()` or `GetChunks()` invocation. |
rules/S3063/csharp/rule.adoc
Outdated
[source,csharp] | ||
---- | ||
var sb = new StringBuilder(); // Compliant | ||
sb.GetChunks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this example. The description is self-explanatory.
rules/S3063/csharp/rule.adoc
Outdated
sb.Append(str).Append(", "); | ||
// ... | ||
} | ||
_logger.LogInformation(sb.toString, DateTimeOffset.UtcNow); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ILogger.LogInformation doesn't require a DateTimeOffset.UtcNow
to be passed.
_logger.LogInformation(sb.toString, DateTimeOffset.UtcNow); | |
_logger.LogInformation(sb.toString); |
rules/S3063/csharp/rule.adoc
Outdated
* retrieved by a custom function | ||
[source,csharp] | ||
---- | ||
var sb = GetStringBuilder(); // Compliant | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* retrieved by a custom function | |
[source,csharp] | |
---- | |
var sb = GetStringBuilder(); // Compliant | |
---- | |
* retrieved by a custom function (`var sb = GetStringBuilder();`) |
rules/S3063/csharp/rule.adoc
Outdated
|
||
No issue is reported when `StringBuilder` is: | ||
|
||
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All items in a list should start with an uppercase and end with a dot (see e.g. https://github.com/SonarSource/rspec/blob/1b5fe36f3f98b48a9db7966ff6b6402d3db02242/rules/S6472/implementation.adoc)
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. | |
* Accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. |
rules/S3063/vbnet/rule.adoc
Outdated
|
||
No issue is reported when `StringBuilder` is: | ||
|
||
* accessed through a ``CopyTo()`` or ``GetChunks()`` invocation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as for C#
rules/S3063/csharp/rule.adoc
Outdated
@@ -1,16 +1,49 @@ | |||
include::../rule.adoc[] | |||
`StringBuilder` instances that are not accessed through a `ToString()` invocation needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing `ToString()` call should be added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe like this?
`StringBuilder` instances that are not accessed through a `ToString()` invocation needlessly clutter the code, and worse are a drag on performance. Either they should be removed, or the missing `ToString()` call should be added. | |
`StringBuilder` instances that never build a `string` clutter the code and worse are a drag on performance. Either they should be removed, or the missing `ToString()` call should be added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's better, thanks
rules/S3063/csharp/rule.adoc
Outdated
sb.Append(str).Append(", "); | ||
// ... | ||
} | ||
_logger.LogInformation(sb.toString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the _
is a violation of one of our rules.
_logger.LogInformation(sb.toString); | |
logger.LogInformation(sb.ToString()); |
rules/S3063/csharp/rule.adoc
Outdated
|
||
* Accessed through a `CopyTo()` or `GetChunks()` invocation. | ||
* Passed as method argument, on the grounds that it will likely accessed through a `ToString()` invocation there. | ||
* A parameter of the current method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* A parameter of the current method. | |
* Passed in as a parameter to the current method, on the grounds that the callee will materialize the string. |
rules/S3063/csharp/rule.adoc
Outdated
No issue is reported when `StringBuilder` is: | ||
|
||
* Accessed through a `CopyTo()` or `GetChunks()` invocation. | ||
* Passed as method argument, on the grounds that it will likely accessed through a `ToString()` invocation there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Passed as method argument, on the grounds that it will likely accessed through a `ToString()` invocation there. | |
* Passed as a method argument, on the grounds that it will likely be accessed through a `ToString()` invocation there. |
rules/S3063/csharp/rule.adoc
Outdated
|
||
No issue is reported when `StringBuilder` is: | ||
|
||
* Accessed through a `CopyTo()` or `GetChunks()` invocation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the Length access and the indexer access?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know; I was wondering the same. I decided to skip them to simplify the exception paragraph since both are not that common, but I might be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe like this?
* Accessed through a `CopyTo()` or `GetChunks()` invocation. | |
* Accessed through `sb.CopyTo()`, `sb.GetChunks()`, `sb.Length`, or `sb[index]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we get rid of the exception examples it's not that complicated anymore so maybe we can add them for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I only just saw your comment. I created a sub-list for them, but your suggestion may be better indeed, let me change that real quick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Some typos to fix left.
rules/S3063/vbnet/rule.adoc
Outdated
sb.Append(str).Append(", ") | ||
Next | ||
|
||
My.Application.Log.WriteEntry(sb.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My.Application.Log.WriteEntry(sb.toString()) | |
My.Application.Log.WriteEntry(sb.ToString()) |
rules/S3063/vbnet/rule.adoc
Outdated
No issue is reported when `StringBuilder` is: | ||
|
||
* Accessed through `sb.CopyTo()`, `sb.GetChunks()`, `sb.Length`, or `sb(index)`. | ||
* Passed as a method arguments, on the grounds that it will likely be accessed through a `ToString()` invocation there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Passed as a method arguments, on the grounds that it will likely be accessed through a `ToString()` invocation there. | |
* Passed as a method argument, on the grounds that it will likely be accessed through a `ToString()` invocation there. |
SonarQube Quality Gate for 'rspec-tools' |
SonarQube Quality Gate for 'rspec-frontend' |
You can preview this rule here (updated a few minutes after each push).