Skip to content

Conversation

@mary-georgiou-sonarsource
Copy link
Contributor

Fixes #9091

@mary-georgiou-sonarsource mary-georgiou-sonarsource marked this pull request as draft April 18, 2024 12:16
@mary-georgiou-sonarsource mary-georgiou-sonarsource force-pushed the mary/S6962 branch 5 times, most recently from 25a3cd2 to abd6ab6 Compare April 23, 2024 12:14
@mary-georgiou-sonarsource mary-georgiou-sonarsource marked this pull request as ready for review April 23, 2024 12:15
Copy link
Contributor

Choose a reason for hiding this comment

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

Good work!
My comments are mostly about readability, the logic and tests look very good.

|| node.Parent.IsKind(SyntaxKind.ArrowExpressionClause));

private static bool IsInConditionalCode(SyntaxNode node) =>
node.Ancestors().Any(x => x.IsAnyKind(SyntaxKind.IfStatement,

Choose a reason for hiding this comment

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

You are doing this .Ancestors().Any(x => x.IsAnyKind(...) check 4-5 times, please extract it in CSharpSyntaxHelper:

public static bool HasAncestorOfKind(this SyntaxNode syntaxNode, params SyntaxKind[] syntaxKinds) =>
  syntaxNode.Ancestors().Any(ancestor => ancestor.IsAnyKind(syntaxKinds));

Choose a reason for hiding this comment

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

See also

private static bool HasAncestor(SyntaxNode node, SyntaxKind kind) =>
node.FirstAncestorOrSelf<SyntaxNode>(x => x.IsKind(kind)) != null;

Copy link
Contributor Author

@mary-georgiou-sonarsource mary-georgiou-sonarsource Apr 24, 2024

Choose a reason for hiding this comment

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

I'll do it in a separate cleanup PR to replace it everywhere in sonar-dotnet if that's ok.
I saw there are quite some occurrences.

EDIT: I just saw Martin's comment. For some reason, it was not loaded earlier. I'm checking that option now.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, I left only one comment to in-line a method, please take a look.

@sonarqubecloud
Copy link

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@mary-georgiou-sonarsource mary-georgiou-sonarsource merged commit 682542b into master Apr 24, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource deleted the mary/S6962 branch April 24, 2024 12:04
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.

New rule S6962 for C#: You should pool HTTP connections with HttpClientFactory

3 participants