feat: Enables Nullable Reference Types#401
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enables Nullable Reference Types (NRT) across the entire IntelliTect.Analyzer codebase by adding <Nullable>enable</Nullable> to Directory.Build.props and updating all affected code to properly handle nullable annotations. The changes ensure type safety by explicitly marking nullable types and adding appropriate null checks throughout the codebase.
Changes:
- Enabled nullable reference types in Directory.Build.props for all projects
- Updated analyzers with nullable annotations and null safety checks
- Enhanced code fixes with proper nullable handling and graceful degradation patterns
- Improved test infrastructure with nullable annotations and ArgumentNullException.ThrowIfNull validation
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Directory.Build.props | Added <Nullable>enable</Nullable> to enable nullable reference types project-wide |
| UnusedLocalVariable.cs | Added null check for DataFlowAnalysis result from AnalyzeDataFlow |
| BanImplicitDateTimeToDateTimeOffsetConversion.cs | Added nullable annotation to GetTypeByMetadataName result |
| AttributesOnSeparateLines.cs (Analyzer) | Added null checks for ApplicationSyntaxReference and null-conditional operator for AttributeClass.Name |
| AsyncVoid.cs (Analyzer) | Improved pattern matching using is not pattern for cleaner null handling |
| AnalyzerBlockMixins.cs | Updated return types and intermediate variables with nullable annotations |
| DiagnosticVerifier.cs | Added nullable annotations and ArgumentNullException.ThrowIfNull validation |
| CodeFixVerifier.cs | Added nullable annotations, ArgumentNullException.ThrowIfNull, and null-forgiving operators on Task.Result |
| DiagnosticVerifier.Helper.cs | Added null checks with InvalidOperationException for compilation operations |
| CodeFixVerifier.Helper.cs | Added null checks with InvalidOperationException for document and semantic model operations |
| AnalyzerTests.cs | Added null check for compilation result |
| NamingIdentifierPascal.cs | Added graceful degradation by returning original solution when null checks fail |
| NamingFieldPascalUnderscore.cs | Added graceful degradation by returning original solution when null checks fail |
| AttributesOnSeparateLines.cs (CodeFix) | Added null checks for syntax root and null-forgiving operators for Parent navigation |
| AsyncVoid.cs (CodeFix) | Added null checks for syntax root and method declaration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ect.Analyzer/IntelliTect.Analyzer/Analyzers/BanImplicitDateTimeToDateTimeOffsetConversion.cs
Show resolved
Hide resolved
IntelliTect.Analyzer/IntelliTect.Analyzer.CodeFixes/AttributesOnSeparateLines.cs
Outdated
Show resolved
Hide resolved
Enables Nullable Reference Types throughout the project. Adds null checks and throws exceptions where syntax root or semantic model retrieval fails, improving code safety and preventing potential null reference exceptions.
ff59bca to
6289bb0
Compare
|
@copilot fix any code comments/issues that you find from this pr review |
|
@BenjaminMichaelis I've opened a new pull request, #406, to work on those changes. Once the pull request is ready, I'll request review from you. |
…onversion AnalyzeObjectCreation now uses null-check and returns early instead of throwing InvalidOperationException, consistent with AnalyzeInvocation null handling.
- SymbolMixins: INamedTypeSymbol -> INamedTypeSymbol? for GetTypeByMetadataName result - FavorDirectoryEnumerationCalls code fix: nullable-annotate root, invocation, semanticModel, oldRoot, parent, returnType, and IParameterSymbol? targetParam - DiagnosticVerifier.Helper: MetadataReference? field/return type and string? runtimeDir
GetTypeByMetadataName can return null if the type is not in the compilation. Previously the nullable result was passed directly to SymbolEqualityComparer, silently producing a wrong result. Now returns early, consistent with AnalyzeObjectCreation.
Add test coverage for DateTime? compared against DateTimeOffset and DateTimeOffset? in binary comparison expressions, which were previously untested edge cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
No description provided.