Skip to content

Commit

Permalink
SLVS-1691 Remove unused SQ.Client GetRules requests and properties (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource authored Dec 27, 2024
1 parent c1012fa commit 730a567
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -60,7 +60,7 @@ public void TestInitialize()

validRules = new List<SonarQubeRule>
{
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<SonarQubeProperty>();
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>(), SonarQubeIssueType.Unknown, null, null, null, null, null, null);
new SonarQubeRule(ruleKey, repoKey, isActive, SonarQubeIssueSeverity.Info, null, null, new Dictionary<string, string>(), SonarQubeIssueType.Unknown);

private string GetRuleString(string expectedKey, string expectedSeverity) =>
$"dotnet_diagnostic.{expectedKey}.severity = {expectedSeverity}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core.UnitTests/CSharpVB/SonarLintConfigGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> parameters = null, string description = null, IReadOnlyList<SonarQubeDescriptionSection> descriptionSections = null, IReadOnlyList<string> educationPrinciples = null, string name = null, IReadOnlyList<string> 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<string, string> parameters = null) =>
new SonarQubeRule(ruleKey, repoKey, isActive: false, SonarQubeIssueSeverity.Blocker, null, null, parameters, SonarQubeIssueType.Unknown);

private Language ToLanguage(string sqLanguageKey) => Language.GetLanguageFromLanguageKey(sqLanguageKey);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Education/XamlGenerator/RichRuleHelpXamlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ internal interface IRichRuleHelpXamlBuilder
/// <summary>
/// Generates a XAML document containing the help information for the specified rule
/// </summary>
/// <remarks>Assumes that the <see cref="IRuleInfo.Description"/> and <see cref="IRuleInfo.DescriptionSections"/> are parseable as XML.
/// <remarks>Assumes that the <see cref="IRuleInfo.Description"/> and <see cref="IRuleInfo.RichRuleDescriptionDto"/> contents are parseable as XML.
/// Also assumes that the containing control defines a list of Style resources, one for each
/// value in the enum <see cref="StyleResourceNames"/>.
/// The document will still render if a style is missing, but the styling won't be correct.</remarks>
/// <param name="ruleInfo">Rule description information</param>
/// <param name="issueContext">Key for the How to fix it Context acquired from a specific issue</param>
FlowDocument Create(IRuleInfo ruleInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 8 additions & 10 deletions src/SonarQube.Client.Tests/SonarQubeService_ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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""
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
49 changes: 5 additions & 44 deletions src/SonarQube.Client.Tests/SonarQubeService_GetRuleByKeyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"": [
Expand Down Expand Up @@ -153,34 +129,19 @@ 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, SonarQubeSoftwareQualitySeverity>
{ { 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]
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,
Expand Down
Loading

0 comments on commit 730a567

Please sign in to comment.