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
Modify rule S2445: Add C# description and samples #1570
Modify rule S2445: Add C# description and samples #1570
Conversation
ff5bc4b
to
e812315
Compare
e812315
to
685319b
Compare
SonarQube Quality Gate for 'rspec-tools' |
SonarQube Quality Gate for 'rspec-frontend' |
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
One note: shouldn't this be applied to VB.NET as well? Locking works there exactly the same way as it does in C# (with the SyncLock
keyword), and it seems like a simple rule.
While only C# is mentioned in the task, it surely could. If you and @mary-georgiou-sonarsource both agree, I would invest some time extending the implementation to VB.NET as well. |
In case this rule is valid also for VB.NET (I haven't checked) - IMO, it's better to create another issue regarding the VB.NET version of the rule and implement the C# part in way that the implementation can be re-used for the VB.NET (by putting the common code in a base class). |
Reporting the outcome of the discussion offline on the possibility of extending the rule to VB.NET. We are going to have a dedicated GitHub issue to implement this rule for VB.NET, rather than extending this GitHub issue. We are going to stick with the C#-specific implementation for the time being, since the effort to refactor the code into a base class is possibly 90% or more, of the effort to implement the VB.NET rule. |
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.
Round 1:
I'd update the description to match better the C# case.Seeing Pavel's comment regarding the title - I agree - leave as is.- Add in the example the case of the interned string
- Please add educational links in the RSPEC. For example: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/lock and https://learn.microsoft.com/en-us/dotnet/api/system.string.intern?view=net-7.0
You'll need to rebase on master for the pipeline to succeed.
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.
Cleanup
@pavel-mikula-sonarsource @mary-georgiou-sonarsource I addressed your comments and I am reassigning this PR back to you, although GitHub Checks are currently failing. The issue with the GitHub Checks seems to come from https://next.sonarqube.com/sonarqube/batch/index returning 503, rather than by actual issues with the adoc content itself. |
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.
- Refining a bit more the description
- One file probably needs reverting
- Please add the educational links
0066116
to
3496561
Compare
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.
Just a bit more decription refinement - looks good otherwise.
Yes, sure. I wasn't aware in what state the actual implementation PR is. |
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.
Final polishing
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
Is there a ticket created for the part that was left out? It should be in sonar-dotnet,labeled with the new rule idea |
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
Created SonarSource/sonar-dotnet#6804 |
… belongs to other classes
caa02e6
to
6c5beae
Compare
SonarQube Quality Gate for 'rspec-tools' |
SonarQube Quality Gate for 'rspec-frontend' |
Implementation #6750
Kept as draft as it is to be merged after the implementation.
Narrowed scope for C#
The definition of the rule for C# has been narrowed during the review.
Outcome of the offline discussion:
readonly
field to also beprivate
appears in the end too constraining;readonly
object), opting out the other (lock on a non-private
object);protected
, instead ofprivate
, to allow methods of a derived type to synchronize with methods of the base type, and you don't want to be forced to use properties to do that.For these reasons, we are changing the rule and narrowing its scope for C#: when locking on a field, that field should be
readonly
. Whether it's private or not, it won't matter for the implementation of this rule.