Skip to content

Commit

Permalink
Fix styledoc generating for case when some values is missed
Browse files Browse the repository at this point in the history
  • Loading branch information
FrediKats committed May 17, 2024
1 parent e8f5ae4 commit 1cf4148
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
11 changes: 4 additions & 7 deletions Sources/Kysect.Configuin.CodeStyleDoc/CodeStyleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ private ICodeStyleElement ParseRuleSettings(
RoslynStyleRule rule = ruleGroup.Rules.Single(r => r.RuleId.Equals(severityEditorConfigSetting.RuleId));
var options = ruleGroup
.Options
.Select(o => GetOptionConfiguration(optionConfigurations, o.Name))
.Select(o => FindOptionConfiguration(optionConfigurations, o.Name))
.WhereNotNull()
.ToList();

return new CodeStyleRoslynStyleRuleConfiguration(rule, severityEditorConfigSetting.Severity, options, ruleGroup.Overview, ruleGroup.Example);
Expand All @@ -123,14 +124,10 @@ private ICodeStyleElement ParseRuleSettings(
throw new ConfiguinException($"Rule with id {severityEditorConfigSetting.RuleId} was not found");
}

private CodeStyleRoslynOptionConfiguration GetOptionConfiguration(
private CodeStyleRoslynOptionConfiguration? FindOptionConfiguration(
IReadOnlyCollection<CodeStyleRoslynOptionConfiguration> optionConfigurations,
string name)
{
CodeStyleRoslynOptionConfiguration? option = optionConfigurations.FirstOrDefault(o => o.Option.Name == name);
if (option is null)
throw new ConfiguinException($"Option with name {name} was not found");

return option;
return optionConfigurations.FirstOrDefault(o => o.Option.Name == name);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Kysect.CommonLib.BaseTypes.Extensions;
using Kysect.Configuin.Common;
using Kysect.Configuin.Markdown.Documents;
using Kysect.Configuin.Markdown.Tables;
Expand Down Expand Up @@ -81,6 +82,10 @@ private List<RoslynStyleRuleGroup> ParseIde0055FormatOptions(

public RoslynStyleRuleGroup ParseStyleRules(string info)
{
info.ThrowIfNull();

info = _documentationPreprocessor.Process(info);

MarkdownDocument markdownDocument = MarkdownDocumentExtensions.CreateFromString(info);
IReadOnlyCollection<MarkdownHeadedBlock> markdownHeadedBlocks = markdownDocument.SplitByHeaders(_textExtractor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class MsLearnDocumentationPreprocessor
{
public MsLearnDocumentationRawInfo Process(MsLearnDocumentationRawInfo info)
{
info.ThrowIfNull();

return new MsLearnDocumentationRawInfo(
info.QualityRuleFileContents.Select(Process).ToList(),
info.StyleRuleFileContents.Select(Process).ToList(),
Expand All @@ -27,6 +29,8 @@ public string Process(string input)

lines = RemoveZones(lines);

lines = lines.Where(l => !l.StartsWith("[!INCLUDE")).ToList();

return string.Join(Environment.NewLine, lines);
}

Expand All @@ -41,14 +45,18 @@ private List<string> RemoveZones(List<string> lines)
if (startIndex == -1 || endIndex == -1 || startIndex >= endIndex)
throw new ArgumentException("Cannot find zones for removing");

if (lines[startIndex].StartsWith(":::zone pivot=\"lang-csharp-vb\""))
bool actualZone = lines[startIndex].StartsWith(":::zone pivot=\"lang-csharp-vb\"")
|| lines[startIndex].StartsWith(":::zone pivot=\"dotnet-8-0\"");
if (actualZone)
{
lines.RemoveAt(endIndex);
lines.RemoveAt(startIndex);
continue;
}

if (lines[startIndex].StartsWith(":::zone pivot=\"lang-fsharp\""))
bool notActualZone = lines[startIndex].StartsWith(":::zone pivot=\"lang-fsharp\"")
|| lines[startIndex].StartsWith(":::zone pivot=\"dotnet-7-0,dotnet-6-0\"");
if (notActualZone)
{
lines.RemoveRange(startIndex, endIndex - startIndex + 1);
continue;
Expand Down
3 changes: 3 additions & 0 deletions Sources/Kysect.Configuin.MsLearn/Tables/MsLearnTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ private static void ValidateTableHeader(MarkdownTableContent simpleTable)
string[] expectedHeaders = { "Property", "Value", "Description" };
for (int i = 0; i < simpleTable.Headers.Count; i++)
{
if (string.IsNullOrEmpty(simpleTable.Headers[i]))
continue;

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]}");
}
Expand Down
2 changes: 1 addition & 1 deletion ms-learn
Submodule ms-learn updated 6075 files

0 comments on commit 1cf4148

Please sign in to comment.