Skip to content

Commit

Permalink
Merge pull request #53 from kysect/feat/ca-title-parsing
Browse files Browse the repository at this point in the history
Implement CA* rule title parsing
  • Loading branch information
FrediKats authored Sep 5, 2023
2 parents 58d2e0c + 2094c69 commit 8d0a03f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kysect.Editorconfig" Version="1.0.4" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kysect.Editorconfig" Version="1.0.4" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public string FormatQualityRule(CodeStyleRoslynQualityRuleConfiguration rule)
{
var builder = new MarkdownStringBuilder();

builder.AddH2(rule.Rule.RuleId.ToString());
builder.AddH2($"{rule.Rule.Title} ({rule.Rule.RuleId})");
builder.AddEmptyLine();
builder.AddText($"Severity: {rule.Severity}");

Expand Down
2 changes: 1 addition & 1 deletion Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Kysect.CommonLib" Version="0.1.6" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.4" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.5" />
<PackageReference Include="Markdig" Version="0.33.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public IReadOnlyCollection<RoslynQualityRule> ParseQualityRules(string info)
MsLearnPropertyValueDescriptionTable table = _msLearnTableParser.Parse(markdownTableContent);

MsLearnPropertyValueDescriptionTableRow ruleId = table.GetSingleValue("Rule ID");
MsLearnPropertyValueDescriptionTableRow title = table.GetSingleValue("Title");
MsLearnPropertyValueDescriptionTableRow category = table.GetSingleValue("Category");
// TODO: add this fields to model
MsLearnPropertyValueDescriptionTableRow breakingChanges = table.GetSingleValue("Fix is breaking or non-breaking");
Expand All @@ -136,8 +137,7 @@ public IReadOnlyCollection<RoslynQualityRule> ParseQualityRules(string info)
return ruleIds
.Select(id => new RoslynQualityRule(
id,
// TODO: #40 parse rule name
ruleName: string.Empty,
title.Value,
category.Value,

Check failure on line 141 in Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
// TODO: #41 parse description

Check failure on line 142 in Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs

View workflow job for this annotation

GitHub Actions / build

Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
description: string.Empty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ private static void ValidateTableHeader(MarkdownTableContent simpleTable)
if (simpleTable.Headers.Count != 2 && simpleTable.Headers.Count != 3)
throw new ArgumentException($"Unexpected column count in property-value table. Expected 2 or 3, but was {simpleTable.Headers.Count}");

// TODO: This validation sometimes throw error. In some cases table has "Item" column instead of "Property".
// Maybe we need to drop it.
//string[] expectedHeaders = { "Property", "Value", "Description" };
//for (int i = 0; i < simpleTable.Headers.Count; i++)
//{
// if (!string.IsNullOrEmpty(simpleTable.Headers[i]) && simpleTable.Headers[i] != expectedHeaders[i])
// throw new ArgumentException($"Table header on index {i} must be equal to {expectedHeaders[i]} but was {simpleTable.Headers[i]}");
//}
string[] expectedHeaders = { "Property", "Value", "Description" };
for (int i = 0; i < simpleTable.Headers.Count; i++)
{
if (simpleTable.Headers[i] != expectedHeaders[i])
throw new ArgumentException($"Table header on index {i} must be equal to {expectedHeaders[i]} but was {simpleTable.Headers[i]}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
public class RoslynQualityRule
{
public RoslynRuleId RuleId { get; }
public string RuleName { get; }
public string Title { get; }
public string Category { get; }
public string Description { get; }

public RoslynQualityRule(RoslynRuleId ruleId, string ruleName, string category, string description)
public RoslynQualityRule(RoslynRuleId ruleId, string title, string category, string description)
{
RuleId = ruleId;
RuleName = ruleName;
Title = title;
Category = category;
Description = description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ class MyClass
[Test]
public void FormatQualityRule_ForCA1064_ReturnExpected()
{
// TODO: change CA1064 -> Exceptions should be public (CA1064)
// TODO: add description
const string expected = """
## CA1064
## Exceptions should be public (CA1064)

Severity: Warning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void ParseQualityRule_CA1865_CA1867_ReturnExpectedResult()
// TODO: parse description
var expected = new RoslynQualityRule(
RoslynRuleId.Parse("CA1865"),
// TODO: parse name?
ruleName: string.Empty,
"Use 'string.Method(char)' instead of 'string.Method(string)' for string with single char",
category: "Performance",
// TODO: parse description?
description: string.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MsLearnTableParserTests
public void Parse_KeyValueTable_ReturnExpectedResult()
{
string input = """
| | Value |
| Property | Value |
|-------------------------------------|------------------------------|
| **Rule ID** | CA1000 |
| **Category** | [Design](design-warnings.md) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class MyClass

public static RoslynQualityRule CA1064()
{
// TODO: parse description
return new RoslynQualityRule(
RoslynRuleId.Parse("CA1064"),
string.Empty,
"Exceptions should be public",
"Design",
// TODO: parse description
string.Empty);
}
}
2 changes: 1 addition & 1 deletion ms-learn
Submodule ms-learn updated 323 files

0 comments on commit 8d0a03f

Please sign in to comment.