Skip to content

Commit

Permalink
Merge pull request #43 from kysect/refactor/update-todo
Browse files Browse the repository at this point in the history
Update TODO
  • Loading branch information
FrediKats authored Sep 2, 2023
2 parents 47b45c6 + d7f1587 commit f39476b
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private bool IsSupported(IEditorConfigSetting setting)
return false;
}

// TODO: Probably, most of this rules related to IDE1006
// TODO: #35 Probably, most of this rules related to IDE1006
if (setting is CompositeRoslynOptionEditorConfigSetting)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ private IEditorConfigSetting ParseSetting(IniFileLine line)
if (isSeveritySetting)
return ParseSeveritySetting(line);

// TODO: remove rule that force StringComparison for string comparing from project .editorconfig
bool isCompositeKeyRule = line.Key.Contains('.', StringComparison.InvariantCultureIgnoreCase);
bool isCompositeKeyRule = line.Key.Contains('.');
if (isCompositeKeyRule)
return ParseCompositeKeySetting(line);

Expand Down Expand Up @@ -74,14 +73,6 @@ private static CompositeRoslynOptionEditorConfigSetting ParseCompositeKeySetting

private static RoslynOptionEditorConfigSetting ParseOptionSetting(IniFileLine line)
{
bool containsSeverityInValue = line.Value.Contains(':', StringComparison.InvariantCultureIgnoreCase);
if (!containsSeverityInValue)
return new RoslynOptionEditorConfigSetting(line.Key, line.Value);

string[] valueParts = line.Value.Split(':', 2);
if (!Enum.TryParse(valueParts[1], true, out RoslynRuleSeverity severity))
throw new ArgumentException($"Cannot parse severity from {valueParts[1]}");

return new RoslynOptionEditorConfigSetting(line.Key, valueParts[0], severity);
return new RoslynOptionEditorConfigSetting(line.Key, line.Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ public record GeneralEditorConfigSetting(

public record RoslynOptionEditorConfigSetting(
string Key,
string Value,
// TODO: ensure that this is supported (severity per option)
RoslynRuleSeverity? Severity) : IEditorConfigSetting
{
public RoslynOptionEditorConfigSetting(string Key, string Value) : this(Key, Value, null)
{
}
}
string Value) : IEditorConfigSetting;

public record RoslynSeverityEditorConfigSetting(
RoslynRuleId RuleId,
Expand Down
7 changes: 3 additions & 4 deletions Sources/Kysect.Configuin.Core/IniParsing/IniParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ public IReadOnlyCollection<IniFileLine> Parse(string content)
if (string.IsNullOrEmpty(line))
continue;

// TODO: support case when comment is not in string start. Like:
// TODO: #37 support case when comment is not in string start. Like:
// key = value # some comment with symbol =
if (line.StartsWith("#"))
continue;

// TODO: support categories in future
// TODO: #38 support categories in future
if (line.StartsWith("["))
continue;

// TODO: remove rule that force StringComparison for string comparing from project .editorconfig
if (!line.Contains('=', StringComparison.InvariantCultureIgnoreCase))
if (!line.Contains('='))
throw new ArgumentException($"Line {line} does not contain '='");

string[] parts = line.Split('=');
Expand Down
4 changes: 2 additions & 2 deletions Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kysect.CommonLib" Version="0.1.0" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.3" />
<PackageReference Include="Kysect.CommonLib" Version="0.1.4" />
<PackageReference Include="Kysect.Editorconfig" Version="1.0.4" />
<PackageReference Include="Markdig" Version="0.31.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Markdig.Parsers;
using Kysect.Configuin.Core.MarkdownParsing.TextExtractor;
using Markdig.Parsers;
using Markdig.Syntax;

namespace Kysect.Configuin.Core.MarkdownParsing.Documents;
Expand All @@ -10,7 +11,7 @@ public static MarkdownDocument CreateFromString(string content)
return MarkdownParser.Parse(content, MarkdownPipelineProvider.GetDefault());
}

public static IReadOnlyCollection<MarkdownHeadedBlock> SplitByHeaders(this MarkdownDocument markdownDocument)
public static IReadOnlyCollection<MarkdownHeadedBlock> SplitByHeaders(this MarkdownDocument markdownDocument, IMarkdownTextExtractor textExtractor)
{
ArgumentNullException.ThrowIfNull(markdownDocument);

Expand All @@ -26,7 +27,7 @@ public static IReadOnlyCollection<MarkdownHeadedBlock> SplitByHeaders(this Markd
{
if (headingBlock is not null)
{
result.Add(new MarkdownHeadedBlock(headingBlock, blocks));
result.Add(new MarkdownHeadedBlock(textExtractor.ExtractText(headingBlock), blocks));
}

headingBlock = currentHeaderBlock;
Expand All @@ -40,7 +41,7 @@ public static IReadOnlyCollection<MarkdownHeadedBlock> SplitByHeaders(this Markd

if (headingBlock is not null)
{
result.Add(new MarkdownHeadedBlock(headingBlock, blocks));
result.Add(new MarkdownHeadedBlock(textExtractor.ExtractText(headingBlock), blocks));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
using Kysect.Configuin.Core.MarkdownParsing.TextExtractor;
using Markdig.Syntax;
using Markdig.Syntax;

namespace Kysect.Configuin.Core.MarkdownParsing.Documents;

public class MarkdownHeadedBlock
{
public HeadingBlock Header { get; }
public string HeaderText { get; }
public IReadOnlyCollection<Block> Content { get; }

public MarkdownHeadedBlock(HeadingBlock header, IReadOnlyCollection<Block> content)
public MarkdownHeadedBlock(string headerText, IReadOnlyCollection<Block> content)
{
Header = header;
HeaderText = headerText;
Content = content;
}

// TODO: remove this method and pass header text instead of header block
public string GetHeaderText()
{
return PlainTextExtractor.Create().ExtractText(Header);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public string ExtractText(Block block)
// KB: HtmlRenderer change '"' to "&quot;". Decode will change in back
return HttpUtility
.HtmlDecode(result)
// TODO: To smth with this =_=
.Replace("\r\n", "\n", StringComparison.InvariantCultureIgnoreCase)
.Replace("\n", Environment.NewLine, StringComparison.InvariantCultureIgnoreCase);
// TODO: Do smth with this =_=
.Replace("\r\n", "\n")
.Replace("\n", Environment.NewLine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Kysect.Configuin.Core.MsLearnDocumentation.Models;

// TODO: need more semantic naming
public record RoslynStyleRuleInformationTable(
RoslynRuleId RuleId,
string Title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public RoslynRules Parse(MsLearnDocumentationRawInfo rawInfo)
public IReadOnlyCollection<RoslynStyleRule> ParseStyleRules(string info)
{
MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(info);
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders();
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor);

if (markdownHeadedBlocks.Count == 0)
throw new ConfiguinException("Style rule markdown file does not contains any heading blocks. Cannot parse description");
Expand Down Expand Up @@ -101,15 +101,15 @@ private RoslynStyleRule ConvertToRule(
roslynStyleRuleInformationTable.Title,
roslynStyleRuleInformationTable.Category,
overviewText,
// TODO: support this?
// TODO: #39 support this
example: string.Empty,
roslynStyleRuleOptions);
}

public IReadOnlyCollection<RoslynQualityRule> ParseQualityRules(string info)
{
MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(info);
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders();
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor);

if (markdownHeadedBlocks.Count == 0)
throw new ConfiguinException("Style rule markdown file does not contains any heading blocks. Cannot parse description");
Expand All @@ -136,35 +136,34 @@ public IReadOnlyCollection<RoslynQualityRule> ParseQualityRules(string info)
return ruleIds
.Select(id => new RoslynQualityRule(
id,
// TODO: parse rule name
// TODO: #40 parse rule name
ruleName: string.Empty,
category.Value,
// TODO: parse description
// TODO: #41 parse description
description: string.Empty))
.ToList();
}

public IReadOnlyCollection<RoslynStyleRuleOption> ParseAdditionalFormattingOptions(string dotnetFormattingFileContent)
{
MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(dotnetFormattingFileContent);
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders();
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor);
return ParseOptions(markdownHeadedBlocks);
}

private IReadOnlyCollection<RoslynRuleId> ParseQualityRuleTableIdRow(MsLearnPropertyValueDescriptionTableRow ruleId)
{
// TODO: remove StringComparison
if (ruleId.Value.Contains("-", StringComparison.InvariantCultureIgnoreCase))
if (ruleId.Value.Contains("-"))
return RoslynRuleIdRange.Parse(ruleId.Value).Enumerate().ToList();

return new[] { RoslynRuleId.Parse(ruleId.Value) };
}

private string GetStyleOverviewText(IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks)
{
MarkdownHeadedBlock? overviewBlock = markdownHeadedBlocks.FirstOrDefault(h => h.GetHeaderText() == "Overview");
MarkdownHeadedBlock? overviewBlock = markdownHeadedBlocks.FirstOrDefault(h => h.HeaderText == "Overview");
if (overviewBlock is null)
// TODO: IDE0055
// TODO: Rule IDE0055 does not contains this block
//throw new ConfiguinException("Style rule page does not contains Overview block.");
return string.Empty;

Expand All @@ -187,8 +186,7 @@ private IReadOnlyCollection<RoslynStyleRuleOption> ParseOptions(IReadOnlyCollect
private bool HeaderForOption(MarkdownHeadedBlock markdownHeadedBlock)
{
// TODO: do it in better way?
// TODO: remove StringComparison
string headerText = markdownHeadedBlock.GetHeaderText();
string headerText = markdownHeadedBlock.HeaderText;

return headerText.StartsWith("dotnet_")
|| headerText.StartsWith("csharp_")
Expand All @@ -200,7 +198,7 @@ private RoslynStyleRuleOption ParseOption(MarkdownHeadedBlock optionBlock)
{
var tables = optionBlock.Content.OfType<Table>().ToList();
if (tables.Count != 1)
throw new ConfiguinException($"Unexpected table count in option block {optionBlock.GetHeaderText()}");
throw new ConfiguinException($"Unexpected table count in option block {optionBlock.HeaderText}");

MarkdownTableContent markdownTableContent = _markdownTableParser.ParseToSimpleContent(tables.Single());
MsLearnPropertyValueDescriptionTable table = _msLearnTableParser.Parse(markdownTableContent);
Expand All @@ -209,9 +207,9 @@ private RoslynStyleRuleOption ParseOption(MarkdownHeadedBlock optionBlock)
CodeBlock? csharpCodeBlock = codeBlocks
.OfType<FencedCodeBlock>()
.FirstOrDefault(cb => cb.Info == "csharp");
// TODO: use null instead of empty line
string csharpCodeSample = csharpCodeBlock is null
? ""

string? csharpCodeSample = csharpCodeBlock is null
? null
: _textExtractor.ExtractText(csharpCodeBlock);

MsLearnPropertyValueDescriptionTableRow optionName = table.GetSingleValue("Option name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class RoslynRules
{
public IReadOnlyCollection<RoslynQualityRule> QualityRules { get; }
public IReadOnlyCollection<RoslynStyleRule> StyleRules { get; }
// TODO: #42 This options is related to IDE0055
public IReadOnlyCollection<RoslynStyleRuleOption> DotnetFormattingOptions { get; }
public IReadOnlyCollection<RoslynStyleRuleOption> SharpFormattingOptions { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public record RoslynStyleRuleOption(
string Name,
IReadOnlyCollection<RoslynStyleRuleOptionValue> Options,
string? DefaultValue,
string CsharpCodeSample);
string? CsharpCodeSample);
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@
using Kysect.Configuin.Core.EditorConfigParsing;
using Kysect.Configuin.Core.CodeStyleGeneration;
using Kysect.Configuin.Core.CodeStyleGeneration.Models;
using Kysect.Configuin.Core.MarkdownParsing.TextExtractor;
using Kysect.Configuin.Tests.Tools;
using NUnit.Framework;

namespace Kysect.Configuin.Tests.CodeStyleGeneration;

public class CodeStyleGeneratorTests
{
private readonly MsLearnDocumentationParser _msLearnDocumentationParser;
private readonly EditorConfigSettingsParser _editorConfigSettingsParser;
private readonly MsLearnDocumentationInfoLocalProvider _repositoryPathProvider;

public CodeStyleGeneratorTests()
{
_editorConfigSettingsParser = new EditorConfigSettingsParser();
_msLearnDocumentationParser = new MsLearnDocumentationParser(PlainTextExtractor.Create());
_repositoryPathProvider = TestImplementations.CreateDocumentationInfoLocalProvider();
}
private readonly MsLearnDocumentationParser _msLearnDocumentationParser = new(TestImplementations.GetTextExtractor());
private readonly EditorConfigSettingsParser _editorConfigSettingsParser = new();
private readonly MsLearnDocumentationInfoLocalProvider _repositoryPathProvider = TestImplementations.CreateDocumentationInfoLocalProvider();

[Test]
public void Generate_ForAllMsLearnDocumentation_FinishWithoutErrors()

Check warning on line 19 in Sources/Kysect.Configuin.Tests/CodeStyleGeneration/CodeStyleGeneratorTests.cs

View workflow job for this annotation

GitHub Actions / build

Remove the underscores from member name Kysect.Configuin.Tests.CodeStyleGeneration.CodeStyleGeneratorTests.Generate_ForAllMsLearnDocumentation_FinishWithoutErrors() (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1707)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public void Parse_StyleOption_ReturnOptionRule()
string content = "csharp_style_var_when_type_is_apparent = true";
var expected = new RoslynOptionEditorConfigSetting(
Key: "csharp_style_var_when_type_is_apparent",
Value: "true",
Severity: null);
Value: "true");

EditorConfigSettings editorConfigSettings = _parser.Parse(content);

Expand All @@ -73,8 +72,7 @@ public void Parse_StyleOptionWithSeverity_ReturnOptionRuleWithSeverity()
string content = "csharp_style_var_when_type_is_apparent = true";
var expected = new RoslynOptionEditorConfigSetting(
Key: "csharp_style_var_when_type_is_apparent",
Value: "true",
Severity: null);
Value: "true");

EditorConfigSettings editorConfigSettings = _parser.Parse(content);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using FluentAssertions;
using Kysect.Configuin.Core.MarkdownParsing.Documents;
using Kysect.Configuin.Core.MarkdownParsing.TextExtractor;
using Kysect.Configuin.Tests.Tools;
using Markdig.Syntax;
using NUnit.Framework;

namespace Kysect.Configuin.Tests.MsLearnDocumentation;

public class MarkdownDocumentParserTests
{
private readonly IMarkdownTextExtractor _plainTextExtractor = TestImplementations.GetTextExtractor();

[Test]
public void SplitByHeaders_DocumentWithThreeHeaders_ReturnThreeParts()

Check warning on line 15 in Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownDocumentParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Remove the underscores from member name Kysect.Configuin.Tests.MsLearnDocumentation.MarkdownDocumentParserTests.SplitByHeaders_DocumentWithThreeHeaders_ReturnThreeParts() (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1707)
{
Expand Down Expand Up @@ -40,7 +44,7 @@ public void SplitByHeaders_DocumentWithThreeHeaders_ReturnThreeParts()
""";

MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(input);
IReadOnlyCollection<MarkdownHeadedBlock> headedBlocks = markdownDocument.SplitByHeaders();
IReadOnlyCollection<MarkdownHeadedBlock> headedBlocks = markdownDocument.SplitByHeaders(_plainTextExtractor);

headedBlocks.Should().HaveCount(3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Kysect.Configuin.Core.MarkdownParsing.Documents;
using Kysect.Configuin.Core.MarkdownParsing.Tables;
using Kysect.Configuin.Core.MarkdownParsing.Tables.Models;
using Kysect.Configuin.Core.MarkdownParsing.TextExtractor;
using Kysect.Configuin.Tests.Tools;
using Markdig.Extensions.Tables;
using Markdig.Syntax;
using NUnit.Framework;
Expand All @@ -12,7 +12,7 @@ namespace Kysect.Configuin.Tests.MsLearnDocumentation;

public class MarkdownTableParserTests
{
private readonly MarkdownTableParser _parser = new (PlainTextExtractor.Create());
private readonly MarkdownTableParser _parser = new MarkdownTableParser(TestImplementations.GetTextExtractor());

[Test]
public void ParseToSimpleContent_ForSimpleTable_ReturnExpectedResult()

Check warning on line 18 in Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownTableParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Remove the underscores from member name Kysect.Configuin.Tests.MsLearnDocumentation.MarkdownTableParserTests.ParseToSimpleContent_ForSimpleTable_ReturnExpectedResult() (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1707)
Expand Down

0 comments on commit f39476b

Please sign in to comment.