-
Notifications
You must be signed in to change notification settings - Fork 468
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
Enable nullable reference types for the repo #3021
Conversation
src/Microsoft.CodeAnalysis.Analyzers/CSharp/CSharpImmutableObjectMethodAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.CodeAnalysis.Analyzers/Core/MetaAnalyzers/DiagnosticAnalyzerAttributeAnalyzer.cs
Outdated
Show resolved
Hide resolved
...ft.CodeQuality.Analyzers/CSharp/QualityGuidelines/CSharpUseLiteralsWhereAppropriate.Fixer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Security/DoNotUseInsecureDeserializerWithoutBinderBase.cs
Show resolved
Hide resolved
...CodeQuality.Analyzers/Core/ApiDesignGuidelines/CollectionsShouldImplementGenericInterface.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.CodeQuality.Analyzers/Core/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs
Outdated
Show resolved
Hide resolved
....CodeQuality.Analyzers/Core/ApiDesignGuidelines/DoNotRaiseExceptionsInUnexpectedLocations.cs
Outdated
Show resolved
Hide resolved
....CodeQuality.Analyzers/Core/ApiDesignGuidelines/DoNotRaiseExceptionsInUnexpectedLocations.cs
Outdated
Show resolved
Hide resolved
...Microsoft.CodeQuality.Analyzers/Core/ApiDesignGuidelines/OverrideMethodsOnComparableTypes.cs
Outdated
Show resolved
Hide resolved
...icrosoft.CodeQuality.Analyzers/Core/ApiDesignGuidelines/TypeNamesShouldNotMatchNamespaces.cs
Outdated
Show resolved
Hide resolved
@@ -61,6 +61,7 @@ public override void Initialize(AnalysisContext analysisContext) | |||
var lastField = fieldInitializer?.InitializedFields.LastOrDefault(); | |||
var fieldInitializerValue = fieldInitializer?.Value; | |||
if (fieldInitializerValue == null || | |||
lastField == 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.
💭 Could this one have been a bug? Maybe try to add a test to hit this case?
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.
Avoiding adding unit tests in this PR. I will leave this comment unresolved and file a followup bug to track any such cases.
...Microsoft.NetCore.Analyzers/Core/Performance/UsePropertyInsteadOfCountMethodWhenAvailable.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Security/DoNotReferSelfInSerializableClass.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/ThrownExceptionInfo.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/ThrownExceptionInfo.cs
Show resolved
Hide resolved
src/Utilities/Compiler/Options/CategorizedAnalyzerConfigOptions.cs
Outdated
Show resolved
Hide resolved
Change this to: if (variableInitializerOperation.Value == null
|| !sslProtocolsSymbol.Equals(variableInitializerOperation.Value.Type)) and then can get rid of the ? for valueOperation. (I think that makes more sense anyway. Thanks nullable reference!) Refers to: src/Microsoft.NetCore.Analyzers/Core/Security/SslProtocolsAnalyzer.cs:127 in 64aa452. [](commit_id = 64aa452, deletion_comment = False) |
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.
🚢 security analyzers look fine to me
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.
📝 Now at 212/322 files viewed
src/Microsoft.CodeAnalysis.Analyzers/CSharp/CSharpImmutableObjectMethodAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/CSharp/Runtime/CSharpUseOrdinalStringComparison.Fixer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Security/DoNotSerializeTypeWithPointerFields.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Security/DoNotDisableHttpClientCRLCheck.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Security/DoNotCallDangerousMethodsInDeserialization.cs
Outdated
Show resolved
Hide resolved
internal static SyntaxNode CreateOrdinalMemberAccess(SyntaxGenerator generator, SemanticModel model) | ||
{ | ||
INamedTypeSymbol stringComparisonType = model.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemStringComparison); | ||
INamedTypeSymbol stringComparisonType = model.Compilation.GetOrCreateTypeByMetadataName(WellKnownTypeNames.SystemStringComparison)!; |
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 is a fascinating case. We have several situations where the code fix relies on the analyzer behavior to ensure null will not be encountered. No request for a change here but eventually interested in seeing if the situation could be improved.
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.
Yes, totally agree. We need a follow-up PR to clean this up across the repo.
src/Microsoft.CodeQuality.Analyzers/Core/QualityGuidelines/AbstractRemoveEmptyFinalizers.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.
Now up to 248/322.
src/Microsoft.NetCore.Analyzers/Core/Runtime/DoNotPassLiteralsAsLocalizedParameters.cs
Outdated
Show resolved
Hide resolved
@@ -144,7 +144,7 @@ void AnalyzeArgument(IParameterSymbol parameter, IPropertySymbol containingPrope | |||
} | |||
|
|||
// FxCop compat: Filter out xml string literals. | |||
var filteredStrings = stringLiteralValues.Where(literal => !LooksLikeXmlTag(literal)); | |||
IEnumerable<string> filteredStrings = stringLiteralValues.Where(literal => literal != null && !LooksLikeXmlTag(literal))!; |
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.
💭 Was the lack of a null check here a bug in the analyzer? Any idea how we might have hit that case?
Not a big fan of the suppression here, but WhereNotNull
would be an additional allocation. Perhaps we're on a code path where it doesn't matter anyway so I'll leave the suggestion here:
IEnumerable<string> filteredStrings = stringLiteralValues.Where(literal => literal != null && !LooksLikeXmlTag(literal))!; | |
IEnumerable<string> filteredStrings = stringLiteralValues.WhereNotNull().Where(literal => !LooksLikeXmlTag(literal)); |
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.
Yep, it was a bug. I will keep this comment unresolved so we can track adding a regression test for this.
src/Microsoft.NetCore.Analyzers/Core/Runtime/SpecifyIFormatProvider.cs
Outdated
Show resolved
Hide resolved
if (variableInitializerOperation.Value != null | ||
&& !sslProtocolsSymbol.Equals(variableInitializerOperation.Value.Type)) | ||
if (variableInitializerOperation.Value == null | ||
|| !sslProtocolsSymbol.Equals(variableInitializerOperation.Value.Type)) |
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.
😕 Was this a bug? Should we have a test covering this condition?
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.
Yes, will add this comment to set of items that needs a regression test.
src/Microsoft.NetCore.Analyzers/Core/Runtime/DisposeObjectsBeforeLosingScope.cs
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Runtime/DisposeObjectsBeforeLosingScope.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Runtime/DisposableFieldsShouldBeDisposed.cs
Show resolved
Hide resolved
src/Microsoft.NetCore.Analyzers/Core/Runtime/DisposableFieldsShouldBeDisposed.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/PredicatedAnalysisData.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/CacheBasedEquatable.cs
Show resolved
Hide resolved
...ilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/TaintedDataAnalysis/TaintedDataSymbolMap.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DictionaryAnalysisData.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DictionaryAnalysisData.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AbstractLocation.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AbstractLocation.cs
Outdated
Show resolved
Hide resolved
...ilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs
Show resolved
Hide resolved
...ilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs
Show resolved
Hide resolved
...ilities/FlowAnalysis/FlowAnalysis/Analysis/ValueContentAnalysis/ValueContentAbstractValue.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AddressSharedEntitiesProvider.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AddressSharedEntitiesProvider.cs
Outdated
Show resolved
Hide resolved
...ities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityDataFlowOperationVisitor.cs
Outdated
Show resolved
Hide resolved
...ities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityDataFlowOperationVisitor.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DataFlowOperationVisitor.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DataFlowOperationVisitor.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DataFlowOperationVisitor.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DataFlowOperationVisitor.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/AnalysisEntityFactory.cs
Outdated
Show resolved
Hide resolved
...ysis/Analysis/PropertySetAnalysis/PropertySetAnalysis.PropertySetDataFlowOperationVisitor.cs
Show resolved
Hide resolved
...lowAnalysis/FlowAnalysis/Analysis/ParameterValidationAnalysis/ParameterValidationAnalysis.cs
Outdated
Show resolved
Hide resolved
...alidationAnalysis/ParameterValidationAnalysis.ParameterValidationDataFlowOperationVisitor.cs
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/DisposeAnalysis/DisposeAnalysisHelper.cs
Outdated
Show resolved
Hide resolved
src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/DisposeAnalysis/DisposeAnalysisHelper.cs
Outdated
Show resolved
Hide resolved
Ah, I accidentally fetched in sources from master :(. I will clean this up and update the PR over the weekend. |
15e8079
to
533b93e
Compare
The branch is now back to sane state. @sharwell Please let me know if you have any more feedback before I merge the PR. I will file a separate work item for adding tests for unresolved comments. |
{ | ||
SemanticModel model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); | ||
if (model.GetSymbolInfo((IdentifierNameSyntax)identifier, cancellationToken).Symbol is IMethodSymbol methodSymbol && CanAddStringComparison(methodSymbol, model)) | ||
if (model.GetSymbolInfo((IdentifierNameSyntax)identifier!, cancellationToken).Symbol is IMethodSymbol methodSymbol && CanAddStringComparison(methodSymbol, model)) |
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 suppression is not supposed to be needed. If it's not compiling for you with this removed, a compiler bug should be filed.
@dotnet-bot retest this please |
#pramga warning disable CS
or comments withTODO(dotpaul): Enable nullable analysis.
NOTE: PR targets 2.9.x branch. Once it flows into master, I will add remaining annotations in new code in master.