Enable nullable types in Linux detector files#1709
Conversation
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
There was a problem hiding this comment.
Pull request overview
This PR enables nullable reference types across all Linux detector files by removing #nullable disable directives and adding the necessary nullable annotations to maintain type safety. This is part of the broader effort to enable nullable types throughout the codebase (as indicated by Nullable=enable in Directory.Build.props).
Changes:
- Removed
#nullable disablefrom all source files undersrc/Microsoft.ComponentDetection.Detectors/linux/and their corresponding test files - Added nullable annotations (
?and!) to return types, parameters, and local variables where needed (e.g., factoryCreateComponentmethods now returnTypedComponent?, helper methods returnstring?) - Updated test files to use
null!instead ofnullfor non-nullable constructor parameters and addedNotBeNull()assertions where needed
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/.../linux/ILinuxScanner.cs |
Removed #nullable disable |
src/.../linux/LinuxScanner.cs |
Removed #nullable disable; added null-forgiving ! after .Where() filter; changed error return from null to []; made CreateComponentWithLayers return tuple TypedComponent? |
src/.../linux/LinuxContainerDetector.cs |
Removed #nullable disable; added ! to Enum.GetName; simplified InvalidUserInputException to single-param ctor |
src/.../linux/LinuxApplicationLayerDetector.cs |
Removed #nullable disable; added ! to all Enum.GetName calls |
src/.../linux/Contracts/ImageScanningResult.cs |
Removed #nullable disable; ContainerDetails → ContainerDetails?; Components initialized to [] |
src/.../linux/Exceptions/MissingContainerDetailException.cs |
Removed #nullable disable |
src/.../linux/Factories/IArtifactComponentFactory.cs |
Removed #nullable disable; CreateComponent returns TypedComponent? |
src/.../linux/Factories/ArtifactComponentFactoryBase.cs |
Removed #nullable disable; abstract CreateComponent returns TypedComponent?; helper methods return string? |
src/.../linux/Factories/*.cs (9 factories) |
Removed #nullable disable; CreateComponent overrides return TypedComponent?; private helper return types updated |
test/.../LinuxScannerTests.cs |
Removed #nullable disable; added BeOfType and NotBeNull assertions |
test/.../LinuxContainerDetectorTests.cs |
Removed #nullable disable; updated Func<..., Exception?, string> in mock verifications |
test/.../LinuxApplicationLayerExperimentTests.cs |
Removed #nullable disable; changed null to null! for constructor args |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1709 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Enable nullable types in Linux detector files