diff --git a/Sources/Kysect.Configuin.Core/CodeStyleGeneration/CodeStyleGenerator.cs b/Sources/Kysect.Configuin.Core/CodeStyleGeneration/CodeStyleGenerator.cs index 39c810c..467a188 100644 --- a/Sources/Kysect.Configuin.Core/CodeStyleGeneration/CodeStyleGenerator.cs +++ b/Sources/Kysect.Configuin.Core/CodeStyleGeneration/CodeStyleGenerator.cs @@ -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; diff --git a/Sources/Kysect.Configuin.Core/EditorConfigParsing/EditorConfigSettingsParser.cs b/Sources/Kysect.Configuin.Core/EditorConfigParsing/EditorConfigSettingsParser.cs index da90f9c..2dddb95 100644 --- a/Sources/Kysect.Configuin.Core/EditorConfigParsing/EditorConfigSettingsParser.cs +++ b/Sources/Kysect.Configuin.Core/EditorConfigParsing/EditorConfigSettingsParser.cs @@ -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); @@ -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); } } \ No newline at end of file diff --git a/Sources/Kysect.Configuin.Core/EditorConfigParsing/Settings/IEditorConfigSetting.cs b/Sources/Kysect.Configuin.Core/EditorConfigParsing/Settings/IEditorConfigSetting.cs index 2f3956c..0bb36ae 100644 --- a/Sources/Kysect.Configuin.Core/EditorConfigParsing/Settings/IEditorConfigSetting.cs +++ b/Sources/Kysect.Configuin.Core/EditorConfigParsing/Settings/IEditorConfigSetting.cs @@ -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, diff --git a/Sources/Kysect.Configuin.Core/IniParsing/IniParser.cs b/Sources/Kysect.Configuin.Core/IniParsing/IniParser.cs index fdd748e..2c55bba 100644 --- a/Sources/Kysect.Configuin.Core/IniParsing/IniParser.cs +++ b/Sources/Kysect.Configuin.Core/IniParsing/IniParser.cs @@ -13,17 +13,16 @@ public IReadOnlyCollection 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('='); diff --git a/Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj b/Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj index 94076b6..2a9240b 100644 --- a/Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj +++ b/Sources/Kysect.Configuin.Core/Kysect.Configuin.Core.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownDocumentExtensions.cs b/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownDocumentExtensions.cs index 50caa11..e7d7086 100644 --- a/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownDocumentExtensions.cs +++ b/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownDocumentExtensions.cs @@ -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; @@ -10,7 +11,7 @@ public static MarkdownDocument CreateFromString(string content) return MarkdownParser.Parse(content, MarkdownPipelineProvider.GetDefault()); } - public static IReadOnlyCollection SplitByHeaders(this MarkdownDocument markdownDocument) + public static IReadOnlyCollection SplitByHeaders(this MarkdownDocument markdownDocument, IMarkdownTextExtractor textExtractor) { ArgumentNullException.ThrowIfNull(markdownDocument); @@ -26,7 +27,7 @@ public static IReadOnlyCollection SplitByHeaders(this Markd { if (headingBlock is not null) { - result.Add(new MarkdownHeadedBlock(headingBlock, blocks)); + result.Add(new MarkdownHeadedBlock(textExtractor.ExtractText(headingBlock), blocks)); } headingBlock = currentHeaderBlock; @@ -40,7 +41,7 @@ public static IReadOnlyCollection SplitByHeaders(this Markd if (headingBlock is not null) { - result.Add(new MarkdownHeadedBlock(headingBlock, blocks)); + result.Add(new MarkdownHeadedBlock(textExtractor.ExtractText(headingBlock), blocks)); } return result; diff --git a/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownHeadedBlock.cs b/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownHeadedBlock.cs index 2a60ae5..5717c7c 100644 --- a/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownHeadedBlock.cs +++ b/Sources/Kysect.Configuin.Core/MarkdownParsing/Documents/MarkdownHeadedBlock.cs @@ -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 Content { get; } - public MarkdownHeadedBlock(HeadingBlock header, IReadOnlyCollection content) + public MarkdownHeadedBlock(string headerText, IReadOnlyCollection 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); - } } \ No newline at end of file diff --git a/Sources/Kysect.Configuin.Core/MarkdownParsing/TextExtractor/PlainTextExtractor.cs b/Sources/Kysect.Configuin.Core/MarkdownParsing/TextExtractor/PlainTextExtractor.cs index c1e0f1f..5067232 100644 --- a/Sources/Kysect.Configuin.Core/MarkdownParsing/TextExtractor/PlainTextExtractor.cs +++ b/Sources/Kysect.Configuin.Core/MarkdownParsing/TextExtractor/PlainTextExtractor.cs @@ -41,8 +41,8 @@ public string ExtractText(Block block) // KB: HtmlRenderer change '"' to """. 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); } } \ No newline at end of file diff --git a/Sources/Kysect.Configuin.Core/MsLearnDocumentation/Models/RoslynStyleRuleInformationTable.cs b/Sources/Kysect.Configuin.Core/MsLearnDocumentation/Models/RoslynStyleRuleInformationTable.cs index 4f5df69..61ccdc8 100644 --- a/Sources/Kysect.Configuin.Core/MsLearnDocumentation/Models/RoslynStyleRuleInformationTable.cs +++ b/Sources/Kysect.Configuin.Core/MsLearnDocumentation/Models/RoslynStyleRuleInformationTable.cs @@ -2,7 +2,6 @@ namespace Kysect.Configuin.Core.MsLearnDocumentation.Models; -// TODO: need more semantic naming public record RoslynStyleRuleInformationTable( RoslynRuleId RuleId, string Title, diff --git a/Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs b/Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs index efa5a36..08efa31 100644 --- a/Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs +++ b/Sources/Kysect.Configuin.Core/MsLearnDocumentation/MsLearnDocumentationParser.cs @@ -39,7 +39,7 @@ public RoslynRules Parse(MsLearnDocumentationRawInfo rawInfo) public IReadOnlyCollection ParseStyleRules(string info) { MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(info); - IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(); + IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor); if (markdownHeadedBlocks.Count == 0) throw new ConfiguinException("Style rule markdown file does not contains any heading blocks. Cannot parse description"); @@ -101,7 +101,7 @@ private RoslynStyleRule ConvertToRule( roslynStyleRuleInformationTable.Title, roslynStyleRuleInformationTable.Category, overviewText, - // TODO: support this? + // TODO: #39 support this example: string.Empty, roslynStyleRuleOptions); } @@ -109,7 +109,7 @@ private RoslynStyleRule ConvertToRule( public IReadOnlyCollection ParseQualityRules(string info) { MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(info); - IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(); + IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor); if (markdownHeadedBlocks.Count == 0) throw new ConfiguinException("Style rule markdown file does not contains any heading blocks. Cannot parse description"); @@ -136,10 +136,10 @@ public IReadOnlyCollection 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(); } @@ -147,14 +147,13 @@ public IReadOnlyCollection ParseQualityRules(string info) public IReadOnlyCollection ParseAdditionalFormattingOptions(string dotnetFormattingFileContent) { MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(dotnetFormattingFileContent); - IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(); + IReadOnlyCollection markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor); return ParseOptions(markdownHeadedBlocks); } private IReadOnlyCollection 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) }; @@ -162,9 +161,9 @@ private IReadOnlyCollection ParseQualityRuleTableIdRow(MsLearnProp private string GetStyleOverviewText(IReadOnlyCollection 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; @@ -187,8 +186,7 @@ private IReadOnlyCollection 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_") @@ -200,7 +198,7 @@ private RoslynStyleRuleOption ParseOption(MarkdownHeadedBlock optionBlock) { var tables = optionBlock.Content.OfType().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); @@ -209,9 +207,9 @@ private RoslynStyleRuleOption ParseOption(MarkdownHeadedBlock optionBlock) CodeBlock? csharpCodeBlock = codeBlocks .OfType() .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"); diff --git a/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynRules.cs b/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynRules.cs index f3fb7ce..fe86ba8 100644 --- a/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynRules.cs +++ b/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynRules.cs @@ -4,6 +4,7 @@ public class RoslynRules { public IReadOnlyCollection QualityRules { get; } public IReadOnlyCollection StyleRules { get; } + // TODO: #42 This options is related to IDE0055 public IReadOnlyCollection DotnetFormattingOptions { get; } public IReadOnlyCollection SharpFormattingOptions { get; } diff --git a/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynStyleRuleOption.cs b/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynStyleRuleOption.cs index b0b6f87..a3a0a6d 100644 --- a/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynStyleRuleOption.cs +++ b/Sources/Kysect.Configuin.Core/RoslynRuleModels/RoslynStyleRuleOption.cs @@ -4,4 +4,4 @@ public record RoslynStyleRuleOption( string Name, IReadOnlyCollection Options, string? DefaultValue, - string CsharpCodeSample); \ No newline at end of file + string? CsharpCodeSample); \ No newline at end of file diff --git a/Sources/Kysect.Configuin.Tests/CodeStyleGeneration/CodeStyleGeneratorTests.cs b/Sources/Kysect.Configuin.Tests/CodeStyleGeneration/CodeStyleGeneratorTests.cs index 1abd07b..30ff859 100644 --- a/Sources/Kysect.Configuin.Tests/CodeStyleGeneration/CodeStyleGeneratorTests.cs +++ b/Sources/Kysect.Configuin.Tests/CodeStyleGeneration/CodeStyleGeneratorTests.cs @@ -4,7 +4,6 @@ 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; @@ -12,16 +11,9 @@ 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() diff --git a/Sources/Kysect.Configuin.Tests/EditorConfigSettingsParsing/EditorConfigSettingsParserTests.cs b/Sources/Kysect.Configuin.Tests/EditorConfigSettingsParsing/EditorConfigSettingsParserTests.cs index a98830b..ee1a5c1 100644 --- a/Sources/Kysect.Configuin.Tests/EditorConfigSettingsParsing/EditorConfigSettingsParserTests.cs +++ b/Sources/Kysect.Configuin.Tests/EditorConfigSettingsParsing/EditorConfigSettingsParserTests.cs @@ -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); @@ -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); diff --git a/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownDocumentParserTests.cs b/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownDocumentParserTests.cs index 1fc105d..1cc6492 100644 --- a/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownDocumentParserTests.cs +++ b/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownDocumentParserTests.cs @@ -1,5 +1,7 @@ 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; @@ -7,6 +9,8 @@ namespace Kysect.Configuin.Tests.MsLearnDocumentation; public class MarkdownDocumentParserTests { + private readonly IMarkdownTextExtractor _plainTextExtractor = TestImplementations.GetTextExtractor(); + [Test] public void SplitByHeaders_DocumentWithThreeHeaders_ReturnThreeParts() { @@ -40,7 +44,7 @@ public void SplitByHeaders_DocumentWithThreeHeaders_ReturnThreeParts() """; MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(input); - IReadOnlyCollection headedBlocks = markdownDocument.SplitByHeaders(); + IReadOnlyCollection headedBlocks = markdownDocument.SplitByHeaders(_plainTextExtractor); headedBlocks.Should().HaveCount(3); } diff --git a/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownTableParserTests.cs b/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownTableParserTests.cs index 6b6f931..6befc99 100644 --- a/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownTableParserTests.cs +++ b/Sources/Kysect.Configuin.Tests/MsLearnDocumentation/MarkdownTableParserTests.cs @@ -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; @@ -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()