From c087efd008095c5942159fce66a0f5c9648ed1b6 Mon Sep 17 00:00:00 2001 From: Aditya Narayan Date: Thu, 9 Nov 2023 10:42:55 +0530 Subject: [PATCH] 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); }