-
Notifications
You must be signed in to change notification settings - Fork 227
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 S6603: The collection-specific "TrueForAll" method should be used instead of the "All" extension #7163
Conversation
"location": { | ||
"uri": "sources\Automapper\src\AutoMapper\Configuration\MapperConfiguration.cs", | ||
"region": { | ||
"startLine": 473, |
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.
sonar-dotnet/analyzers/its/sources/AutoMapper/src/AutoMapper/Configuration/MapperConfiguration.cs
Line 473 in b529eb3
if (Profiles.All(x => x.Name != profileName)) |
"id": "S6603", | ||
"message": "The collection-specific "TrueForAll" method should be used instead of the "All" extension", | ||
"location": { | ||
"uri": "sources\Automapper\src\AutoMapper\Execution\ObjectFactory.cs", |
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.
sonar-dotnet/analyzers/its/sources/AutoMapper/src/AutoMapper/Execution/ObjectFactory.cs
Line 36 in b529eb3
var ctorWithOptionalArgs = type.GetDeclaredConstructors().FirstOrDefault(c => c.GetParameters().All(p => p.IsOptional)); |
"id": "S6603", | ||
"message": "The collection-specific "TrueForAll" method should be used instead of the "All" extension", | ||
"location": { | ||
"uri": "sources\Automapper\src\AutoMapper\Internal\TypeDetails.cs", |
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.
sonar-dotnet/analyzers/its/sources/AutoMapper/src/AutoMapper/Internal/TypeDetails.cs
Line 183 in b529eb3
public bool AllParametersOptional() => Parameters.All(p => p.IsOptional); |
"location": { | ||
"uri": "sources\Nancy\src\Nancy\Security\ClaimsPrincipalExtensions.cs", | ||
"region": { | ||
"startLine": 31, |
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.
sonar-dotnet/analyzers/its/sources/Nancy/src/Nancy/Security/ClaimsPrincipalExtensions.cs
Line 31 in b529eb3
return user != null && requiredClaims.All(user.HasClaim); |
"id": "S6603", | ||
"message": "The collection-specific "TrueForAll" method should be used instead of the "All" extension", | ||
"location": { | ||
"uri": "sources\Nancy\src\Nancy\Security\ClaimsPrincipalExtensions.cs", |
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.
sonar-dotnet/analyzers/its/sources/Nancy/src/Nancy/Security/ClaimsPrincipalExtensions.cs
Line 68 in b529eb3
return user != null && requiredRoles != null && requiredRoles.All(user.IsInRole); |
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.
Left some very small comments
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UseTrueForAll.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! Only waiting for the TryGetOperands
now 😄
b168c4d
to
936ccbd
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.
That's a pretty good test coverage 👍 only 2 more things
public void UseTrueForAll_CS_Immutable() => | ||
builderCS.AddPaths("UseTrueForAll.Immutable.cs") | ||
.AddReferences(MetadataReferenceFacade.SystemCollections) | ||
.WithOutputKind(OutputKind.DynamicallyLinkedLibrary) |
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.
Educational: what is the purpose of this?
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 do not have a main or top level statements, I split my logic in classes. So the compiler needs to know that there is no entrypoint for this compilation (aka it's a library).
If I added a single line of code, like: var x = 42;
above my code it would work as an executable, but it would not add much to the logic of the testcase.
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.
Actually, I'm not sure, all of those UTs are running fine without this line. I think you need the "single line of code" only using WithTopLevelStatements
where the compiler actually needs an entry point, but I think the functionality you mentioned is the default one
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 absolutely right, the default behavior of the builder is DynamicLinkedLibrary
. I did not see it because before I tried with top level statements, which as you said need at least a line of code. Thanks!
var nullableMethodBad = DoWork()?.All(x => true); // Noncompliant | ||
var inlineInitialization = new int[] { 42 }.All(x => true); // Noncompliant | ||
|
||
_ = immutable.Fluent().Fluent().Fluent().Fluent().All(x => true); //Noncompliant |
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.
Assignments are not needed and IMO they can be removed to visually simplify the tests
936ccbd
to
985c967
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
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'll leave you merge it when IsCorrectCall
coverage is improved/ the method is modified removing the null-check on Symbol
Fixes #7122