Skip to content

Commit

Permalink
SLVS-1596 Add GetEffectiveIssueDetailsAsync (#5814)
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaskos-sonar authored Nov 8, 2024
1 parent ff36cfa commit 9f15429
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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("<p>Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.</p>"),
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": "<p>Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code.</p>"
},
"params": [
{
"name": "max",
"description": "Maximum cognitive complexity",
"value": "15",
"defaultValue": "15"
}
],
"severityDetails": {
"severity": "CRITICAL",
"type": "CODE_SMELL"
},
"ruleDescriptionContextKey": "key"
}
}
""";

var actual = JsonConvert.DeserializeObject<GetEffectiveIssueDetailsResponse>(serialized);

actual
.Should()
.BeEquivalentTo(expected,
options =>
options
.ComparingByMembers<GetEffectiveIssueDetailsResponse>()
.ComparingByMembers<EffectiveIssueDetailsDto>()
.ComparingByMembers<RuleMonolithicDescriptionDto>()
.ComparingByMembers<EffectiveRuleParamDto>()
.ComparingByMembers<StandardModeDetails>());
}
}
23 changes: 23 additions & 0 deletions src/SLCore/Service/Issue/GetEffectiveIssueDetailsParams.cs
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 25 additions & 0 deletions src/SLCore/Service/Issue/GetEffectiveIssueDetailsResponse.cs
Original file line number Diff line number Diff line change
@@ -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);
30 changes: 30 additions & 0 deletions src/SLCore/Service/Issue/IIssueSLCoreService.cs
Original file line number Diff line number Diff line change
@@ -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<GetEffectiveIssueDetailsResponse> GetEffectiveIssueDetailsAsync(GetEffectiveIssueDetailsParams parameters);
}
36 changes: 36 additions & 0 deletions src/SLCore/Service/Issue/Models/EffectiveIssueDetailsDto.cs
Original file line number Diff line number Diff line change
@@ -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<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto>))] Either<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto> description,
[JsonProperty("params")] List<EffectiveRuleParamDto> parameters,
[JsonConverter(typeof(EitherJsonConverter<StandardModeDetails, MQRModeDetails>))] Either<StandardModeDetails, MQRModeDetails> severityDetails,
string ruleDescriptionContextKey);

0 comments on commit 9f15429

Please sign in to comment.