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.
| INamedTypeSymbol? dateTimeOffsetType = context.Compilation.GetTypeByMetadataName("System.DateTimeOffset"); | ||
| if (SymbolEqualityComparer.Default.Equals(containingType, dateTimeOffsetType)) |
There was a problem hiding this comment.
Inconsistent null handling compared to the AnalyzeObjectCreation method in the same file. While SymbolEqualityComparer.Default.Equals correctly handles null values and returns false, the AnalyzeObjectCreation method (lines 62-65) throws an InvalidOperationException if GetTypeByMetadataName returns null. Consider adding a similar null check here for consistency, or at minimum add a comment explaining why the different approaches are acceptable.
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
No description provided.