Skip to content

Commit 0975ccb

Browse files
authored
Fixing extra blank line in xml formatting (#1767)
closes #1760
1 parent 6ca9c61 commit 0975ccb

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<TargetFrameworks>net10.0</TargetFrameworks>
4-
<LangVersion>12</LangVersion>
4+
<LangVersion>14</LangVersion>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<!-- this is the warning generators get when they fail to generate a source file this makes sure the error for it failing is obvious -->

Src/CSharpier.Cli/ConsoleLogger.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using Microsoft.Extensions.Logging;
2+
#if NET8_0
3+
using Lock = object;
4+
#endif
25

36
namespace CSharpier.Cli;
47

58
internal class ConsoleLogger(IConsole console, LogLevel loggingLevel, LogFormat logFormat) : ILogger
69
{
7-
private static readonly object ConsoleLock = new();
10+
private static readonly Lock ConsoleLock = new();
811

912
public virtual void Log<TState>(
1013
LogLevel logLevel,

Src/CSharpier.Core/Xml/XNodePrinters/Node.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,16 @@ internal static Doc Print(RawNode node, PrintingContext context)
1515

1616
foreach (var childNode in node.Nodes)
1717
{
18-
result.Add(Print(childNode, context), Doc.HardLine);
18+
result.Add(
19+
Print(childNode, context),
20+
childNode.NodeType is XmlNodeType.Whitespace ? Doc.Null : Doc.HardLine
21+
);
1922
}
2023

2124
result.Add(Doc.HardLine);
2225

2326
return Doc.Concat(ref result);
2427
}
25-
if (node.NodeType == XmlNodeType.XmlDeclaration)
26-
{
27-
var version = node.Attributes.FirstOrDefault(o => o.Name == "version")?.Value;
28-
var encoding = node.Attributes.FirstOrDefault(o => o.Name == "encoding")?.Value;
29-
var standalone = node.Attributes.FirstOrDefault(o => o.Name == "standalone")?.Value;
30-
31-
var declaration = $"<?xml version=\"{version}\"";
32-
if (!string.IsNullOrEmpty(encoding))
33-
{
34-
declaration += $" encoding=\"{encoding}\"";
35-
}
36-
37-
if (!string.IsNullOrEmpty(standalone))
38-
{
39-
declaration += $" standalone=\"{standalone}\"";
40-
}
41-
42-
declaration += "?>";
43-
44-
return declaration;
45-
}
4628

4729
if (node.NodeType == XmlNodeType.DocumentType)
4830
{

Src/CSharpier.Tests/FormattingTests/TestFiles/xml/EmptyLines.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
13
<Root>
24
<Element />
35
<Element />

0 commit comments

Comments
 (0)