From c087efd008095c5942159fce66a0f5c9648ed1b6 Mon Sep 17 00:00:00 2001 From: Aditya Narayan Date: Thu, 9 Nov 2023 10:42:55 +0530 Subject: [PATCH 1/2] Fixing 3 sonar code smells and 1 sonar bug --- src/LCT.Common/FileParser.cs | 2 +- src/LCT.PackageIdentifier/ConanProcessor.cs | 2 +- src/LCT.PackageIdentifier/NugetDevDependencyParser.cs | 2 +- src/LCT.PackageIdentifier/NugetProcessor.cs | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/LCT.Common/FileParser.cs b/src/LCT.Common/FileParser.cs index e84876c5..005f23ab 100644 --- a/src/LCT.Common/FileParser.cs +++ b/src/LCT.Common/FileParser.cs @@ -23,7 +23,7 @@ public TomlTable ParseTomlFile(string filePath) table = TOML.Parse(reader); return table; } - catch(Exception ex) + catch(TomlParseException) { return new TomlTable(); } diff --git a/src/LCT.PackageIdentifier/ConanProcessor.cs b/src/LCT.PackageIdentifier/ConanProcessor.cs index 04065bfd..02f6b873 100644 --- a/src/LCT.PackageIdentifier/ConanProcessor.cs +++ b/src/LCT.PackageIdentifier/ConanProcessor.cs @@ -292,7 +292,7 @@ private static void GetDependecyDetails(List componentsForBOM, List lstComponentForBOM, ref int noOfDevDependent, List nodePackages) { var rootNode = nodePackages.FirstOrDefault(); - if (!rootNode.Dependencies.Any() || rootNode.Dependencies == null) + if (rootNode != null && (!rootNode.Dependencies.Any() || rootNode.Dependencies == null)) { throw new ArgumentNullException(nameof(nodePackages), "Dependency(requires) node name details not present in the root node."); } diff --git a/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs b/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs index 386ffb68..4ba9c63a 100644 --- a/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs +++ b/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs @@ -44,7 +44,7 @@ public static NugetDevDependencyParser Instance } } - public List Parse(string configFile) + public static List Parse(string configFile) { List containerList = new(); diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 2221b406..96acc650 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -619,8 +619,7 @@ private static string ReferenceTagDetailsForPackageReference(XmlNode childNode, private static List ParseAssetFile(string configFile) { - NugetDevDependencyParser nugetDevDependencyParser = NugetDevDependencyParser.Instance; - List containers = nugetDevDependencyParser.Parse(configFile); + List containers = NugetDevDependencyParser.Parse(configFile); return ConvertContainerAsNugetPackage(containers, configFile); } From fd4b61e7c28c8a6084763042201237bde238ca91 Mon Sep 17 00:00:00 2001 From: Aditya Narayan Date: Thu, 9 Nov 2023 13:57:51 +0530 Subject: [PATCH 2/2] fixing an instance error in NugetDevDependencyParser and the check for null in test case --- src/LCT.Common/FileOperations.cs | 2 +- src/LCT.PackageIdentifier/NugetDevDependencyParser.cs | 4 +++- src/LCT.PackageIdentifier/NugetProcessor.cs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/LCT.Common/FileOperations.cs b/src/LCT.Common/FileOperations.cs index 3641d7bf..a3ed559f 100644 --- a/src/LCT.Common/FileOperations.cs +++ b/src/LCT.Common/FileOperations.cs @@ -102,7 +102,7 @@ public Bom CombineComponentsFromExistingBOM(Bom components, string filePath) comparisonData.Components = comparisonData.Components?.GroupBy(x => new { x.Name, x.Version }).Select(y => y.First()).ToList(); - if (comparisonData.Dependencies.Count > 0) + if (comparisonData.Dependencies != null && comparisonData.Dependencies.Count > 0) { comparisonData.Dependencies.AddRange(components.Dependencies); } diff --git a/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs b/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs index 4ba9c63a..d31e9b2a 100644 --- a/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs +++ b/src/LCT.PackageIdentifier/NugetDevDependencyParser.cs @@ -44,7 +44,9 @@ public static NugetDevDependencyParser Instance } } - public static List Parse(string configFile) +#pragma warning disable CA1822 // Mark members as static + public List Parse(string configFile) +#pragma warning restore CA1822 // Mark members as static { List containerList = new(); diff --git a/src/LCT.PackageIdentifier/NugetProcessor.cs b/src/LCT.PackageIdentifier/NugetProcessor.cs index 96acc650..2221b406 100644 --- a/src/LCT.PackageIdentifier/NugetProcessor.cs +++ b/src/LCT.PackageIdentifier/NugetProcessor.cs @@ -619,7 +619,8 @@ private static string ReferenceTagDetailsForPackageReference(XmlNode childNode, private static List ParseAssetFile(string configFile) { - List containers = NugetDevDependencyParser.Parse(configFile); + NugetDevDependencyParser nugetDevDependencyParser = NugetDevDependencyParser.Instance; + List containers = nugetDevDependencyParser.Parse(configFile); return ConvertContainerAsNugetPackage(containers, configFile); }