-
Notifications
You must be signed in to change notification settings - Fork 222
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 S1168 FP: Does not respect nullable annotations #6952
Fix S1168 FP: Does not respect nullable annotations #6952
Conversation
I know the current solution is not something that should be shipped. In // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
namespace StyleCop.Analyzers.Lightup
{
public readonly record struct NullabilityInfo
{
// ..
}
} Obviously that should become available in |
see also #6878 |
see also #6825 |
We track the implementation for this in #6825 The idea is to do something
Yes. Something like in TypeInfoExtensions needs to be created: public static class ITypeSymbolExtensions
{
public NullableAnnotation NullableAnnotation(this ITypeSymbol symbol) { }
} It is a bit easier as |
I could not find anything outside the CFG project. (I searched for |
You can have a look at this PR #6099. It shouldn't be as complicated in this case. A simple call to |
9e078e7
to
84d53c7
Compare
@martin-strecker-sonarsource I've changed the implementation of the |
84d53c7
to
e00084a
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.
Nice work, @Corniel! I just have some minor suggestions.
{ | ||
return FallbackAccessor; | ||
} | ||
if (!typeof(TProperty).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo())) |
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 is exactly what we need here!
analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs
Outdated
Show resolved
Hide resolved
analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
internal static class TypeHelper | ||
{ | ||
#region TypeKind | ||
private static readonly Func<ITypeSymbol, NullableAnnotation> NullableAnnotationAccessor = LightupHelpers.CreateSyntaxPropertyAccessor<ITypeSymbol, NullableAnnotation>(typeof(ITypeSymbol), nameof(NullableAnnotation)); |
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.
This line is too long.
…InsteadOfNull.cs Co-authored-by: Martin Strecker <103252490+martin-strecker-sonarsource@users.noreply.github.com>
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. @Corniel thank you for your contribution!
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Kudos, SonarCloud Quality Gate passed! |
SonarCloud Quality Gate failed. |
@martin-strecker-sonarsource Due to the updated indenting, some existing lines popped up that are not covered by existing unit tests. What to do?
|
The coverage is only about the non-whitespace changes and this case: |
I fully agree, but it is not my call, therefor the question. |
Peach validation:
That's an impressive list @Corniel Thank you for the contribution! |
Fixes #6878
Fixes #6825
Add a check on the return type to check nullability.