-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
25a3cd2
to
abd6ab6
Compare
...ts/SonarAnalyzer.Test/TestCases/CloudNative/AzureFunctionsReuseClients.HttpClient.CSharp9.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.
Good work!
My comments are mostly about readability, the logic and tests look very good.
analyzers/tests/SonarAnalyzer.Test/Rules/AspNet/ControllersReuseClientTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/Rules/AspNet/ControllersReuseClientTest.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/TestCases/AspNet/ControllerReuseClient.CSharp12.cs
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/TestCases/AspNet/ControllersReuseClient.Csharp8.cs
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/ControllersReuseClient.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/ControllersReuseClient.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/ControllersReuseClient.cs
Outdated
Show resolved
Hide resolved
|| node.Parent.IsKind(SyntaxKind.ArrowExpressionClause)); | ||
|
||
private static bool IsInConditionalCode(SyntaxNode node) => | ||
node.Ancestors().Any(x => x.IsAnyKind(SyntaxKind.IfStatement, |
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.
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));
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.
See also
sonar-dotnet/analyzers/src/SonarAnalyzer.CSharp/Common/Walkers/MutedSyntaxWalker.cs
Lines 127 to 128 in f64e085
private static bool HasAncestor(SyntaxNode node, SyntaxKind kind) => | |
node.FirstAncestorOrSelf<SyntaxNode>(x => x.IsKind(kind)) != null; |
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'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.
3877a4a
to
0af2b71
Compare
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, I left only one comment to in-line a method, please take a look.
analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/ControllersReuseClient.cs
Outdated
Show resolved
Hide resolved
55ba381
to
db469d3
Compare
db469d3
to
c3d685e
Compare
Quality Gate passedIssues Measures |
Quality Gate passedIssues Measures |
Fixes #9091