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
Fix S2190 FN: Support indexer, conversion operator and event declaration #8464
base: master
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Can you please increase the coverage and fix the 3 issues? |
I fixed the code smells and opened an issue for the rest of the FPs that remain in the file. Regarding the coverage I could not come up with any valid or invalid code snippet that would cover the cases, however I would rather leave it there as defensive coding than to create AD0001s if anything changes in Roslyn. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
Quality Gate failedFailed conditions 85.5% Coverage on New Code (required ≥ 95%) |
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.
Left few ideas to bump the coverage
IIncrementOrDecrementOperationWrapper.FromOperation(operation).OperatorMethod, | ||
OperationKindEx.Unary => | ||
IUnaryOperationWrapper.FromOperation(operation).OperatorMethod, | ||
OperationKindEx.Conversion=> |
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.
OperationKindEx.Conversion=> | |
OperationKindEx.Conversion => |
public void CheckForNoExitIndexer(SonarSyntaxNodeReportingContext c, IndexerDeclarationSyntax indexer, IPropertySymbol propertySymbol) | ||
{ | ||
// SonarCFG is out of support | ||
} |
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 these two methods can/should be tested by adding two compliant event/indexers UTs in InfiniteRecursion.SonarCfg
test file
OperationKindEx.Binary => | ||
IBinaryOperationWrapper.FromOperation(operation).OperatorMethod, | ||
OperationKindEx.Decrement => | ||
IIncrementOrDecrementOperationWrapper.FromOperation(operation).OperatorMethod, |
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.
It's weird because this line is tested in InfiniteRecursion.CSharp11.cs
through:
public class Decrement : IDecrementOperators<Decrement>
{
public static Decrement operator --(Decrement val) => --val; // Noncompliant
}
same for Unary:
public class BitWise : IBitwiseOperators<BitWise, BitWise, BitWise>
{
public static BitWise operator ~(BitWise value) => ~value; // Noncompliant
public static BitWise operator &(BitWise left, BitWise right) => left & right; // Noncompliant
public static BitWise operator |(BitWise left, BitWise right) => left | right; // Noncompliant
public static BitWise operator ^(BitWise left, BitWise right) => left ^ right; // Noncompliant
}
but the code coverage tool is not detecting those lines as covered.
c => | ||
{ | ||
var indexer = (IndexerDeclarationSyntax)c.Node; | ||
if (c.SemanticModel.GetDeclaredSymbol(indexer) is { } indexerSymbol) |
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.
We are registering for a declaration syntax node, looking at the documentation, I don't see how c.SemanticModel.GetDeclaredSymbol(indexer)
might return null
. I think we can avoid this check entirely and simply run:
checker.CheckForNoExitIndexer(c, indexer, c.SemanticModel.GetDeclaredSymbol(indexer));
c => | ||
{ | ||
var eventDeclaration = (EventDeclarationSyntax)c.Node; | ||
if (c.SemanticModel.GetDeclaredSymbol(eventDeclaration) is { } eventSymbol) |
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 above
property.ExpressionBody, | ||
property.AccessorList, | ||
property.Identifier.GetLocation(), |
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.
What about reducing the number of parameters of CheckForNoExit
by passing directly the MemberDeclarationSyntax
, and then retrieving all those properties within the method?
private static void CheckForNoExit(SonarSyntaxNodeReportingContext c, MemberDeclarationSyntax declarationSyntax, string arrowExpressionMessageArg, string accessorMessageArg)
Fixes #6642
Fixes #6643
Fixes #6644