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
New Rule S4545: "DebuggerDisplayAttribute" strings should reference existing members #6728
New Rule S4545: "DebuggerDisplayAttribute" strings should reference existing members #6728
Conversation
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.CSharp10.cs
Outdated
Show resolved
Hide resolved
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.
Nicely done! Those are some really detailed test cases.
I've only found some minor issues.
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.vb
Outdated
Show resolved
Hide resolved
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 couple more findings:
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/Rules/DebuggerDisplayUsesExistingMembersTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.cs
Show resolved
Hide resolved
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
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.
RSPEC needs to be updated i rspec repo and then also here
[DebuggerDisplay("Name: {FullName}")] | ||
public class Person | ||
{ | ||
public string FullName { get; private set; } | ||
} |
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.
Also here (comments are out of order, the the 3rd below first)
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.
Rest of the review.
I'll let @andrei-epure-sonarsource to do 2nd round and resolve my comments.
analyzers/src/SonarAnalyzer.CSharp/Facade/CSharpSyntaxFacade.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.VisualBasic/Facade/VisualBasicSyntaxFacade.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.CSharp9.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/Rules/DebuggerDisplayUsesExistingMembersTest.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Outdated
Show resolved
Hide resolved
44b4fd4
to
806874c
Compare
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.CSharp11.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.vb
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/DebuggerDisplayUsesExistingMembersBase.cs
Show resolved
Hide resolved
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.
806874c
to
bac7bf4
Compare
please check the quality gate :) |
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/DebuggerDisplayUsesExistingMembers.cs
Outdated
Show resolved
Hide resolved
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Code smellsI have removed the two methods I have forgotten, in the C# and VB.NET facades. class A1 { }
class A2 { }
partial class A { A1 P1; } // Compliant, with threshold 2
partial class A { A2 P2; }
partial class B { A1 P1; A2 P2; } // Noncompliant, with threshold 2 But this seems to me just a workaround. Any idea @andrei-epure-sonarsource ? |
CoverageRemoving the two unused methods in VB and C# facades has increased the coverage level, which is now > 95% overall.
That is not easy to test, without mocking @andrei-epure-sonarsource If you think it makes sense to cover that scenario, I would look into it. |
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
@antonioaversa you can resolve the SC S1200 issues as "won't fix" and then merge this (the gate will become green) all good on not covering the Regex exception |
Andrei took over the review
Fixes #6703
RSPEC: SonarSource/rspec#1571
Remarks:
Primary use is for types and assemblies.
While not recommended,
DebuggerDisplayAttribute
can be used on properties, fields, delegates, etc. c.p. https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerdisplayattribute?view=net-7.0When applied to properties or fields, the context is the one of the enclosing type:
It is unclear how it is supposed to be used/to work on
enum
: setting it in VS 2022 results in the debugger<Internal error evaluating expression>
.Expression of arbitrary complexity can be written in the attribute, involving 0 or more fields.
This implementation produces false negatives due to the following limitations:
value
, are not checked;value
, are not evaluated;this.Member
is not supported;1 + Member
, are not supported;aliases forDebuggerDisplayAttribute
are not supported;