Skip to content

Commit f2d7419

Browse files
authored
Enable nullable in Linux detector files (#1709)
1 parent 3d2cdeb commit f2d7419

20 files changed

+101
-115
lines changed

src/Microsoft.ComponentDetection.Detectors/linux/Contracts/ImageScanningResult.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Contracts;
32

43
using System.Collections.Generic;
@@ -13,10 +12,10 @@ internal class ImageScanningResult
1312
/// <summary>
1413
/// Gets or sets the container details associated with the image scanning result.
1514
/// </summary>
16-
public ContainerDetails ContainerDetails { get; set; }
15+
public ContainerDetails? ContainerDetails { get; set; }
1716

1817
/// <summary>
1918
/// Gets or sets the collection of components detected during the image scanning process.
2019
/// </summary>
21-
public IEnumerable<DetectedComponent> Components { get; set; }
20+
public IEnumerable<DetectedComponent> Components { get; set; } = [];
2221
}

src/Microsoft.ComponentDetection.Detectors/linux/Exceptions/MissingContainerDetailException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Exceptions;
32

43
using System;

src/Microsoft.ComponentDetection.Detectors/linux/Factories/ArtifactComponentFactoryBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -19,14 +18,14 @@ public abstract class ArtifactComponentFactoryBase : IArtifactComponentFactory
1918
public abstract IEnumerable<string> SupportedArtifactTypes { get; }
2019

2120
/// <inheritdoc/>
22-
public abstract TypedComponent CreateComponent(ArtifactElement artifact, Distro distro);
21+
public abstract TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro);
2322

2423
/// <summary>
2524
/// Extracts license information from the artifact, checking both metadata and top-level licenses array.
2625
/// </summary>
2726
/// <param name="artifact">The artifact element from Syft output.</param>
2827
/// <returns>A comma-separated string of license values, or null if no licenses are found.</returns>
29-
protected static string GetLicenseFromArtifact(ArtifactElement artifact)
28+
protected static string? GetLicenseFromArtifact(ArtifactElement artifact)
3029
{
3130
// First try metadata.License which may be a string
3231
var license = artifact.Metadata?.License?.String;
@@ -50,7 +49,7 @@ protected static string GetLicenseFromArtifact(ArtifactElement artifact)
5049
/// </summary>
5150
/// <param name="artifact">The artifact element from Syft output.</param>
5251
/// <returns>The author or maintainer string, or null if neither is found.</returns>
53-
protected static string GetAuthorFromArtifact(ArtifactElement artifact)
52+
protected static string? GetAuthorFromArtifact(ArtifactElement artifact)
5453
{
5554
var author = artifact.Metadata?.Author;
5655
if (!string.IsNullOrEmpty(author))

src/Microsoft.ComponentDetection.Detectors/linux/Factories/CargoComponentFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -17,7 +16,7 @@ internal class CargoComponentFactory : ArtifactComponentFactoryBase
1716
public override IEnumerable<string> SupportedArtifactTypes => ["rust-crate"];
1817

1918
/// <inheritdoc/>
20-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
19+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2120
{
2221
if (artifact == null)
2322
{

src/Microsoft.ComponentDetection.Detectors/linux/Factories/CondaComponentFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -17,7 +16,7 @@ internal class CondaComponentFactory : ArtifactComponentFactoryBase
1716
public override IEnumerable<string> SupportedArtifactTypes => ["conda"];
1817

1918
/// <inheritdoc/>
20-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
19+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2120
{
2221
if (artifact == null)
2322
{

src/Microsoft.ComponentDetection.Detectors/linux/Factories/GoComponentFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -17,7 +16,7 @@ internal class GoComponentFactory : ArtifactComponentFactoryBase
1716
public override IEnumerable<string> SupportedArtifactTypes => ["go-module"];
1817

1918
/// <inheritdoc/>
20-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
19+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2120
{
2221
if (artifact == null)
2322
{

src/Microsoft.ComponentDetection.Detectors/linux/Factories/IArtifactComponentFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -30,5 +29,5 @@ public interface IArtifactComponentFactory
3029
/// <param name="artifact">The artifact element from Syft output.</param>
3130
/// <param name="distro">The distribution information from Syft output.</param>
3231
/// <returns>A TypedComponent instance, or null if the artifact cannot be processed.</returns>
33-
public TypedComponent CreateComponent(ArtifactElement artifact, Distro distro);
32+
public TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro);
3433
}

src/Microsoft.ComponentDetection.Detectors/linux/Factories/LinuxComponentFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -17,7 +16,7 @@ internal class LinuxComponentFactory : ArtifactComponentFactoryBase
1716
public override IEnumerable<string> SupportedArtifactTypes => ["apk", "deb", "rpm"];
1817

1918
/// <inheritdoc/>
20-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
19+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2120
{
2221
if (artifact == null || distro == null)
2322
{

src/Microsoft.ComponentDetection.Detectors/linux/Factories/MavenComponentFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -17,7 +16,7 @@ internal class MavenComponentFactory : ArtifactComponentFactoryBase
1716
public override IEnumerable<string> SupportedArtifactTypes => ["java-archive"];
1817

1918
/// <inheritdoc/>
20-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
19+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2120
{
2221
if (artifact == null)
2322
{
@@ -59,7 +58,7 @@ public override TypedComponent CreateComponent(ArtifactElement artifact, Distro
5958
/// Attempts to parse groupId and artifactId from a name in the format "groupId:artifactId"
6059
/// or similar Maven coordinate notation.
6160
/// </summary>
62-
private static bool TryParseFromName(string name, out string groupId, out string artifactId)
61+
private static bool TryParseFromName(string name, out string? groupId, out string? artifactId)
6362
{
6463
groupId = null;
6564
artifactId = null;

src/Microsoft.ComponentDetection.Detectors/linux/Factories/NpmComponentFactory.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#nullable disable
21
namespace Microsoft.ComponentDetection.Detectors.Linux.Factories;
32

43
using System.Collections.Generic;
@@ -18,7 +17,7 @@ internal class NpmComponentFactory : ArtifactComponentFactoryBase
1817
public override IEnumerable<string> SupportedArtifactTypes => ["npm"];
1918

2019
/// <inheritdoc/>
21-
public override TypedComponent CreateComponent(ArtifactElement artifact, Distro distro)
20+
public override TypedComponent? CreateComponent(ArtifactElement artifact, Distro distro)
2221
{
2322
if (artifact == null)
2423
{
@@ -41,7 +40,7 @@ public override TypedComponent CreateComponent(ArtifactElement artifact, Distro
4140
);
4241
}
4342

44-
private static NpmAuthor GetNpmAuthorFromArtifact(ArtifactElement artifact)
43+
private static NpmAuthor? GetNpmAuthorFromArtifact(ArtifactElement artifact)
4544
{
4645
var authorString = artifact.Metadata?.Author;
4746
if (!string.IsNullOrWhiteSpace(authorString))
@@ -52,7 +51,7 @@ private static NpmAuthor GetNpmAuthorFromArtifact(ArtifactElement artifact)
5251
return null;
5352
}
5453

55-
private static string GetHashFromArtifact(ArtifactElement artifact)
54+
private static string? GetHashFromArtifact(ArtifactElement artifact)
5655
{
5756
if (!string.IsNullOrWhiteSpace(artifact.Metadata?.Integrity))
5857
{

0 commit comments

Comments
 (0)