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

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

Merged
merged 8 commits into from
Apr 24, 2024

Conversation

mary-georgiou-sonarsource
Copy link
Contributor

Fixes #9091

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.

analyzers/rspec/cs/S6962.json Outdated Show resolved Hide resolved
|| 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

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.

analyzers/src/SonarAnalyzer.CSharp/ReuseClientBase.cs Outdated Show resolved Hide resolved
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.

Copy link

sonarcloud bot commented Apr 24, 2024

Copy link

sonarcloud bot commented Apr 24, 2024

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
25 checks passed
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