diff --git a/src/Core.UnitTests/RuleSettingsSerializerTests.cs b/src/Core.UnitTests/RuleSettingsSerializerTests.cs index 28a63f14d..4c93ce8ad 100644 --- a/src/Core.UnitTests/RuleSettingsSerializerTests.cs +++ b/src/Core.UnitTests/RuleSettingsSerializerTests.cs @@ -118,7 +118,7 @@ public void RealFile_RoundTripLoadAndSave_WithFirstCapsPropertyNames() 'Parameters': { 'key1': 'value1' }, - 'Severity': 'Critical' + 'Severity': 'Critical' }, 'xxx:yyy': { 'level': 'off', @@ -153,9 +153,6 @@ public void RealFile_RoundTripLoadAndSave_WithFirstCapsPropertyNames() loadedSettings.Rules["xxx:yyy"].Parameters["key2"].Should().Be("value2"); loadedSettings.Rules["xxx:yyy"].Parameters["key3"].Should().Be("value3"); - loadedSettings.Rules["typescript:S2685"].Severity.Should().Be(IssueSeverity.Critical); - loadedSettings.Rules["xxx:yyy"].Severity.Should().Be(IssueSeverity.Blocker); - // 2. Save and reload testSubject.SafeSave(filePath2, loadedSettings); File.Exists(filePath2).Should().BeTrue(); @@ -192,8 +189,8 @@ public void RealFile_RoundTripSaveAndLoad() { Rules = new Dictionary { - { "repo1:key1", new RuleConfig { Level = RuleLevel.Off, Severity = IssueSeverity.Major } }, - { "repo1:key2", new RuleConfig { Level = RuleLevel.On, Severity = IssueSeverity.Blocker } }, + { "repo1:key1", new RuleConfig { Level = RuleLevel.Off } }, + { "repo1:key2", new RuleConfig { Level = RuleLevel.On } }, { "repox:keyy", new RuleConfig { @@ -227,10 +224,6 @@ public void RealFile_RoundTripSaveAndLoad() reloadedSettings.Rules["repo1:key2"].Level.Should().Be(RuleLevel.On); reloadedSettings.Rules["repox:keyy"].Level.Should().Be(RuleLevel.On); - reloadedSettings.Rules["repo1:key1"].Severity.Should().Be(IssueSeverity.Major); - reloadedSettings.Rules["repo1:key2"].Severity.Should().Be(IssueSeverity.Blocker); - reloadedSettings.Rules["repox:keyy"].Severity.Should().BeNull(); - reloadedSettings.Rules["repo1:key1"].Parameters.Should().BeNull(); reloadedSettings.Rules["repo1:key2"].Parameters.Should().BeNull(); diff --git a/src/Core/UserRuleSettings/RulesSettings.cs b/src/Core/UserRuleSettings/RulesSettings.cs index 0a790b485..65ea5ca14 100644 --- a/src/Core/UserRuleSettings/RulesSettings.cs +++ b/src/Core/UserRuleSettings/RulesSettings.cs @@ -72,10 +72,6 @@ public class RuleConfig // comparer, which is case-sensitive. [JsonProperty("parameters", NullValueHandling = NullValueHandling.Ignore)] public Dictionary Parameters { get; set; } - - [JsonProperty("severity", NullValueHandling = NullValueHandling.Ignore)] - [JsonConverter(typeof(StringEnumConverter))] - public IssueSeverity? Severity { get; set; } } public enum RuleLevel @@ -83,13 +79,4 @@ public enum RuleLevel On, Off } - - public enum IssueSeverity - { - Blocker = 0, - Critical = 1, - Major = 2, - Minor = 3, - Info = 4, - } } diff --git a/src/SLCore.UnitTests/Service/Analysis/AnalyzeFilesResponseTests.cs b/src/SLCore.UnitTests/Service/Analysis/AnalyzeFilesResponseTests.cs index af2b57921..a4cb3856d 100644 --- a/src/SLCore.UnitTests/Service/Analysis/AnalyzeFilesResponseTests.cs +++ b/src/SLCore.UnitTests/Service/Analysis/AnalyzeFilesResponseTests.cs @@ -22,7 +22,6 @@ using SonarLint.VisualStudio.SLCore.Common.Models; using SonarLint.VisualStudio.SLCore.Service.Analysis; using SonarLint.VisualStudio.SLCore.Service.Analysis.Models; -using IssueSeverity = SonarLint.VisualStudio.Core.UserRuleSettings.IssueSeverity; namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Analysis; @@ -30,7 +29,7 @@ namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Analysis; public class AnalyzeFilesResponseTests { [TestMethod] - public void Serialize_AsExpected() + public void Deserialize_AsExpected() { var failedFile = new FileUri("C:\\tmp\\junit14012097140227905793\\Foo.cs"); var textRange = new TextRangeDto(1, 0, 1, 20); @@ -42,25 +41,24 @@ public void Serialize_AsExpected() var failedAnalysisFiles = new HashSet { failedFile }; var rawIssues = new List { - new RawIssueDto(IssueSeverity.Major, RuleType.BUG, CleanCodeAttribute.IDENTIFIABLE, - new Dictionary(), "S123", "PRIMARY MESSAGE", failedFile, + new(IssueSeverity.MAJOR, RuleType.BUG, CleanCodeAttribute.IDENTIFIABLE, new(){[SoftwareQuality.MAINTAINABILITY] = ImpactSeverity.HIGH}, "S123", "PRIMARY MESSAGE", failedFile, rawIssueFlow, [], textRange, "RULE DESCRIPTION CONTEXT KEY", VulnerabilityProbability.HIGH) }; - var testSubject = new AnalyzeFilesResponse(failedAnalysisFiles, rawIssues); + var expectedResponse = new AnalyzeFilesResponse(failedAnalysisFiles, rawIssues); - const string expectedString = """ + const string serializedString = """ { "failedAnalysisFiles": [ "file:///C:/tmp/junit14012097140227905793/Foo.cs" ], "rawIssues": [ { - "severity": 2, - "type": 1, - "cleanCodeAttribute": 2, - "impacts": {}, + "severity": "MAJOR", + "type": "BUG", + "cleanCodeAttribute": "IDENTIFIABLE", + "impacts": { "MAINTAINABILITY" : "HIGH"}, "ruleKey": "S123", "primaryMessage": "PRIMARY MESSAGE", "fileUri": "file:///C:/tmp/junit14012097140227905793/Foo.cs", @@ -93,9 +91,9 @@ public void Serialize_AsExpected() ] } """; - - var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented); - serializedString.Should().Be(expectedString); + var actualResponse = JsonConvert.DeserializeObject(serializedString); + + actualResponse.Should().BeEquivalentTo(expectedResponse, options => options.ComparingByMembers().ComparingByMembers().ComparingByMembers()); } } diff --git a/src/SLCore/Service/Analysis/Models/RawIssueDto.cs b/src/SLCore/Service/Analysis/Models/RawIssueDto.cs index 2eb1b80bb..f5bb6e9c3 100644 --- a/src/SLCore/Service/Analysis/Models/RawIssueDto.cs +++ b/src/SLCore/Service/Analysis/Models/RawIssueDto.cs @@ -19,7 +19,7 @@ */ using SonarLint.VisualStudio.SLCore.Common.Models; -using IssueSeverity = SonarLint.VisualStudio.Core.UserRuleSettings.IssueSeverity; +using IssueSeverity = SonarLint.VisualStudio.SLCore.Common.Models.IssueSeverity; namespace SonarLint.VisualStudio.SLCore.Service.Analysis.Models;