Skip to content
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 S2368 FP/FN: Don't raise for extension methods and raise for constructors #8152

Merged

Conversation

sagi1623
Copy link
Contributor

@sagi1623 sagi1623 commented Oct 6, 2023

Fixes #7329
And handles ordinary constructor support from #8083

@cristian-ambrosini-sonarsource
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@SonarSource SonarSource deleted a comment from azure-pipelines bot Oct 9, 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to bump a bit the coverage to reach >95%


protected override SyntaxToken GetIdentifier(MethodStatementSyntax method) => method.Identifier;
protected override Location GetIssueLocation(SyntaxNode node) =>
node?.RemoveParentheses() switch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are passing c.Node to the method which should be not null by design, so ? can be removed


protected override SyntaxToken GetIdentifier(MethodStatementSyntax method) => method.Identifier;
protected override Location GetIssueLocation(SyntaxNode node) =>
node?.RemoveParentheses() switch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for RemoveParentheses(), we are passing a MethodDeclaration or a ConstructorDeclaration so most probably it's not needed and can be removed

protected override Location GetIssueLocation(SyntaxNode node) =>
node?.RemoveParentheses() switch
{
ConstructorBlockSyntax x => x.SubNewStatement.NewKeyword.GetLocation(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic could be also rewritten as a ternary, something similar to:

protected override Location GetIssueLocation(SyntaxNode node) =>
    node is ConstructorBlockSyntax x
        ? x.SubNewStatement.NewKeyword.GetLocation()
        : Language.Syntax.NodeIdentifier(node)?.GetLocation();

@cristian-ambrosini-sonarsource
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.0% 95.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cristian-ambrosini-sonarsource cristian-ambrosini-sonarsource merged commit 5bf048e into SonarSource:master Oct 18, 2023
24 checks passed
@sagi1623 sagi1623 deleted the AraGimLeg/S2368 branch November 2, 2023 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix S2368 FP: Do not raise on extension methods when "this" is multidimensional array
2 participants