Skip to content

Commit

Permalink
More StyleCop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Sigmund committed Jun 22, 2022
1 parent c3b7564 commit 098e133
Show file tree
Hide file tree
Showing 124 changed files with 403 additions and 375 deletions.
8 changes: 5 additions & 3 deletions src/Microsoft.Sbom.Api/Bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Sbom.Extensions.Entities;
using Microsoft.Sbom.Api.Converters;
using Microsoft.Sbom.Api.Convertors;
using Microsoft.Sbom.Api.Entities.output;
using Microsoft.Sbom.Api.Entities.Output;
using Microsoft.Sbom.Api.Executors;
using Microsoft.Sbom.Api.Filters;
using Microsoft.Sbom.Api.Hashing;
Expand Down Expand Up @@ -41,6 +41,7 @@ namespace Microsoft.Sbom.Api
/// </remarks>
public class Bindings : NinjectModule
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1123:Do not place regions within elements", Justification = "Enable documentation of code")]
public override void Load()
{
Bind<IFileSystemUtils>().ToProvider<FileSystemUtilsProvider>().InSingletonScope();
Expand All @@ -59,10 +60,11 @@ public override void Load()

Bind<IFilter>().To<DownloadedRootPathFilter>().Named(nameof(DownloadedRootPathFilter)).OnActivation(f => f.Init());
Bind<IFilter>().To<ManifestFolderFilter>().Named(nameof(ManifestFolderFilter)).OnActivation(f => f.Init());

Bind<ILogger>().ToProvider<LoggerProvider>();

#region Bind all manifest parsers

// Search external assemblies
Kernel.Bind(scan => scan
.FromAssembliesMatching("*Parsers*")
Expand All @@ -83,6 +85,7 @@ public override void Load()
#endregion

#region Bind all manifest generators

// Search external assemblies
Kernel.Bind(scan => scan
.FromAssembliesMatching("*Parsers*")
Expand Down Expand Up @@ -209,7 +212,6 @@ public override void Load()
Bind<ExternalDocumentReferenceWriter>().ToSelf().InThreadScope();
Bind<ISBOMReaderForExternalDocumentReference>().To<SPDXSBOMReaderForExternalDocumentReference>().InThreadScope();


#endregion

#region Bind all hash algorithm providers
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.Sbom.Api/Config/ApiConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class ApiConfigurationBuilder
/// <param name="specifications"></param>
/// <param name="runtimeConfiguration"></param>
/// <param name="verbosity"></param>
/// <returns>A generate configuration</returns>
/// <returns>A generate configuration.</returns>
internal Configuration GetConfiguration(
string rootPath,
string manifestDirPath,
Expand Down Expand Up @@ -62,9 +62,9 @@ internal Configuration GetConfiguration(
configuration.PackageVersion = GetConfigurationSetting(metadata.PackageVersion);
configuration.Parallelism = GetConfigurationSetting(sanitizedRuntimeConfiguration.WorkflowParallelism);
configuration.GenerationTimestamp = GetConfigurationSetting(sanitizedRuntimeConfiguration.GenerationTimestamp);
configuration.NamespaceUriBase = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriBase);
configuration.NamespaceUriUniquePart = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriUniquePart);
configuration.FollowSymlinks = GetConfigurationSetting(sanitizedRuntimeConfiguration.FollowSymlinks);
configuration.NamespaceUriBase = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriBase);
configuration.NamespaceUriUniquePart = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriUniquePart);
configuration.FollowSymlinks = GetConfigurationSetting(sanitizedRuntimeConfiguration.FollowSymlinks);

SetVerbosity(sanitizedRuntimeConfiguration, configuration);

Expand All @@ -82,8 +82,8 @@ internal Configuration GetConfiguration(
{
configuration.ExternalDocumentReferenceListFile = GetConfigurationSetting(externalDocumentReferenceListFile);
}
if (!String.IsNullOrWhiteSpace(componentPath))

if (!string.IsNullOrWhiteSpace(componentPath))
{
configuration.BuildComponentPath = GetConfigurationSetting(componentPath);
}
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.Sbom.Api/Config/ArgRevivers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class ArgRevivers
[ArgReviver]
public static IList<ManifestInfo> ReviveManifestInfo(string _, string value)
{

try
{
IList<ManifestInfo> manifestInfos = new List<ManifestInfo>();
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Sbom.Api/Config/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class ConfigFile
/// Gets or sets the name of the package this SBOM represents.
/// </summary>
public string PackageName { get; set; }

/// <summary>
/// Gets or sets the version of the package this SBOM represents.
/// </summary>
Expand Down Expand Up @@ -133,7 +133,7 @@ public class ConfigFile
/// Gets or sets additional set of command-line arguments for Component Detector.
/// </summary>
public string AdditionalComponentDetectorArgs { get; set; }

/// <summary>
/// Gets or sets unique part of the namespace uri for SPDX 2.2 SBOMs. This value should be globally unique.
/// If this value is not provided, we generate a unique guid that will make the namespace globally unique.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Api/Config/ConfigFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ConfigFileParser(IFileSystemUtils fileSystemUtils)

public async Task<ConfigFile> ParseFromJsonFile(string filePath)
{
if(string.IsNullOrEmpty(filePath))
if (string.IsNullOrEmpty(filePath))
{
throw new ArgumentNullException($"{nameof(filePath)} cannot be emtpy.");
}
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.Sbom.Api/Config/ConfigPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void Process(Configuration source, Configuration destination, ResolutionC
{
// Assign default values if any using the default value attribute.
if (property.GetValue(destination) == null &&
property.Attributes[typeof(System.ComponentModel.DefaultValueAttribute)]
property.Attributes[typeof(System.ComponentModel.DefaultValueAttribute)]
is System.ComponentModel.DefaultValueAttribute defaultValueAttribute)
{
SetDefautValue(destination, defaultValueAttribute.Value, property);
}

// Run validators on all properties.
configValidators.ForEach(v => v.Validate(property.DisplayName, property.GetValue(destination), property.Attributes));
configValidators.ForEach(v => v.Validate(property.DisplayName, property.GetValue(destination), property.Attributes));
}

// Sanitize configuration
Expand Down Expand Up @@ -81,6 +81,7 @@ private void SetDefautValue(Configuration destination, object value, PropertyDes
Source = SettingSource.Default
});
}

// Fall through, only primitive types are currently supported.
// Add more primitive types if needed here.
}
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.Sbom.Api/Config/ConfigSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public Configuration SanitizeConfig(Configuration configuration)

private ConfigurationSetting<IList<ManifestInfo>> GetDefaultManifestInfoForValidationAction(Configuration configuration)
{
if (configuration.ManifestToolAction != ManifestToolActions.Validate
|| ( configuration.ManifestInfo.Value != null && configuration.ManifestInfo.Value.Count != 0))
if (configuration.ManifestToolAction != ManifestToolActions.Validate
|| (configuration.ManifestInfo.Value != null && configuration.ManifestInfo.Value.Count != 0))
{
return configuration.ManifestInfo;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ private ConfigurationSetting<string> GetManifestDirPath(ConfigurationSetting<str
{
Value = EnsurePathEndsWithManifestFolderForGenerate(manifestDirPathConfig.Value, manifestToolAction),
Source = manifestDirPathConfig.Source
}; ;
};
}

private string EnsurePathEndsWithManifestFolderForGenerate(string value, ManifestToolActions manifestToolAction)
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.Sbom.Api/Config/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ await configFileParser.ParseFromJsonFile(commandLineArgs.ConfigFilePath.Value) :
// Convert config file arguments to configuration.
var configFileArgs = mapper.Map<ConfigFile, Configuration>(configFromFile);


// Combine both configs, include defaults.
return mapper.Map(commandLineArgs, configFileArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class ConfigurationExtensions
/// <param name="arg"></param>
/// <param name="builder"></param>
/// <returns></returns>
private static ComponentDetectionCliArgumentBuilder AddToCommandLineBuilder(this (string Name, object Value) arg, ComponentDetectionCliArgumentBuilder builder) =>
private static ComponentDetectionCliArgumentBuilder AddToCommandLineBuilder(this (string Name, object Value) arg, ComponentDetectionCliArgumentBuilder builder) =>
!string.IsNullOrWhiteSpace(arg.Name) ? builder.AddArg(arg.Name, arg.Value.ToString()) : builder.ParseAndAddArgs(arg.Value.ToString());

/// <summary>
Expand All @@ -49,6 +49,5 @@ public static string[] ToComponentDetectorCommandLineParams(this IConfiguration
.ForEach(arg => arg.AddToCommandLineBuilder(builder));
return builder.Build();
}

}
}
5 changes: 2 additions & 3 deletions src/Microsoft.Sbom.Api/Config/ManifestToolCmdRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ public async Task Generate(GenerationArgs generationArgs)
var configFileParser = kernel.Get<ConfigFileParser>();
var configBuilder = new ConfigurationBuilder<GenerationArgs>(mapper, configFileParser);

kernel.Bind<IConfiguration>().ToConstant(await configBuilder.GetConfiguration(generationArgs));
kernel.Bind<IConfiguration>().ToConstant(await configBuilder.GetConfiguration(generationArgs));

var result = await kernel.Get<IWorkflow>(nameof(SBOMGenerationWorkflow)).RunAsync();
await kernel.Get<IRecorder>().FinalizeAndLogTelemetryAsync();
IsFailed = !result;

}
catch (AccessDeniedValidationArgException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void ValidateInternal(string paramName, object paramValue, Attri
{
if (paramValue != null && paramValue is string value && !string.IsNullOrEmpty(value))
{
if(!fileSystemUtils.FileExists(value))
if (!fileSystemUtils.FileExists(value))
{
throw new ValidationArgException($"{paramName} file not found for '{value}'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FilePathIsWritableValidator : ConfigValidator
{
private readonly IFileSystemUtils fileSystemUtils;

public FilePathIsWritableValidator(IFileSystemUtils fileSystemUtils, IAssemblyConfig assemblyConfig)
public FilePathIsWritableValidator(IFileSystemUtils fileSystemUtils, IAssemblyConfig assemblyConfig)
: base(typeof(FilePathIsWritableAttribute), assemblyConfig)
{
this.fileSystemUtils = fileSystemUtils ?? throw new ArgumentNullException(nameof(fileSystemUtils));
Expand Down
9 changes: 5 additions & 4 deletions src/Microsoft.Sbom.Api/Config/Validators/IntRangeValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ namespace Microsoft.Sbom.Api.Config.Validators
/// </summary>
public class IntRangeValidator : ConfigValidator
{
public IntRangeValidator(IAssemblyConfig assemblyConfig) : base(typeof(IntRangeAttribute), assemblyConfig)
public IntRangeValidator(IAssemblyConfig assemblyConfig)
: base(typeof(IntRangeAttribute), assemblyConfig)
{
}

public override void ValidateInternal(string paramName, object paramValue, Attribute attribute)
{
if(paramValue != null && paramValue is int value)
if (paramValue != null && paramValue is int value)
{
IntRangeAttribute intRangeAttribute = attribute as IntRangeAttribute;
if(value < intRangeAttribute.MinRange || value > intRangeAttribute.MaxRange)

if (value < intRangeAttribute.MinRange || value > intRangeAttribute.MaxRange)
{
throw new ValidationArgException($"The value for {paramName} should be equal to or between {intRangeAttribute.MinRange} and {intRangeAttribute.MaxRange}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ConfigurationSetting<AlgorithmName> Convert(AlgorithmName sourceMember, R
{
settingSource = SettingSource.Default;
}

return new ConfigurationSetting<AlgorithmName>
{
Source = settingSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public StringConfigurationSettingAddingConverter(SettingSource settingSource)
public ConfigurationSetting<string> Convert(string sourceMember, ResolutionContext context)
{
if (string.IsNullOrEmpty(sourceMember))
{
return null;
}

return new ConfigurationSetting<string>
{
Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.Sbom.Api/ConfigurationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public ConfigurationProfile()
ForAllPropertyMaps(
p => p.SourceType == typeof(AlgorithmName),
(c, memberOptions) => memberOptions.ConvertUsing(new HashAlgorithmNameConfigurationSettingAddingConverter(GetSettingSourceFor(c.SourceMember.ReflectedType))));

}

// Based on the type of source, return the settings type.
Expand All @@ -118,13 +117,12 @@ private SettingSource GetSettingSourceFor(Type sourceType)
switch (sourceType)
{
case Type _ when sourceType.IsSubclassOf(typeof(CommonArgs)):
case Type _ when sourceType == typeof(CommonArgs):
case Type _ when sourceType == typeof(CommonArgs):
return SettingSource.CommandLine;
case Type _ when sourceType == typeof(ConfigFile):
return SettingSource.JsonConfig;
default: return SettingSource.Default;
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ await errors.Writer.WriteAsync(new FileValidationResult

private ExternalDocumentReferenceInfo ConvertComponentToExternalReference(ScannedComponent component)
{

if(!(component.Component is SpdxComponent))
if (!(component.Component is SpdxComponent))
{
throw new ArgumentException($"{nameof(component.Component)} is not an SpdxComponent");
}

var sbomComponent = (SpdxComponent)component.Component;

if(sbomComponent.DocumentNamespace is null)
if (sbomComponent.DocumentNamespace is null)
{
throw new ArgumentException($"{nameof(sbomComponent)} should have {nameof(sbomComponent.DocumentNamespace)}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public DropValidatorManifestPathConverter(IConfiguration configuration, IOSUtils
//relativeTo
string buildDropPath = configuration.BuildDropPath.Value;
bool isOutsideDropPath = false;
if (path == null) throw new ArgumentNullException(nameof(path));
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}

if (!fileSystemUtilsExtension.IsTargetPathInSource(path, buildDropPath))
{
isOutsideDropPath = true;

// Allow spdx files to be outside the root path, all externalDocumentReference must be in the file array regardless of where they are located.
// More details are in this spec: https://github.com/spdx/spdx-spec/issues/571
if (!path.EndsWith(Constants.SPDXFileExtension, osUtils.GetFileSystemStringComparisonType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ public ExternalReferenceInfoToPathConverter(ILogger log)
{
var path = externalDocumentRef.Path;
if(path == null)
if (path == null)
{
log.Debug($"Encountered an error while converting external reference {externalDocumentRef.ExternalDocumentName} for null path.");
await errors.Writer.WriteAsync(new FileValidationResult
{
ErrorType = ErrorType.Other,
// on the exception that Path does not exist, use DocumentName for uniqueness
Path = externalDocumentRef.ExternalDocumentName
});
}
}
else
{
await output.Writer.WriteAsync(path);
Expand Down
5 changes: 2 additions & 3 deletions src/Microsoft.Sbom.Api/Converters/IManifestPathConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
namespace Microsoft.Sbom.Api.Convertors
{
public interface IManifestPathConverter
{
{
/// <summary>
/// Convert a file path from a relative path to a path format
/// that the manifest implements.
/// </summary>
/// <param name="path">The relative path of the file.</param>
/// <returns>The file path in the manifest format and boolean for if the path is outside the BuildDropPath</returns>

/// <returns>The file path in the manifest format and boolean for if the path is outside the BuildDropPath.</returns>
(string, bool) Convert(string path);
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Api/Entities/ErrorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum ErrorType

[EnumMember(Value = "Additional File")]
AdditionalFile = 2,

[EnumMember(Value = "Missing File")]
MissingFile = 3,

Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.Sbom.Api/Entities/FileValidationResult.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Microsoft.Sbom.Contracts;
using Microsoft.Sbom.Contracts.Entities;
using Microsoft.Sbom.Contracts.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using EntityErrorType = Microsoft.Sbom.Contracts.Enums.ErrorType;
using Microsoft.Sbom.Contracts.Entities;

namespace Microsoft.Sbom.Api.Entities
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Api/Entities/output/ErrorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Collections.Generic;

namespace Microsoft.Sbom.Api.Entities.output
namespace Microsoft.Sbom.Api.Entities.Output
{
/// <summary>
/// Error container for validation errors.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Api/Entities/output/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Runtime.Serialization;

namespace Microsoft.Sbom.Api.Entities.output
namespace Microsoft.Sbom.Api.Entities.Output
{
/// <summary>
/// The result of the validation.
Expand Down
Loading

0 comments on commit 098e133

Please sign in to comment.