From a1c0dcdb0ccee596be26a76bb170d080c5013015 Mon Sep 17 00:00:00 2001 From: Vasileios Naskos Date: Fri, 8 Nov 2024 11:44:49 +0100 Subject: [PATCH] Add GetEffectiveIssueDetailsAsync --- .../GetEffectiveIssueDetailsParamsTests.cs | 44 ++++++++++ .../GetEffectiveIssueDetailsResponseTests.cs | 86 +++++++++++++++++++ .../Issue/GetEffectiveIssueDetailsParams.cs | 23 +++++ .../Issue/GetEffectiveIssueDetailsResponse.cs | 25 ++++++ .../Service/Issue/IIssueSLCoreService.cs | 30 +++++++ .../Issue/Models/EffectiveIssueDetailsDto.cs | 36 ++++++++ 6 files changed, 244 insertions(+) create mode 100644 src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsParamsTests.cs create mode 100644 src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsResponseTests.cs create mode 100644 src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs create mode 100644 src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs create mode 100644 src/SLCore/Service/Issue/IIssueSLCoreService.cs create mode 100644 src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs diff --git a/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsParamsTests.cs b/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsParamsTests.cs new file mode 100644 index 000000000..9ae9bc678 --- /dev/null +++ b/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsParamsTests.cs @@ -0,0 +1,44 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using Newtonsoft.Json; +using SonarLint.VisualStudio.SLCore.Service.Issue; + +namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Issue; + +[TestClass] +public class GetEffectiveIssueDetailsParamsTests +{ + [TestMethod] + public void Serialized_AsExpected() + { + var guid = Guid.NewGuid(); + var expected = $$""" + { + "configurationScopeId": "CONFIG_SCOPE_ID", + "issueId": "{{guid.ToString()}}" + } + """; + + var getEffectiveIssueDetailsParams = new GetEffectiveIssueDetailsParams("CONFIG_SCOPE_ID", guid); + + JsonConvert.SerializeObject(getEffectiveIssueDetailsParams, Formatting.Indented).Should().Be(expected); + } +} diff --git a/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsResponseTests.cs b/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsResponseTests.cs new file mode 100644 index 000000000..fa33a74ce --- /dev/null +++ b/src/SLCore.UnitTests/Service/Issue/GetEffectiveIssueDetailsResponseTests.cs @@ -0,0 +1,86 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using Newtonsoft.Json; +using SonarLint.VisualStudio.SLCore.Common.Models; +using SonarLint.VisualStudio.SLCore.Service.Issue; +using SonarLint.VisualStudio.SLCore.Service.Issue.Models; +using SonarLint.VisualStudio.SLCore.Service.Rules.Models; + +namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Issue; + +[TestClass] +public class GetEffectiveIssueDetailsResponseTests +{ + [TestMethod] + public void Deserialized_AsExpected() + { + var expected = new GetEffectiveIssueDetailsResponse( + details: new EffectiveIssueDetailsDto( + ruleKey: "S3776", + name: "Cognitive Complexity of methods should not be too high", + language: Language.CS, + vulnerabilityProbability: VulnerabilityProbability.HIGH, + description: new RuleMonolithicDescriptionDto("

Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.

"), + parameters: [new EffectiveRuleParamDto("max", "Maximum cognitive complexity", "15", "15")], + severityDetails: new StandardModeDetails(IssueSeverity.CRITICAL, RuleType.CODE_SMELL), + ruleDescriptionContextKey: "key")); + + const string serialized = """ + { + details: { + "ruleKey": "S3776", + "name": "Cognitive Complexity of methods should not be too high", + "language": "cs", + "vulnerabilityProbability": "HIGH", + "description": { + "htmlContent": "

Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.

" + }, + "params": [ + { + "name": "max", + "description": "Maximum cognitive complexity", + "value": "15", + "defaultValue": "15" + } + ], + "severityDetails": { + "severity": "CRITICAL", + "type": "CODE_SMELL" + }, + "ruleDescriptionContextKey": "key" + } + } + """; + + var actual = JsonConvert.DeserializeObject(serialized); + + actual + .Should() + .BeEquivalentTo(expected, + options => + options + .ComparingByMembers() + .ComparingByMembers() + .ComparingByMembers() + .ComparingByMembers() + .ComparingByMembers()); + } +} diff --git a/src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs b/src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs new file mode 100644 index 000000000..ab7908f6c --- /dev/null +++ b/src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs @@ -0,0 +1,23 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +namespace SonarLint.VisualStudio.SLCore.Service.Issue; + +public record GetEffectiveIssueDetailsParams(string configurationScopeId, Guid issueId); diff --git a/src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs b/src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs new file mode 100644 index 000000000..6b00cbd3a --- /dev/null +++ b/src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs @@ -0,0 +1,25 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using SonarLint.VisualStudio.SLCore.Service.Issue.Models; + +namespace SonarLint.VisualStudio.SLCore.Service.Issue; + +public record GetEffectiveIssueDetailsResponse(EffectiveIssueDetailsDto details); diff --git a/src/SLCore/Service/Issue/IIssueSLCoreService.cs b/src/SLCore/Service/Issue/IIssueSLCoreService.cs new file mode 100644 index 000000000..b6f3fe95d --- /dev/null +++ b/src/SLCore/Service/Issue/IIssueSLCoreService.cs @@ -0,0 +1,30 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using SonarLint.VisualStudio.SLCore.Core; +using SonarLint.VisualStudio.SLCore.Protocol; + +namespace SonarLint.VisualStudio.SLCore.Service.Issue; + +[JsonRpcClass("issue")] +public interface IIssueSLCoreService : ISLCoreService +{ + Task GetEffectiveIssueDetailsAsync(GetEffectiveIssueDetailsParams parameters); +} diff --git a/src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs b/src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs new file mode 100644 index 000000000..9bce238de --- /dev/null +++ b/src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs @@ -0,0 +1,36 @@ +/* + * SonarLint for Visual Studio + * Copyright (C) 2016-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +using Newtonsoft.Json; +using SonarLint.VisualStudio.SLCore.Common.Models; +using SonarLint.VisualStudio.SLCore.Protocol; +using SonarLint.VisualStudio.SLCore.Service.Rules.Models; + +namespace SonarLint.VisualStudio.SLCore.Service.Issue.Models; + +public record EffectiveIssueDetailsDto( + string ruleKey, + string name, + Language language, + VulnerabilityProbability? vulnerabilityProbability, + [JsonConverter(typeof(EitherJsonConverter))] Either description, + [JsonProperty("params")] List parameters, + [JsonConverter(typeof(EitherJsonConverter))] Either severityDetails, + string ruleDescriptionContextKey);