diff --git a/Sources/Kysect.Configuin.EditorConfig/Formatter/EditorConfigFormatter.cs b/Sources/Kysect.Configuin.EditorConfig/Formatter/EditorConfigFormatter.cs index 8e5a976..31d89da 100644 --- a/Sources/Kysect.Configuin.EditorConfig/Formatter/EditorConfigFormatter.cs +++ b/Sources/Kysect.Configuin.EditorConfig/Formatter/EditorConfigFormatter.cs @@ -65,6 +65,19 @@ public EditorConfigDocument FormatAccordingToRuleDefinitions(EditorConfigDocumen selectedStyleRuleNodes.Add(editorConfigPropertyNode); } + + if (roslynStyleRuleGroup.Rules.Any(r => r.RuleId.Equals(RoslynNameRuleInfo.RuleId))) + { + foreach (EditorConfigPropertyNode editorConfigPropertyNode in propertyNodes) + { + IEditorConfigSetting editorConfigSetting = _settingsParser.ParseSetting(editorConfigPropertyNode); + if (editorConfigSetting is not CompositeRoslynOptionEditorConfigSetting option) + continue; + + if (RoslynNameRuleInfo.IsNameRuleOption(option.ToDisplayString())) + selectedStyleRuleNodes.Add(editorConfigPropertyNode); + } + } } List selectedQualityRuleNodes = new List(); diff --git a/Sources/Kysect.Configuin.MsLearn/MsLearnDocumentationParser.cs b/Sources/Kysect.Configuin.MsLearn/MsLearnDocumentationParser.cs index 59a5a2f..f8a8321 100644 --- a/Sources/Kysect.Configuin.MsLearn/MsLearnDocumentationParser.cs +++ b/Sources/Kysect.Configuin.MsLearn/MsLearnDocumentationParser.cs @@ -45,7 +45,7 @@ public RoslynRules Parse(MsLearnDocumentationRawInfo rawInfo) var roslynStyleRules = rawInfo.StyleRuleFileContents.Select(ParseStyleRules).ToList(); roslynStyleRules = ParseIde0055FormatOptions(roslynStyleRules, rawInfo); - + roslynStyleRules = AddNamingRule(roslynStyleRules); return new RoslynRules(roslynQualityRules, roslynStyleRules); } @@ -80,6 +80,16 @@ private List ParseIde0055FormatOptions( return roslynStyleRules; } + private List AddNamingRule(List roslynStyleRules) + { + var namingRule = new RoslynStyleRule(RoslynNameRuleInfo.RuleId, "Code-style naming rules", "Style"); + var roslynStyleRuleGroup = new RoslynStyleRuleGroup(namingRule, string.Empty, null); + + roslynStyleRules.Add(roslynStyleRuleGroup); + return roslynStyleRules; + } + + public RoslynStyleRuleGroup ParseStyleRules(string info) { info.ThrowIfNull(); diff --git a/Sources/Kysect.Configuin.RoslynModels/RoslynStyleRuleInfo.cs b/Sources/Kysect.Configuin.RoslynModels/RoslynStyleRuleInfo.cs new file mode 100644 index 0000000..0620905 --- /dev/null +++ b/Sources/Kysect.Configuin.RoslynModels/RoslynStyleRuleInfo.cs @@ -0,0 +1,18 @@ +using Kysect.CommonLib.BaseTypes.Extensions; + +namespace Kysect.Configuin.RoslynModels; + +public static class RoslynNameRuleInfo +{ + public static RoslynRuleId RuleId { get; } = new RoslynRuleId("IDE", 1006); + + public static bool IsNameRuleOption(string optionName) + { + optionName.ThrowIfNull(); + + return optionName.StartsWith("dotnet_naming_rule") + || optionName.StartsWith("dotnet_naming_symbols") + || optionName.StartsWith("dotnet_naming_style"); + + } +} \ No newline at end of file diff --git a/Sources/Kysect.Configuin.Tests/EditorConfig/EditorConfigFormatterTests.cs b/Sources/Kysect.Configuin.Tests/EditorConfig/EditorConfigFormatterTests.cs index 4e54571..b7d6953 100644 --- a/Sources/Kysect.Configuin.Tests/EditorConfig/EditorConfigFormatterTests.cs +++ b/Sources/Kysect.Configuin.Tests/EditorConfig/EditorConfigFormatterTests.cs @@ -75,6 +75,37 @@ public void Format_QualityAndStyleRulesMashed_ReturnOrderedLinesWithHeader() FormatAndCompare(input, expected); } + [Fact] + public void Format_NamingRule_ReturnOrderedLinesWithHeader() + { + var input = """ + dotnet_naming_style.camel_case_style.capitalization = camel_case + dotnet_diagnostic.IDE0081.severity = none + dotnet_naming_style.disallowed_style.capitalization = pascal_case + dotnet_diagnostic.IDE1006.severity = none + dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style + """; + + var expected = """ + # Autogenerated values + [*.cs] + ### IDE ### + dotnet_diagnostic.IDE0081.severity = none + dotnet_diagnostic.IDE1006.severity = none + dotnet_naming_style.camel_case_style.capitalization = camel_case + dotnet_naming_style.disallowed_style.capitalization = pascal_case + dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style + """; + + MsLearnDocumentationRawInfo msLearnDocumentationRawInfo = _repositoryPathReader.Provide(Constants.GetPathToMsDocsRoot()); + RoslynRules roslynRules = _msLearnDocumentationParser.Parse(msLearnDocumentationRawInfo); + + EditorConfigDocument editorConfigDocument = _parser.Parse(input); + EditorConfigDocument formattedDocument = _formatter.FormatAccordingToRuleDefinitions(editorConfigDocument, roslynRules); + + formattedDocument.ToFullString().Should().Be(expected); + } + [Fact(Skip = "Test is not work during CI. Need to rewrite it without reading and comparing huge .ini files")] public void FormatAccordingToRuleDefinitions_Sample_ReturnExpectedFormatterDocument() {