-
Notifications
You must be signed in to change notification settings - Fork 230
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 FP S3878: #6893 and #6894 #9395
Fix FP S3878: #6893 and #6894 #9395
Conversation
53c8632
to
6a3858a
Compare
@antonioaversa or @Tim-Pohlmann (whoever reviews) - all ITs are killed FPs. |
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.
As discussed, the FN on all reference types is too penalizing for this rule.
We should check the actual array type at the call site, and act differently in presence of reference type.
analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayPassedAsParams.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/ArrayPassedAsParamsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/ArrayPassedAsParamsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/TestCases/ArrayPassedAsParams.cs
Outdated
Show resolved
Hide resolved
2583d09
to
089156d
Compare
402882e
to
7361e8c
Compare
f696d63
to
7614e1b
Compare
e7eda3d
to
80d2ec3
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.
I am a bit confused with the flow: see here.
analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayPassedAsParams.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayPassedAsParams.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/ArrayPassedAsParamsBase.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/TestCases/ArrayPassedAsParams.cs
Outdated
Show resolved
Hide resolved
analyzers/tests/SonarAnalyzer.Test/TestCases/ArrayPassedAsParams.vb
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.Common/Rules/ArrayPassedAsParamsBase.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.
LGTM!
The new flow is easier to understand!
I left a minor comment here.
ArrayElementType(lastArgument, model) is { IsReferenceType: true } elementType | ||
&& !elementType.Is(KnownType.System_Object) | ||
&& parameterLookup.TryGetSyntax(param, out var arguments) | ||
&& arguments.Count() is 1; |
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.
arguments
should be an ImmutableArray
, which has the Length
property, which is definitely O(1).
Count
, however, is from LINQ and is in general O(n)
. While Count
should have optimized code for IList
implementers (several LINQ methods do), for arrays I would directly use Length
.
Quality Gate passed for 'Sonar .NET Java Plugin'Issues Measures |
Quality Gate passed for 'SonarAnalyzer for .NET'Issues Measures |
Fixes #6893
Fixes #6894