Skip to content

Commit

Permalink
Add ListAllStandaloneRulesDefinitions to IRulesRpcService (#5284)
Browse files Browse the repository at this point in the history
Part of #5265
  • Loading branch information
1 parent 5b82b42 commit 992c531
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public void DeserializeSlcoreResponse_AsExpected()
.Should()
.BeEquivalentTo(expectedRuleDetails,
options => options
.ComparingByMembers<GetEffectiveRuleDetailsResponse>()
.ComparingByMembers<EffectiveRuleDetailsDto>()
.WithStrictOrdering()
.RespectingDeclaredTypes()
.Excluding((IMemberInfo info) => info.RuntimeType == typeof(string) && info.SelectedMemberPath.EndsWith(".content.Left.htmlContent")));
Expand Down
18 changes: 2 additions & 16 deletions src/SLCore/Service/Rules/GetEffectiveRuleDetailsParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Diagnostics.CodeAnalysis;
namespace SonarLint.VisualStudio.SLCore.Service.Rules;

namespace SonarLint.VisualStudio.SLCore.Service.Rules
{
[ExcludeFromCodeCoverage]
public class GetEffectiveRuleDetailsParams
{
public string configurationScopeId { get; }
public string ruleKey { get; }

public GetEffectiveRuleDetailsParams(string configurationScopeId, string ruleKey)
{
this.configurationScopeId = configurationScopeId;
this.ruleKey = ruleKey;
}
}
}
public record GetEffectiveRuleDetailsParams(string configurationScopeId, string ruleKey);
13 changes: 2 additions & 11 deletions src/SLCore/Service/Rules/GetEffectiveRuleDetailsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@

using SonarLint.VisualStudio.SLCore.Service.Rules.Models;

namespace SonarLint.VisualStudio.SLCore.Service.Rules
{
public class GetEffectiveRuleDetailsResponse
{
public GetEffectiveRuleDetailsResponse(EffectiveRuleDetailsDto details)
{
this.details = details;
}
namespace SonarLint.VisualStudio.SLCore.Service.Rules;

public EffectiveRuleDetailsDto details { get; }
}
}
public record GetEffectiveRuleDetailsResponse(EffectiveRuleDetailsDto details);
22 changes: 13 additions & 9 deletions src/SLCore/Service/Rules/IRulesRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
using SonarLint.VisualStudio.SLCore.Core;
using SonarLint.VisualStudio.SLCore.Protocol;

namespace SonarLint.VisualStudio.SLCore.Service.Rules
namespace SonarLint.VisualStudio.SLCore.Service.Rules;

[JsonRpcClass("rule")]
public interface IRulesRpcService : ISLCoreService
{
[JsonRpcClassAttribute("rule")]
public interface IRulesRpcService : ISLCoreService
{
/// <summary>
/// Gets Rule Meta Data from SLCORE
/// </summary>
Task<GetEffectiveRuleDetailsResponse> GetEffectiveRuleDetailsAsync(GetEffectiveRuleDetailsParams parameters);
}
/// <summary>
/// Gets Rule Meta Data from SLCORE
/// </summary>
Task<GetEffectiveRuleDetailsResponse> GetEffectiveRuleDetailsAsync(GetEffectiveRuleDetailsParams parameters);

/// <summary>
/// Lists all available standalone rule definitions
/// </summary>
Task<ListAllStandaloneRulesDefinitionsResponse> ListAllStandaloneRulesDefinitionsAsync();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.Diagnostics.CodeAnalysis;
using SonarLint.VisualStudio.SLCore.Service.Rules.Models;

namespace SonarLint.VisualStudio.SLCore.Service.Rules;

[ExcludeFromCodeCoverage]
public record ListAllStandaloneRulesDefinitionsResponse(Dictionary<string, RuleDefinitionDto> rulesByKey);
46 changes: 11 additions & 35 deletions src/SLCore/Service/Rules/Models/AbstractRuleDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,15 @@
using System.Collections.Generic;
using SonarLint.VisualStudio.SLCore.Common.Models;

namespace SonarLint.VisualStudio.SLCore.Service.Rules.Models
{
public abstract class AbstractRuleDto
{
protected AbstractRuleDto(string key,
string name,
IssueSeverity severity,
RuleType type,
CleanCodeAttribute? cleanCodeAttribute,
CleanCodeAttributeCategory? cleanCodeAttributeCategory,
List<ImpactDto> defaultImpacts,
Language language,
VulnerabilityProbability? vulnerabilityProbability)
{
this.key = key;
this.name = name;
this.severity = severity;
this.type = type;
this.cleanCodeAttribute = cleanCodeAttribute;
this.cleanCodeAttributeCategory = cleanCodeAttributeCategory;
this.defaultImpacts = defaultImpacts;
this.language = language;
this.vulnerabilityProbability = vulnerabilityProbability;
}
namespace SonarLint.VisualStudio.SLCore.Service.Rules.Models;

public string key { get; }
public string name { get; }
public IssueSeverity severity { get; }
public RuleType type { get; }
public CleanCodeAttribute? cleanCodeAttribute { get; }
public CleanCodeAttributeCategory? cleanCodeAttributeCategory { get; }
public List<ImpactDto> defaultImpacts { get; }
public Language language { get; }
public VulnerabilityProbability? vulnerabilityProbability { get; }
}
}
public abstract record AbstractRuleDto(
string key,
string name,
IssueSeverity severity,
RuleType type,
CleanCodeAttribute? cleanCodeAttribute,
CleanCodeAttributeCategory? cleanCodeAttributeCategory,
List<ImpactDto> defaultImpacts,
Language language,
VulnerabilityProbability? vulnerabilityProbability);
56 changes: 23 additions & 33 deletions src/SLCore/Service/Rules/Models/EffectiveRuleDetailsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,27 @@
using SonarLint.VisualStudio.SLCore.Common.Models;
using SonarLint.VisualStudio.SLCore.Protocol;

namespace SonarLint.VisualStudio.SLCore.Service.Rules.Models
{
public class EffectiveRuleDetailsDto : AbstractRuleDto
{
public EffectiveRuleDetailsDto(string key,
string name,
IssueSeverity severity,
RuleType type,
CleanCodeAttribute? cleanCodeAttribute,
CleanCodeAttributeCategory? cleanCodeAttributeCategory,
List<ImpactDto> defaultImpacts,
Language language,
VulnerabilityProbability? vulnerabilityProbability,
Either<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto> description,
List<EffectiveRuleParamDto> @params)
: base(key,
name,
severity,
type,
cleanCodeAttribute,
cleanCodeAttributeCategory,
defaultImpacts,
language,
vulnerabilityProbability)
{
this.description = description;
this.@params = @params;
}
namespace SonarLint.VisualStudio.SLCore.Service.Rules.Models;

[JsonConverter(typeof(EitherJsonConverter<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto>))]
public Either<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto> description { get; }
public List<EffectiveRuleParamDto> @params { get; }
}
}
public record EffectiveRuleDetailsDto(
string key,
string name,
IssueSeverity severity,
RuleType type,
CleanCodeAttribute? cleanCodeAttribute,
CleanCodeAttributeCategory? cleanCodeAttributeCategory,
List<ImpactDto> defaultImpacts,
Language language,
VulnerabilityProbability? vulnerabilityProbability,
[property: JsonConverter(typeof(EitherJsonConverter<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto>))]
Either<RuleMonolithicDescriptionDto, RuleSplitDescriptionDto> description,
List<EffectiveRuleParamDto> @params)
: AbstractRuleDto(key,
name,
severity,
type,
cleanCodeAttribute,
cleanCodeAttributeCategory,
defaultImpacts,
language,
vulnerabilityProbability);
48 changes: 48 additions & 0 deletions src/SLCore/Service/Rules/Models/RuleDefinitionDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.Diagnostics.CodeAnalysis;
using SonarLint.VisualStudio.SLCore.Common.Models;

namespace SonarLint.VisualStudio.SLCore.Service.Rules.Models;

[ExcludeFromCodeCoverage]
public record RuleDefinitionDto(
string key,
string name,
IssueSeverity severity,
RuleType type,
CleanCodeAttribute? cleanCodeAttribute,
CleanCodeAttributeCategory? cleanCodeAttributeCategory,
List<ImpactDto> defaultImpacts,
Language language,
VulnerabilityProbability? vulnerabilityProbability,
Dictionary<string, object> paramsByKey, // object because we ignore rule parameters at the moment
bool isActiveByDefault)
: AbstractRuleDto(key,
name,
severity,
type,
cleanCodeAttribute,
cleanCodeAttributeCategory,
defaultImpacts,
language,
vulnerabilityProbability);

0 comments on commit 992c531

Please sign in to comment.