Skip to content

Comments

feat: Enables Nullable Reference Types#401

Open
BenjaminMichaelis wants to merge 1 commit intomainfrom
bmichaelis/nullability
Open

feat: Enables Nullable Reference Types#401
BenjaminMichaelis wants to merge 1 commit intomainfrom
bmichaelis/nullability

Conversation

@BenjaminMichaelis
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings February 24, 2026 09:10
@BenjaminMichaelis BenjaminMichaelis self-assigned this Feb 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +45 to 46
INamedTypeSymbol? dateTimeOffsetType = context.Compilation.GetTypeByMetadataName("System.DateTimeOffset");
if (SymbolEqualityComparer.Default.Equals(containingType, dateTimeOffsetType))
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant