Skip to content

Commit 6dd0fff

Browse files
committed
Adding the xml whitespace options
1 parent c3b87f8 commit 6dd0fff

File tree

8 files changed

+251
-147
lines changed

8 files changed

+251
-147
lines changed

Src/CSharpier.Cli/EditorConfig/EditorConfigFileParser.cs renamed to Src/CSharpier.Cli/EditorConfig/CSharpierConfigParser.cs

File renamed without changes.

Src/CSharpier.Cli/EditorConfig/EditorConfigSections.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ internal class EditorConfigSections
5353
printerOptions.EndOfLine = endOfLine;
5454
}
5555

56+
if (resolvedConfiguration.XmlWhitespaceSensitivity is { } xmlWhitespaceSensitivity)
57+
{
58+
printerOptions.XmlWhitespaceSensitivity = xmlWhitespaceSensitivity;
59+
}
60+
5661
return printerOptions;
5762
}
5863

@@ -63,6 +68,7 @@ private class ResolvedConfiguration
6368
public int? TabWidth { get; }
6469
public int? MaxLineLength { get; }
6570
public EndOfLine? EndOfLine { get; }
71+
public XmlWhitespaceSensitivity? XmlWhitespaceSensitivity { get; set; }
6672
public string? Formatter { get; }
6773

6874
public ResolvedConfiguration(List<Section> sections)
@@ -104,9 +110,23 @@ public ResolvedConfiguration(List<Section> sections)
104110
}
105111

106112
var endOfLine = sections.LastOrDefault(o => o.EndOfLine != null)?.EndOfLine;
107-
if (Enum.TryParse(endOfLine, true, out EndOfLine result))
113+
if (Enum.TryParse(endOfLine, true, out EndOfLine parsedEndOfLine))
114+
{
115+
this.EndOfLine = parsedEndOfLine;
116+
}
117+
118+
var xmlWhitespaceSensitivity = sections
119+
.LastOrDefault(o => o.XmlWhitespaceSensitivity != null)
120+
?.XmlWhitespaceSensitivity;
121+
if (
122+
Enum.TryParse(
123+
xmlWhitespaceSensitivity,
124+
true,
125+
out XmlWhitespaceSensitivity parsedXmlWhitespaceSensitivity
126+
)
127+
)
108128
{
109-
this.EndOfLine = result;
129+
this.XmlWhitespaceSensitivity = parsedXmlWhitespaceSensitivity;
110130
}
111131

112132
this.Formatter = sections.LastOrDefault(o => o.Formatter is not null)?.Formatter;

Src/CSharpier.Cli/EditorConfig/Section.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal class Section(SectionData section, string directory)
1313
public string? MaxLineLength { get; } = section.Keys["max_line_length"];
1414
public string? EndOfLine { get; } = section.Keys["end_of_line"];
1515
public string? Formatter { get; } = section.Keys["csharpier_formatter"];
16+
public string? XmlWhitespaceSensitivity { get; } =
17+
section.Keys["csharpier_xml_whitespace_sensitivity"];
1618

1719
public bool IsMatch(string fileName, bool ignoreDirectory)
1820
{

Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ internal class ConfigurationFileOptions
1010
public int? IndentSize { get; init; }
1111
public bool UseTabs { get; init; }
1212

13+
[JsonConverter(typeof(CaseInsensitiveEnumConverter<XmlWhitespaceSensitivity>))]
14+
public XmlWhitespaceSensitivity XmlWhitespaceSensitivity { get; init; } =
15+
XmlWhitespaceSensitivity.Strict;
16+
1317
[JsonConverter(typeof(CaseInsensitiveEnumConverter<EndOfLine>))]
1418
public EndOfLine EndOfLine { get; init; }
1519

@@ -38,6 +42,7 @@ out var parsedFormatter
3842
UseTabs = matchingOverride.UseTabs,
3943
Width = matchingOverride.PrintWidth,
4044
EndOfLine = matchingOverride.EndOfLine,
45+
XmlWhitespaceSensitivity = matchingOverride.XmlWhitespaceSensitivity,
4146
};
4247
}
4348

@@ -50,6 +55,7 @@ out var parsedFormatter
5055
UseTabs = this.UseTabs,
5156
Width = this.PrintWidth,
5257
EndOfLine = this.EndOfLine,
58+
XmlWhitespaceSensitivity = this.XmlWhitespaceSensitivity,
5359
};
5460
}
5561

@@ -73,6 +79,10 @@ internal class Override
7379
public int IndentSize { get; init; } = 4;
7480
public bool UseTabs { get; init; }
7581

82+
[JsonConverter(typeof(CaseInsensitiveEnumConverter<XmlWhitespaceSensitivity>))]
83+
public XmlWhitespaceSensitivity XmlWhitespaceSensitivity { get; init; } =
84+
XmlWhitespaceSensitivity.Strict;
85+
7686
[JsonConverter(typeof(CaseInsensitiveEnumConverter<EndOfLine>))]
7787
public EndOfLine EndOfLine { get; init; }
7888

Src/CSharpier.Core/PrinterOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public int IndentSize
2727
public bool TrimInitialLines { get; init; } = true;
2828
public bool IncludeGenerated { get; set; }
2929
public Formatter Formatter { get; set; } = formatter;
30+
public XmlWhitespaceSensitivity XmlWhitespaceSensitivity { get; set; } =
31+
XmlWhitespaceSensitivity.Strict;
3032

3133
public const int WidthUsedByTests = 100;
3234

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace CSharpier.Core;
2+
3+
internal enum XmlWhitespaceSensitivity
4+
{
5+
Strict,
6+
Xaml,
7+
Ignore,
8+
}

Src/CSharpier.Tests/Cli/Options/EditorConfigFileParserTests.cs renamed to Src/CSharpier.Tests/Cli/Options/CSharpierConfigParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace CSharpier.Tests.Cli.Options;
66

7-
public class EditorConfigFileParserTests
7+
public class CSharpierConfigParserTests
88
{
99
[Test]
1010
public void Should_Parse_Yaml_With_Overrides()

0 commit comments

Comments
 (0)