From de0c62af44255087261909db5b57b6a6eedb043a Mon Sep 17 00:00:00 2001 From: Georgii Borovinskikh <117642191+georgii-borovinskikh-sonarsource@users.noreply.github.com> Date: Fri, 27 Dec 2024 15:34:54 +0100 Subject: [PATCH] SLVS-1691 Remove unused SQ.Client GetRules requests and properties (#5926) [SLVS-1691](https://sonarsource.atlassian.net/browse/SLVS-1691) [SLVS-1691]: https://sonarsource.atlassian.net/browse/SLVS-1691?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- .../CSharpVBBindingConfigProviderTests.cs | 14 +-- .../Binding/GlobalConfigGeneratorTests.cs | 2 +- .../RoslynPluginRuleKeyExtensionsTests.cs | 2 +- .../CSharpVB/SonarLintConfigGeneratorTests.cs | 4 +- .../XamlGenerator/RichRuleHelpXamlBuilder.cs | 3 +- .../DefaultConfiguration_Configure_Tests.cs | 2 - .../SonarQubeService_ExtensionMethods.cs | 18 ++-- .../SonarQubeService_GetRuleByKeyAsync.cs | 49 +--------- .../SonarQubeService_GetRulesAsync.cs | 91 +------------------ .../Api/DefaultConfiguration.cs | 2 - .../Api/V10_2/GetRulesWithCCTRequest.cs | 11 +-- .../Api/V5_50/GetRulesRequest.cs | 63 +------------ .../GetRulesWithDescriptionSectionsRequest.cs | 59 ------------ .../GetRulesWithEducationPrinciplesRequest.cs | 58 ------------ .../Models/SonarQubeDescriptionSection.cs | 38 -------- src/SonarQube.Client/Models/SonarQubeRule.cs | 31 +------ 16 files changed, 40 insertions(+), 407 deletions(-) delete mode 100644 src/SonarQube.Client/Api/V9_5/GetRulesWithDescriptionSectionsRequest.cs delete mode 100644 src/SonarQube.Client/Api/V9_6/GetRulesWithEducationPrinciplesRequest.cs delete mode 100644 src/SonarQube.Client/Models/SonarQubeDescriptionSection.cs diff --git a/src/ConnectedMode.UnitTests/Binding/CSharpVBBindingConfigProviderTests.cs b/src/ConnectedMode.UnitTests/Binding/CSharpVBBindingConfigProviderTests.cs index f95f5b03ac..93f594e133 100644 --- a/src/ConnectedMode.UnitTests/Binding/CSharpVBBindingConfigProviderTests.cs +++ b/src/ConnectedMode.UnitTests/Binding/CSharpVBBindingConfigProviderTests.cs @@ -42,16 +42,16 @@ public class CSharpVBBindingConfigProviderTests private SonarQubeQualityProfile validQualityProfile; private static readonly SonarQubeRule ActiveRuleWithUnsupportedSeverity = new SonarQubeRule("activeHotspot", "any1", - true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot, null, null, null, null, null, null); + true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot); private static readonly SonarQubeRule InactiveRuleWithUnsupportedSeverity = new SonarQubeRule("inactiveHotspot", "any2", - false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot, null, null, null, null, null, null); + false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.SecurityHotspot); private static readonly SonarQubeRule ActiveTaintAnalysisRule = new SonarQubeRule("activeTaint", "roslyn.sonaranalyzer.security.foo", - true, SonarQubeIssueSeverity.Blocker, null, null,null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null); + true, SonarQubeIssueSeverity.Blocker, null, null,null, SonarQubeIssueType.CodeSmell); private static readonly SonarQubeRule InactiveTaintAnalysisRule = new SonarQubeRule("inactiveTaint", "roslyn.sonaranalyzer.security.bar", - false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null); + false, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell); [TestInitialize] public void TestInitialize() @@ -60,7 +60,7 @@ public void TestInitialize() validRules = new List { - new SonarQubeRule("key", "repoKey", true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.Bug, null, null, null, null, null, null) + new SonarQubeRule("key", "repoKey", true, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.Bug) }; anyProperties = Array.Empty(); @@ -261,13 +261,13 @@ public void IsSupportedRule_TaintRules(string repositoryKey, bool expected) [DataRow(SonarQubeIssueType.Vulnerability, true)] public void IsSupportedRule_Severity(SonarQubeIssueType issueType, bool expected) { - var rule = new SonarQubeRule("any", "any", true, SonarQubeIssueSeverity.Blocker, null, null, null, issueType, null, null, null, null, null, null); + var rule = new SonarQubeRule("any", "any", true, SonarQubeIssueSeverity.Blocker, null, null, null, issueType); CSharpVBBindingConfigProvider.IsSupportedRule(rule).Should().Be(expected); } private static SonarQubeRule CreateRule(string ruleKey, string repoKey, bool isActive) => - new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell, null, null, null, null, null, null); + new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Blocker, null, null, null, SonarQubeIssueType.CodeSmell); private class TestEnvironmentBuilder { diff --git a/src/ConnectedMode.UnitTests/Binding/GlobalConfigGeneratorTests.cs b/src/ConnectedMode.UnitTests/Binding/GlobalConfigGeneratorTests.cs index f919535536..711b8d2e5b 100644 --- a/src/ConnectedMode.UnitTests/Binding/GlobalConfigGeneratorTests.cs +++ b/src/ConnectedMode.UnitTests/Binding/GlobalConfigGeneratorTests.cs @@ -133,7 +133,7 @@ public void GetVSSeverity_Invalid_Throws(SonarQubeIssueSeverity sqSeverity) } private static SonarQubeRule CreateRule(string ruleKey, string repoKey, bool isActive = true) => - new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Info, null, null, new Dictionary(), SonarQubeIssueType.Unknown, null, null, null, null, null, null); + new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Info, null, null, new Dictionary(), SonarQubeIssueType.Unknown); private string GetRuleString(string expectedKey, string expectedSeverity) => $"dotnet_diagnostic.{expectedKey}.severity = {expectedSeverity}"; diff --git a/src/Core.UnitTests/CSharpVB/RoslynPluginRuleKeyExtensionsTests.cs b/src/Core.UnitTests/CSharpVB/RoslynPluginRuleKeyExtensionsTests.cs index 57a9da20bb..599561cf44 100644 --- a/src/Core.UnitTests/CSharpVB/RoslynPluginRuleKeyExtensionsTests.cs +++ b/src/Core.UnitTests/CSharpVB/RoslynPluginRuleKeyExtensionsTests.cs @@ -38,7 +38,7 @@ public class RoslynPluginRuleKeyExtensionsTests [DataRow("vbnet", "sonaranalyzer-vbnet")] // special case for SonarVBNet public void TryGetPrefix(string ruleKey, string expectedPrefix) { - var rule = new SonarQubeRule("any", ruleKey, false, SonarQubeIssueSeverity.Unknown, null, null, null, SonarQubeIssueType.Unknown, null, null, null, null, null, null); + var rule = new SonarQubeRule("any", ruleKey, false, SonarQubeIssueSeverity.Unknown, null, null, null, SonarQubeIssueType.Unknown); rule.TryGetRoslynPluginPropertyPrefix().Should().Be(expectedPrefix); } diff --git a/src/Core.UnitTests/CSharpVB/SonarLintConfigGeneratorTests.cs b/src/Core.UnitTests/CSharpVB/SonarLintConfigGeneratorTests.cs index 9ccc09569a..f9f2f8a536 100644 --- a/src/Core.UnitTests/CSharpVB/SonarLintConfigGeneratorTests.cs +++ b/src/Core.UnitTests/CSharpVB/SonarLintConfigGeneratorTests.cs @@ -374,8 +374,8 @@ public void Generate_Serialized_ReturnsExpectedXml() private static SonarQubeRule CreateRuleWithValidParams(string ruleKey, string repoKey) => CreateRule(ruleKey, repoKey, ValidParams); - private static SonarQubeRule CreateRule(string ruleKey, string repoKey, IDictionary parameters = null, string description = null, IReadOnlyList descriptionSections = null, IReadOnlyList educationPrinciples = null, string name = null, IReadOnlyList tags = null, string htmlNote = null) => - new SonarQubeRule(ruleKey, repoKey, isActive: false, SonarQubeIssueSeverity.Blocker, null, null, parameters, SonarQubeIssueType.Unknown, description, descriptionSections, educationPrinciples, name, tags, htmlNote); + private static SonarQubeRule CreateRule(string ruleKey, string repoKey, IDictionary parameters = null) => + new SonarQubeRule(ruleKey, repoKey, isActive: false, SonarQubeIssueSeverity.Blocker, null, null, parameters, SonarQubeIssueType.Unknown); private Language ToLanguage(string sqLanguageKey) => Language.GetLanguageFromLanguageKey(sqLanguageKey); } diff --git a/src/Education/XamlGenerator/RichRuleHelpXamlBuilder.cs b/src/Education/XamlGenerator/RichRuleHelpXamlBuilder.cs index 5d6921d3a5..011eda7285 100644 --- a/src/Education/XamlGenerator/RichRuleHelpXamlBuilder.cs +++ b/src/Education/XamlGenerator/RichRuleHelpXamlBuilder.cs @@ -31,12 +31,11 @@ internal interface IRichRuleHelpXamlBuilder /// /// Generates a XAML document containing the help information for the specified rule /// - /// Assumes that the and are parseable as XML. + /// Assumes that the and contents are parseable as XML. /// Also assumes that the containing control defines a list of Style resources, one for each /// value in the enum . /// The document will still render if a style is missing, but the styling won't be correct. /// Rule description information - /// Key for the How to fix it Context acquired from a specific issue FlowDocument Create(IRuleInfo ruleInfo); } diff --git a/src/SonarQube.Client.Tests/Requests/DefaultConfiguration_Configure_Tests.cs b/src/SonarQube.Client.Tests/Requests/DefaultConfiguration_Configure_Tests.cs index 59ade660a9..90162354a9 100644 --- a/src/SonarQube.Client.Tests/Requests/DefaultConfiguration_Configure_Tests.cs +++ b/src/SonarQube.Client.Tests/Requests/DefaultConfiguration_Configure_Tests.cs @@ -62,8 +62,6 @@ public void ConfigureSonarQube_Writes_Debug_Messages() "Registered SonarQube.Client.Api.V8_6.GetHotspotRequest for 8.6", "Registered SonarQube.Client.Api.V7_20.GetExclusionsRequest for 7.2", "Registered SonarQube.Client.Api.V9_4.GetSonarLintEventStream for 9.4", - "Registered SonarQube.Client.Api.V9_5.GetRulesWithDescriptionSectionsRequest for 9.5", - "Registered SonarQube.Client.Api.V9_6.GetRulesWithEducationPrinciplesRequest for 9.6", "Registered SonarQube.Client.Api.V9_7.SearchHotspotRequest for 9.7", "Registered SonarQube.Client.Api.V10_2.SearchHotspotRequest for 10.2", "Registered SonarQube.Client.Api.V10_2.GetRulesWithCCTRequest for 10.2", diff --git a/src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs b/src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs index db88f83b3f..b664e903ba 100644 --- a/src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs +++ b/src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs @@ -36,7 +36,7 @@ public async Task GetAllRulesAsync_FetchesActiveAndInactive() await ConnectToSonarQube(); // One active rule - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 1, ""p"": 1, @@ -48,13 +48,11 @@ public async Task GetAllRulesAsync_FetchesActiveAndInactive() ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } @@ -94,7 +92,7 @@ public async Task GetAllRulesAsync_FetchesActiveAndInactive() "); // One inactive rule - SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 1, ""p"": 1, @@ -135,10 +133,10 @@ public async Task GetAllRulesAsync_OnlyActiveRulesExist_AreFetched() // One active rule, no inactive rules var ruleJson = SingleValidRuleJson("repo1", "rule1"); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", ruleJson); - SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", NoRulesJson); var result = await service.GetAllRulesAsync("quality-profile-1", CancellationToken.None); @@ -157,10 +155,10 @@ public async Task GetAllRulesAsync_OnlyInactiveRulesExist_AreFetched() // One active rule, no inactive rules var ruleJson = SingleValidRuleJson("repo1", "rule1"); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", NoRulesJson); - SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", ruleJson); var result = await service.GetAllRulesAsync("quality-profile-1", CancellationToken.None); @@ -180,10 +178,10 @@ public async Task GetAllRulesAsync_GetInactiveFails_ExceptionIsPropogated() // One active rule, no inactive rules var ruleJson = SingleValidRuleJson("repo1", "rule1"); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", ruleJson); - SetupRequestWithOperation("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", + SetupRequestWithOperation("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", () => { throw new InvalidOperationException("xxx"); }); // Act diff --git a/src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs b/src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs index 9daffaa49b..6e3622c3f6 100644 --- a/src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs +++ b/src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs @@ -37,7 +37,7 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule() await ConnectToSonarQube("10.2.0.0"); SetupRequest( - "api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote%2CdescriptionSections%2CeducationPrinciples%2CcleanCodeAttribute&p=1&ps=500", + "api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342&f=repo%2CinternalKey%2Cparams%2Cactives%2CcleanCodeAttribute&p=1&ps=500", @" { ""total"": 1, @@ -47,52 +47,28 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule() { ""key"": ""csharpsquid:S2342"", ""repo"": ""csharpsquid"", - ""htmlDesc"": ""Html Description"", - ""htmlNote"": ""HTML Note"", - ""name"": ""RuleName"", - ""tags"": [""tag1"",""tag2""], ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } ], ""type"": ""CODE_SMELL"", ""cleanCodeAttributeCategory"": ""INTENTIONAL"", - ""cleanCodeAttribute"": ""CLEAR"", + ""cleanCodeAttribute"": ""CLEAR"", ""impacts"": [ { ""softwareQuality"": ""RELIABILITY"", ""severity"": ""MEDIUM"" } - ], - ""descriptionSections"" : [ - { - ""key"": ""key1"", - ""content"": ""content1"" - }, - { - ""key"": ""key2"", - ""content"": ""content2"", - ""context"":{ - ""displayName"":""displayName"", - ""key"":""key"" - } - } - ], - ""educationPrinciples"": [ - ""education principle 1"", - ""education principle 2"" - ] - }, + ] + } ], ""actives"": { ""csharpsquid:S2225"": [ @@ -153,26 +129,11 @@ public async Task GetRuleByKeyAsync_RuleIsFound_ReturnsRule() result.Key.Should().Be("S2342"); result.RepositoryKey.Should().Be("csharpsquid"); - result.Description.Should().Be("Html Description"); - result.HtmlNote.Should().Be("HTML Note"); result.Severity.Should().Be(SonarQubeIssueSeverity.Minor); - result.Name.Should().Be("RuleName"); - result.Tags.Should().BeEquivalentTo(new[] { "tag1", "tag2" }); result.CleanCodeAttribute.Should().Be(SonarQubeCleanCodeAttribute.Clear); result.SoftwareQualitySeverities.Should().BeEquivalentTo( new Dictionary { { SonarQubeSoftwareQuality.Reliability, SonarQubeSoftwareQualitySeverity.Medium } }); - - result.DescriptionSections.Count.Should().Be(2); - result.DescriptionSections[0].Key.Should().Be("key1"); - result.DescriptionSections[0].HtmlContent.Should().Be("content1"); - result.DescriptionSections[0].Context.Should().BeNull(); - - result.DescriptionSections[1].Key.Should().Be("key2"); - result.DescriptionSections[1].HtmlContent.Should().Be("content2"); - result.DescriptionSections[1].Context.Should().NotBeNull(); - result.DescriptionSections[1].Context.Key.Should().Be("key"); - result.DescriptionSections[1].Context.DisplayName.Should().Be("displayName"); } [TestMethod] @@ -180,7 +141,7 @@ public async Task GetRuleByKeyAsync_RuleIsNotFound_ReturnsNull() { await ConnectToSonarQube(); - SetupRequest("api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342XX&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @"{ + SetupRequest("api/rules/search?qprofile=qpKey&rule_key=csharpsquid%3AS2342XX&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @"{ ""total"": 0, ""p"": 1, ""ps"": 100, diff --git a/src/SonarQube.Client.Tests/SonarQubeService_GetRulesAsync.cs b/src/SonarQube.Client.Tests/SonarQubeService_GetRulesAsync.cs index ac346e6287..28997c05ee 100644 --- a/src/SonarQube.Client.Tests/SonarQubeService_GetRulesAsync.cs +++ b/src/SonarQube.Client.Tests/SonarQubeService_GetRulesAsync.cs @@ -37,7 +37,7 @@ public async Task GetRulesAsync_Old_Active_SonarQubeResponse() { await ConnectToSonarQube(); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 4, ""p"": 1, @@ -58,19 +58,14 @@ public async Task GetRulesAsync_Old_Active_SonarQubeResponse() { ""key"": ""csharpsquid:S2342"", ""repo"": ""csharpsquid"", - ""htmlDesc"": ""Html Description"", - ""name"": ""RuleName"", - ""tags"": [""tag1"",""tag2""], ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } @@ -144,8 +139,6 @@ public async Task GetRulesAsync_Old_Active_SonarQubeResponse() result.SelectMany(r => r.Parameters.Select(p => p.Key)).Should().ContainInOrder(new[] { "format", "flagsAttributeFormat" }); result.SelectMany(r => r.Parameters.Select(p => p.Value)).Should().ContainInOrder(new[] { "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$" }); - result[2].Description.Should().Be("Html Description"); - // All rules with empty parameters should return the same (read-only) object // 0 = S2225, no params; 1 = S4524, no params; 2 = S2342, has params result[0].Parameters.Should().NotBeNull(); @@ -159,7 +152,7 @@ public async Task GetRulesAsync_9_6_Active_SonarQubeResponse() { await ConnectToSonarQube(version: "9.6.0.0"); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote%2CdescriptionSections%2CeducationPrinciples&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 4, ""p"": 1, @@ -180,42 +173,19 @@ public async Task GetRulesAsync_9_6_Active_SonarQubeResponse() { ""key"": ""csharpsquid:S2342"", ""repo"": ""csharpsquid"", - ""htmlDesc"": ""Html Description"", - ""name"": ""RuleName"", - ""tags"": [""tag1"",""tag2""], ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } ], - ""type"": ""CODE_SMELL"", - ""descriptionSections"" : [ - { - ""key"": ""key1"", - ""content"": ""content1"" - }, - { - ""key"": ""key2"", - ""content"": ""content2"", - ""context"":{ - ""displayName"":""displayName"", - ""key"":""key"" - } - } - ], - ""educationPrinciples"": [ - ""education principle 1"", - ""education principle 2"" - ] + ""type"": ""CODE_SMELL"" }, ], ""actives"": { @@ -284,23 +254,6 @@ public async Task GetRulesAsync_9_6_Active_SonarQubeResponse() result.SelectMany(r => r.Parameters.Select(p => p.Key)).Should().ContainInOrder(new[] { "format", "flagsAttributeFormat" }); result.SelectMany(r => r.Parameters.Select(p => p.Value)).Should().ContainInOrder(new[] { "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$" }); - result[2].Description.Should().Be("Html Description"); - - result[2].DescriptionSections.Count.Should().Be(2); - result[2].DescriptionSections[0].Key.Should().Be("key1"); - result[2].DescriptionSections[0].HtmlContent.Should().Be("content1"); - result[2].DescriptionSections[0].Context.Should().BeNull(); - - result[2].DescriptionSections[1].Key.Should().Be("key2"); - result[2].DescriptionSections[1].HtmlContent.Should().Be("content2"); - result[2].DescriptionSections[1].Context.Should().NotBeNull(); - result[2].DescriptionSections[1].Context.Key.Should().Be("key"); - result[2].DescriptionSections[1].Context.DisplayName.Should().Be("displayName"); - - result[2].EducationPrinciples.Count.Should().Be(2); - result[2].EducationPrinciples[0].Should().Be("education principle 1"); - result[2].EducationPrinciples[1].Should().Be("education principle 2"); - // All rules with empty parameters should return the same (read-only) object // 0 = S2225, no params; 1 = S4524, no params; 2 = S2342, has params result[0].Parameters.Should().NotBeNull(); @@ -314,7 +267,7 @@ public async Task GetRulesAsync_9_5_Active_SonarQubeResponse() { await ConnectToSonarQube(version: "9.5.0.0"); - SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote%2CdescriptionSections&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=true&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 4, ""p"": 1, @@ -335,38 +288,19 @@ public async Task GetRulesAsync_9_5_Active_SonarQubeResponse() { ""key"": ""csharpsquid:S2342"", ""repo"": ""csharpsquid"", - ""htmlDesc"": ""Html Description"", - ""name"": ""RuleName"", - ""tags"": [""tag1"",""tag2""], ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } ], ""type"": ""CODE_SMELL"", - ""descriptionSections"" : [ - { - ""key"": ""key1"", - ""content"": ""content1"" - }, - { - ""key"": ""key2"", - ""content"": ""content2"", - ""context"":{ - ""displayName"":""displayName"", - ""key"":""key"" - } - } - ] }, ], ""actives"": { @@ -435,19 +369,6 @@ public async Task GetRulesAsync_9_5_Active_SonarQubeResponse() result.SelectMany(r => r.Parameters.Select(p => p.Key)).Should().ContainInOrder(new[] { "format", "flagsAttributeFormat" }); result.SelectMany(r => r.Parameters.Select(p => p.Value)).Should().ContainInOrder(new[] { "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$", "^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$" }); - result[2].Description.Should().Be("Html Description"); - - result[2].DescriptionSections.Count.Should().Be(2); - result[2].DescriptionSections[0].Key.Should().Be("key1"); - result[2].DescriptionSections[0].HtmlContent.Should().Be("content1"); - result[2].DescriptionSections[0].Context.Should().BeNull(); - - result[2].DescriptionSections[1].Key.Should().Be("key2"); - result[2].DescriptionSections[1].HtmlContent.Should().Be("content2"); - result[2].DescriptionSections[1].Context.Should().NotBeNull(); - result[2].DescriptionSections[1].Context.Key.Should().Be("key"); - result[2].DescriptionSections[1].Context.DisplayName.Should().Be("displayName"); - // All rules with empty parameters should return the same (read-only) object // 0 = S2225, no params; 1 = S4524, no params; 2 = S2342, has params result[0].Parameters.Should().NotBeNull(); @@ -461,7 +382,7 @@ public async Task GetRulesAsync_NotActive_SonarQubeResponse() { await ConnectToSonarQube(); - SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives%2ChtmlDesc%2Ctags%2Cname%2ChtmlNote&p=1&ps=500", @" + SetupRequest("api/rules/search?activation=false&qprofile=quality-profile-1&f=repo%2CinternalKey%2Cparams%2Cactives&p=1&ps=500", @" { ""total"": 4, ""p"": 1, @@ -485,13 +406,11 @@ public async Task GetRulesAsync_NotActive_SonarQubeResponse() ""params"": [ { ""key"": ""format"", - ""htmlDesc"": ""Regular expression used to check the enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$"", ""type"": ""STRING"" }, { ""key"": ""flagsAttributeFormat"", - ""htmlDesc"": ""Regular expression used to check the flags enumeration type names against."", ""defaultValue"": ""^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$"", ""type"": ""STRING"" } diff --git a/src/SonarQube.Client/Api/DefaultConfiguration.cs b/src/SonarQube.Client/Api/DefaultConfiguration.cs index df4278c584..73af91114f 100644 --- a/src/SonarQube.Client/Api/DefaultConfiguration.cs +++ b/src/SonarQube.Client/Api/DefaultConfiguration.cs @@ -55,8 +55,6 @@ public static RequestFactory ConfigureSonarQube(RequestFactory requestFactory) .RegisterRequest("8.6") .RegisterRequest("7.2") .RegisterRequest("9.4") - .RegisterRequest("9.5") - .RegisterRequest("9.6") .RegisterRequest("9.7") .RegisterRequest("10.2") .RegisterRequest("10.2") diff --git a/src/SonarQube.Client/Api/V10_2/GetRulesWithCCTRequest.cs b/src/SonarQube.Client/Api/V10_2/GetRulesWithCCTRequest.cs index 339834e286..83daa24bbd 100644 --- a/src/SonarQube.Client/Api/V10_2/GetRulesWithCCTRequest.cs +++ b/src/SonarQube.Client/Api/V10_2/GetRulesWithCCTRequest.cs @@ -32,19 +32,18 @@ namespace SonarQube.Client.Api.V10_2 { public class GetRulesWithCCTRequest : IGetRulesRequest { - private static readonly IList ResponseFieldsOverride = GetRulesWithEducationPrinciplesRequest - .ResponseFieldsOverride.Concat(new[] { "cleanCodeAttribute" }).ToArray(); - + private static readonly IList ResponseFieldsOverride = GetRulesRequest.ResponseList.Concat(new[] { "cleanCodeAttribute" }).ToArray(); + private readonly GetRulesRequest innerRequest = new GetRulesRequest(); - + public ILogger Logger { get; set; } public int Page { get; set; } public int PageSize { get; set; } - public int ItemsLimit { get; set; } + public int ItemsLimit { get; set; } public bool? IsActive { get; set; } public string QualityProfileKey { get; set; } public string RuleKey { get; set; } - + public async Task InvokeAsync(HttpClient httpClient, CancellationToken token) { innerRequest.IsActive = this.IsActive; diff --git a/src/SonarQube.Client/Api/V5_50/GetRulesRequest.cs b/src/SonarQube.Client/Api/V5_50/GetRulesRequest.cs index 7b14efd324..ff352af6f1 100644 --- a/src/SonarQube.Client/Api/V5_50/GetRulesRequest.cs +++ b/src/SonarQube.Client/Api/V5_50/GetRulesRequest.cs @@ -18,8 +18,6 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -using System.Collections.Generic; -using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SonarQube.Client.Api.Common; @@ -49,7 +47,7 @@ public class GetRulesRequest : PagedRequestBase, IGetRulesRequest // Also Make sure the field is supported in this version of the API. // If not add a new request for API version that supports. e.g. "GetRulesWithDescriptionSectionsRequest" - internal static readonly IList ResponseList = new List { "repo", "internalKey", "params", "actives", "htmlDesc", "tags", "name", "htmlNote" }; + internal static readonly IList ResponseList = new List { "repo", "internalKey", "params", "actives" }; [JsonIgnore] internal IList ResponseListField { get; set; } = ResponseList; @@ -101,8 +99,6 @@ private SonarQubeRule ToSonarQubeRule(RuleResponse response, var issueType = SonarQubeIssueTypeConverter.Convert(response.Type); - var descriptionSections = response.DescriptionSections?.Select(ds => ds.ToSonarQubeDescriptionSection()).ToList(); - return new SonarQubeRule(GetRuleKey(response.Key), response.RepositoryKey, isActive, @@ -110,13 +106,7 @@ private SonarQubeRule ToSonarQubeRule(RuleResponse response, CleanCodeTaxonomyHelpers.ToSonarQubeCleanCodeAttribute(response.CleanCodeAttribute), CleanCodeTaxonomyHelpers.ToDefaultImpacts(response.Impacts), parameters, - issueType, - response.Description, - descriptionSections, - response.EducationPrinciples, - response.Name, - response.Tags, - response.HtmlNote); + issueType); } private static string GetRuleKey(string compositeKey) => @@ -130,27 +120,9 @@ private sealed class RuleResponse [JsonProperty("repo")] public string RepositoryKey { get; set; } - [JsonProperty("htmlDesc")] - public string Description { get; set; } - - [JsonProperty("htmlNote")] - public string HtmlNote { get; set; } - [JsonProperty("type")] public string Type { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("tags")] - public IReadOnlyList Tags { get; set; } - - [JsonProperty("descriptionSections")] - public IReadOnlyList DescriptionSections { get; set; } - - [JsonProperty("educationPrinciples")] - public IReadOnlyList EducationPrinciples { get; set; } - [JsonProperty("cleanCodeAttribute")] public string CleanCodeAttribute { get; set; } @@ -178,36 +150,5 @@ private sealed class ParameterResponse [JsonProperty("value")] public string Value { get; set; } } - - private sealed class DescriptionSectionResponse - { - [JsonProperty("key")] - public string Key { get; set; } - - [JsonProperty("content")] - public string HtmlContent { get; set; } - - [JsonProperty("context")] - public ContextResponse Context { get; set; } - - internal SonarQubeDescriptionSection ToSonarQubeDescriptionSection() - { - return new SonarQubeDescriptionSection(Key, HtmlContent, Context?.ToSonarQubeContex()); - } - } - - private sealed class ContextResponse - { - [JsonProperty("displayName")] - public string DisplayName { get; set; } - - [JsonProperty("key")] - public string Key { get; set; } - - internal SonarQubeContext ToSonarQubeContex() - { - return new SonarQubeContext(DisplayName, Key); - } - } } } diff --git a/src/SonarQube.Client/Api/V9_5/GetRulesWithDescriptionSectionsRequest.cs b/src/SonarQube.Client/Api/V9_5/GetRulesWithDescriptionSectionsRequest.cs deleted file mode 100644 index fceecea8f8..0000000000 --- a/src/SonarQube.Client/Api/V9_5/GetRulesWithDescriptionSectionsRequest.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using SonarQube.Client.Api.V5_50; -using SonarQube.Client.Logging; -using SonarQube.Client.Models; - -namespace SonarQube.Client.Api.V9_5 -{ - public class GetRulesWithDescriptionSectionsRequest : IGetRulesRequest - { - private static readonly IList ResponseFieldsOverride = GetRulesRequest.ResponseList.Concat(new List { "descriptionSections" }).ToList(); - - private readonly GetRulesRequest innerRequest = new GetRulesRequest(); - - public bool? IsActive { get; set; } - public string QualityProfileKey { get; set; } - public string RuleKey { get; set; } - public int Page { get; set; } - public int PageSize { get; set; } - public int ItemsLimit { get; set; } - public ILogger Logger { get; set; } - public IList ResponseFieldsList { get; set; } - - public async Task InvokeAsync(HttpClient httpClient, CancellationToken token) - { - innerRequest.IsActive = this.IsActive; - innerRequest.QualityProfileKey = this.QualityProfileKey; - innerRequest.RuleKey = this.RuleKey; - innerRequest.Logger = this.Logger; - - innerRequest.ResponseListField = ResponseFieldsOverride; - - return await innerRequest.InvokeAsync(httpClient, token); - } - } -} diff --git a/src/SonarQube.Client/Api/V9_6/GetRulesWithEducationPrinciplesRequest.cs b/src/SonarQube.Client/Api/V9_6/GetRulesWithEducationPrinciplesRequest.cs deleted file mode 100644 index 986640098a..0000000000 --- a/src/SonarQube.Client/Api/V9_6/GetRulesWithEducationPrinciplesRequest.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using SonarQube.Client.Api.V5_50; -using SonarQube.Client.Logging; -using SonarQube.Client.Models; - -namespace SonarQube.Client.Api.V9_6 -{ - public class GetRulesWithEducationPrinciplesRequest : IGetRulesRequest - { - internal static readonly IList ResponseFieldsOverride = GetRulesRequest.ResponseList.Concat(new List { "descriptionSections", "educationPrinciples" }).ToList(); - private readonly GetRulesRequest innerRequest = new GetRulesRequest(); - - public bool? IsActive { get; set; } - public string QualityProfileKey { get; set; } - public string RuleKey { get; set; } - public int Page { get; set; } - public int PageSize { get; set; } - public int ItemsLimit { get; set; } - public ILogger Logger { get; set; } - public IList ResponseFieldsList { get; set; } - - public async Task InvokeAsync(HttpClient httpClient, CancellationToken token) - { - innerRequest.IsActive = this.IsActive; - innerRequest.QualityProfileKey = this.QualityProfileKey; - innerRequest.RuleKey = this.RuleKey; - innerRequest.Logger = this.Logger; - - innerRequest.ResponseListField = ResponseFieldsOverride; - - return await innerRequest.InvokeAsync(httpClient, token); - } - } -} diff --git a/src/SonarQube.Client/Models/SonarQubeDescriptionSection.cs b/src/SonarQube.Client/Models/SonarQubeDescriptionSection.cs deleted file mode 100644 index ae5aebd5fd..0000000000 --- a/src/SonarQube.Client/Models/SonarQubeDescriptionSection.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 SonarQube.Client.Models -{ - public class SonarQubeDescriptionSection - { - public SonarQubeDescriptionSection(string key, string htmlContent, SonarQubeContext context) - { - Key = key; - HtmlContent = htmlContent; - Context = context; - } - - public string Key { get; } - - public string HtmlContent { get; } - - public SonarQubeContext Context { get; } - } -} diff --git a/src/SonarQube.Client/Models/SonarQubeRule.cs b/src/SonarQube.Client/Models/SonarQubeRule.cs index c500e25ea6..d603dfe0f7 100644 --- a/src/SonarQube.Client/Models/SonarQubeRule.cs +++ b/src/SonarQube.Client/Models/SonarQubeRule.cs @@ -37,28 +37,15 @@ public SonarQubeRule(string key, SonarQubeCleanCodeAttribute? cleanCodeAttribute, Dictionary softwareQualitySeverities, IDictionary parameters, - SonarQubeIssueType issueType, - string description, - IReadOnlyList descriptionSections, - IReadOnlyList educationPrinciples, - string name, - IReadOnlyList tags, - string htmlNote) - + SonarQubeIssueType issueType) { Key = key; RepositoryKey = repositoryKey; - Description = description; IsActive = isActive; Severity = severity; CleanCodeAttribute = cleanCodeAttribute; SoftwareQualitySeverities = softwareQualitySeverities; IssueType = issueType; - DescriptionSections = descriptionSections; - EducationPrinciples = educationPrinciples; - Name = name; - Tags = tags; - HtmlNote = htmlNote; if (parameters == null || parameters.Count == 0) { @@ -74,18 +61,12 @@ public SonarQubeRule(string key, public string RepositoryKey { get; } - public string Description { get; set; } - public bool IsActive { get; } - public string Name { get; } - - public IReadOnlyList Tags { get; } - public SonarQubeIssueSeverity Severity { get; } - + public SonarQubeCleanCodeAttribute? CleanCodeAttribute { get; } - + public Dictionary SoftwareQualitySeverities { get; } /// @@ -95,11 +76,5 @@ public SonarQubeRule(string key, public IReadOnlyDictionary Parameters { get; } public SonarQubeIssueType IssueType { get; } - - public IReadOnlyList DescriptionSections { get; } - - public IReadOnlyList EducationPrinciples { get; } - - public string HtmlNote { get; } } }