diff --git a/src/Agoda.CodeCompass.MSBuild.Tests/SarifConversionTests.cs b/src/Agoda.CodeCompass.MSBuild.Tests/SarifConversionTests.cs index 4eebd1c..8a7ef49 100644 --- a/src/Agoda.CodeCompass.MSBuild.Tests/SarifConversionTests.cs +++ b/src/Agoda.CodeCompass.MSBuild.Tests/SarifConversionTests.cs @@ -21,8 +21,8 @@ public class SarifConversionTests private JsonSerializerSettings _jsonSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), - Error = HandleDeserializationError - + Error = HandleDeserializationError, + Formatting = Formatting.Indented, }; [Test] diff --git a/src/Agoda.CodeCompass.MSBuild/SarifReporter.cs b/src/Agoda.CodeCompass.MSBuild/SarifReporter.cs index c7952a8..ab76b8f 100644 --- a/src/Agoda.CodeCompass.MSBuild/SarifReporter.cs +++ b/src/Agoda.CodeCompass.MSBuild/SarifReporter.cs @@ -10,6 +10,12 @@ public class SarifReporter { + private static JsonSerializerSettings _jsonSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + Error = HandleDeserializationError, + Formatting = Newtonsoft.Json.Formatting.Indented, + }; private static void HandleDeserializationError(object sender, ErrorEventArgs errorArgs) { // Log the error but don't throw it @@ -19,12 +25,6 @@ private static void HandleDeserializationError(object sender, ErrorEventArgs err } public static string AddTechDebtToSarif(string sarifContent) { - var jsonSettings = new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - Error = HandleDeserializationError - - }; // Detect version var jObject = JObject.Parse(sarifContent); @@ -32,8 +32,8 @@ public static string AddTechDebtToSarif(string sarifContent) return version switch { - "1.0.0" => AddTechDebtToSarifV1(sarifContent, jsonSettings), - "2.1.0" => AddTechDebtToSarifV2(sarifContent, jsonSettings), + "1.0.0" => AddTechDebtToSarifV1(sarifContent, _jsonSettings), + "2.1.0" => AddTechDebtToSarifV2(sarifContent, _jsonSettings), _ => throw new NotSupportedException($"Unsupported SARIF version: {version}") }; }