diff --git a/.editorconfig b/.editorconfig index 800658ef..48c5b234 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1027,14 +1027,6 @@ dotnet_diagnostic.IDE0090.severity = suggestion # IDE0110: Discard can be removed dotnet_diagnostic.IDE0110.severity = suggestion -# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0120 -# IDE0120: Simplify LINQ expression -dotnet_diagnostic.IDE0120.severity = suggestion - -# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0200 -# IDE0200: Lambda expression can be simplified -dotnet_diagnostic.IDE0200.severity = suggestion - # https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0220 # IDE0220: 'foreach' statement implicitly converts '...' to '...' dotnet_diagnostic.IDE0220.severity = suggestion @@ -1043,10 +1035,6 @@ dotnet_diagnostic.IDE0220.severity = suggestion # IDE0251: Member can be made 'readonly' dotnet_diagnostic.IDE0251.severity = suggestion -# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0270 -# IDE0270: Null check can be simplified -dotnet_diagnostic.IDE0270.severity = suggestion - # https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide1006 # IDE1006: Naming rule violation: These words must begin with upper case characters: ... dotnet_diagnostic.IDE1006.severity = suggestion diff --git a/src/Microsoft.Sbom.Api/Executors/ConcurrentSha256HashValidator.cs b/src/Microsoft.Sbom.Api/Executors/ConcurrentSha256HashValidator.cs index 2f5cbe01..2c41427c 100644 --- a/src/Microsoft.Sbom.Api/Executors/ConcurrentSha256HashValidator.cs +++ b/src/Microsoft.Sbom.Api/Executors/ConcurrentSha256HashValidator.cs @@ -47,7 +47,7 @@ public ConcurrentSha256HashValidator(FileHashesDictionary fileHashesDictionary) private async Task Validate(InternalSbomFileInfo internalFileInfo, Channel output, Channel errors) { - var sha256Checksum = internalFileInfo.Checksum.Where(c => c.Algorithm == AlgorithmName.SHA256).FirstOrDefault(); + var sha256Checksum = internalFileInfo.Checksum.FirstOrDefault(c => c.Algorithm == AlgorithmName.SHA256); var fileHashes = new FileHashes(); fileHashes.SetHash(internalFileInfo.FileLocation, sha256Checksum); FileValidationResult failureResult = null; diff --git a/src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfigProvider.cs b/src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfigProvider.cs index 53055957..2e374108 100644 --- a/src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfigProvider.cs +++ b/src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfigProvider.cs @@ -190,9 +190,8 @@ public string GetSBOMNamespaceUri() IMetadataProvider provider = null; if (MetadataDictionary.TryGetValue(MetadataKey.BuildEnvironmentName, out var buildEnvironmentName)) { - provider = metadataProviders - .Where(p => p.BuildEnvironmentName != null && p.BuildEnvironmentName == buildEnvironmentName as string) - .FirstOrDefault(); + provider = this.metadataProviders + .FirstOrDefault(p => p.BuildEnvironmentName != null && p.BuildEnvironmentName == buildEnvironmentName as string); } else { diff --git a/src/Microsoft.Sbom.Api/Utils/ComponentDetectionCliArgumentBuilder.cs b/src/Microsoft.Sbom.Api/Utils/ComponentDetectionCliArgumentBuilder.cs index 1fced0fe..88dd0017 100644 --- a/src/Microsoft.Sbom.Api/Utils/ComponentDetectionCliArgumentBuilder.cs +++ b/src/Microsoft.Sbom.Api/Utils/ComponentDetectionCliArgumentBuilder.cs @@ -74,7 +74,7 @@ public string[] Build() if (keyArgs.Any()) { - var keyArgsCommand = string.Join(" ", keyArgs.Select(x => AsArgumentValue(x))); + var keyArgsCommand = string.Join(" ", keyArgs.Select(this.AsArgumentValue)); command += $" {keyArgsCommand}"; } diff --git a/src/Microsoft.Sbom.Api/Workflows/Helpers/PackageArrayGenerator.cs b/src/Microsoft.Sbom.Api/Workflows/Helpers/PackageArrayGenerator.cs index 16701300..a57531a7 100644 --- a/src/Microsoft.Sbom.Api/Workflows/Helpers/PackageArrayGenerator.cs +++ b/src/Microsoft.Sbom.Api/Workflows/Helpers/PackageArrayGenerator.cs @@ -46,9 +46,8 @@ public async Task> GenerateAsync() { IList totalErrors = new List(); - var sourcesProvider = sourcesProviders - .Where(s => s.IsSupported(ProviderType.Packages)) - .FirstOrDefault(); + var sourcesProvider = this.sourcesProviders + .FirstOrDefault(s => s.IsSupported(ProviderType.Packages)); // Write the start of the array, if supported. IList packagesArraySupportingConfigs = new List(); diff --git a/src/Microsoft.Sbom.Contracts/Contracts/SBOMSpecification.cs b/src/Microsoft.Sbom.Contracts/Contracts/SBOMSpecification.cs index 716aedeb..d6ecf314 100644 --- a/src/Microsoft.Sbom.Contracts/Contracts/SBOMSpecification.cs +++ b/src/Microsoft.Sbom.Contracts/Contracts/SBOMSpecification.cs @@ -53,9 +53,7 @@ public static SbomSpecification Parse(string value) } var values = value.Split(':'); - if (values == null - || values.Length != 2 - || values.Any(v => string.IsNullOrWhiteSpace(v))) + if (values is not { Length: 2 } || values.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentException($"The SBOM specification string is not formatted correctly. The correct format is :."); } diff --git a/src/Microsoft.Sbom.Parsers.Spdx22SbomParser/Generator.cs b/src/Microsoft.Sbom.Parsers.Spdx22SbomParser/Generator.cs index 3d14023a..d77b5af8 100644 --- a/src/Microsoft.Sbom.Parsers.Spdx22SbomParser/Generator.cs +++ b/src/Microsoft.Sbom.Parsers.Spdx22SbomParser/Generator.cs @@ -80,7 +80,7 @@ private SPDXFile ConvertSbomFileToSpdxFile(InternalSbomFileInfo fileInfo) FileCopyrightText = fileInfo.FileCopyrightText ?? Constants.NoAssertionValue, LicenseConcluded = fileInfo.LicenseConcluded ?? Constants.NoAssertionValue, LicenseInfoInFiles = fileInfo.LicenseInfoInFiles ?? Constants.NoAssertionListValue, - FileTypes = fileInfo.FileTypes?.Select(f => GetSPDXFileType(f)).ToList(), + FileTypes = fileInfo.FileTypes?.Select(this.GetSPDXFileType).ToList(), }; spdxFileElement.AddSpdxId(fileInfo.Path, fileInfo.Checksum); @@ -297,12 +297,9 @@ public GenerationResult GenerateJsonDocument(ExternalDocumentReferenceInfo exter throw new ArgumentNullException(nameof(externalDocumentReferenceInfo.Checksum)); } - var sha1Hash = externalDocumentReferenceInfo.Checksum.Where(h => h.Algorithm == AlgorithmName.SHA1).FirstOrDefault(); - - if (sha1Hash is null) - { - throw new MissingHashValueException($"The hash value for algorithm {AlgorithmName.SHA1} is missing from {nameof(externalDocumentReferenceInfo)}"); - } + var sha1Hash = externalDocumentReferenceInfo.Checksum.FirstOrDefault(h => h.Algorithm == AlgorithmName.SHA1) ?? + throw new MissingHashValueException( + $"The hash value for algorithm {AlgorithmName.SHA1} is missing from {nameof(externalDocumentReferenceInfo)}"); var checksumValue = sha1Hash.ChecksumValue.ToLower(); var externalDocumentReferenceElement = new SpdxExternalDocumentReference