Skip to content

Commit 471995e

Browse files
committed
fixing warnings
1 parent b4bad5c commit 471995e

File tree

10 files changed

+34
-82
lines changed

10 files changed

+34
-82
lines changed

Shell/BuildProject.psm1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
function CSH-BuildProject
2-
{
1+
function CSH-BuildProject {
2+
param (
3+
[switch]$doNotExit = $false
4+
)
5+
6+
37
$repositoryRoot = Join-Path $PSScriptRoot ".."
48
$csProjectPath = Join-Path $repositoryRoot "Src/CSharpier.Cli/CSharpier.Cli.csproj"
59

610
& dotnet build $csProjectPath -c release
7-
if ($lastExitCode -gt 0) {
11+
if ($lastExitCode -gt 0 -and -not $doNotExit) {
812
exit $lastExitCode;
913
}
1014
}

Shell/ReviewBranch.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function CSH-ReviewBranch {
6161

6262
$formatArgument = "."
6363
if ($onlyXml) {
64-
$formatArgument = "**/*.{config,csproj,props,slnx,targets,xaml,xml}"
64+
$formatArgument = "**/*.config **/*.csproj **/*.props **/*.slnx **/*.targets **/*.xaml **/*.xml"
6565
}
6666

6767
if ($firstRun) {
@@ -74,7 +74,11 @@ function CSH-ReviewBranch {
7474
# return
7575
# }
7676

77-
CSH-BuildProject
77+
CSH-BuildProject -doNotExit
78+
79+
if ($lastExitCode -gt 0) {
80+
return
81+
}
7882

7983
Set-Location $pathToTestingRepo
8084

Src/CSharpier.Core/Xml/RawAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ internal class RawAttribute
44
{
55
public required string Name { get; set; }
66
public required string Value { get; set; }
7-
}
7+
}

Src/CSharpier.Core/Xml/RawNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ internal class RawNode
88
public RawNode? Parent { get; set; }
99
public RawNode? PreviousNode { get; set; }
1010
public RawNode? NextNode { get; set; }
11-
public required string? Name { get; set; }
11+
public required string Name { get; set; }
1212
public required XmlNodeType NodeType { get; set; }
1313
public required bool IsEmpty { get; set; }
1414
public required RawAttribute[] Attributes { get; set; }
15-
public List<RawNode> Nodes { get; set; } = new();
16-
public string? Value { get; set; }
15+
public List<RawNode> Nodes { get; set; } = [];
16+
public string Value { get; set; } = string.Empty;
1717

1818
public bool IsTextLike()
1919
{

Src/CSharpier.Core/Xml/RawNodePrinters/Element.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace CSharpier.Core.Xml.RawNodePrinters;
77

88
internal static class Element
99
{
10-
internal static Doc Print(RawNode rawNode, XmlPrintingContext context)
10+
internal static Doc Print(RawNode rawNode, PrintingContext context)
1111
{
1212
var shouldHugContent = false;
1313
var attrGroupId = context.GroupFor("element-attr-group-id");

Src/CSharpier.Core/Xml/RawNodePrinters/ElementChildren.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Xml;
2+
using CSharpier.Core.CSharp.SyntaxPrinter;
23
using CSharpier.Core.DocTypes;
34
using CSharpier.Core.Utilities;
45

56
namespace CSharpier.Core.Xml.RawNodePrinters;
67

78
internal static class ElementChildren
89
{
9-
public static Doc Print(RawNode node, XmlPrintingContext context)
10+
public static Doc Print(RawNode node, PrintingContext context)
1011
{
1112
var groupIds = new List<string>();
1213
foreach (var _ in node.Nodes)
@@ -80,7 +81,7 @@ public static Doc Print(RawNode node, XmlPrintingContext context)
8081
return Doc.Concat(ref result);
8182
}
8283

83-
public static Doc PrintChild(RawNode child, XmlPrintingContext context)
84+
public static Doc PrintChild(RawNode child, PrintingContext context)
8485
{
8586
// should we try to support csharpier-ignore some day?
8687
// if (HasPrettierIgnore(child))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace CSharpier.Core.Xml.RawNodePrinters;
99

1010
internal static class Node
1111
{
12-
internal static Doc Print(RawNode node, XmlPrintingContext context)
12+
internal static Doc Print(RawNode node, PrintingContext context)
1313
{
1414
if (node.NodeType == XmlNodeType.XmlDeclaration)
1515
{

Src/CSharpier.Core/Xml/RawNodePrinters/Tag.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static Doc PrintClosingTagStart(RawNode rawNode, PrintingContext context)
8686

8787
public static Doc PrintClosingTagStartMarker(RawNode rawNode, PrintingContext context)
8888
{
89-
return $"</{GetPrefixedElementName(rawNode, context)}";
89+
return $"</{rawNode.Name}";
9090
}
9191

9292
public static Doc PrintClosingTagEnd(RawNode rawNode, PrintingContext context)
@@ -121,22 +121,7 @@ private static Doc PrintOpeningTagStartMarker(RawNode rawNode, PrintingContext c
121121
return "<" + rawNode.Name;
122122
}
123123

124-
return $"<{GetPrefixedElementName(rawNode, context)}";
125-
}
126-
127-
private static string GetPrefixedElementName(RawNode rawNode, PrintingContext context)
128-
{
129-
return rawNode.Name;
130-
// var prefix = element.GetPrefixOfNamespace(element.Name.Namespace);
131-
// if (
132-
// string.IsNullOrEmpty(prefix)
133-
// || !context.Mapping[element].Name.StartsWith(prefix, StringComparison.Ordinal)
134-
// )
135-
// {
136-
// return element.Name.LocalName;
137-
// }
138-
//
139-
// return $"{prefix}:{element.Name.LocalName}";
124+
return $"<{rawNode.Name}";
140125
}
141126

142127
private static bool NeedsToBorrowNextOpeningTagStartMarker(RawNode rawNode)

Src/CSharpier.Core/Xml/RawNodeReader.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,21 @@ XmlReader xmlReader
8282
return elements;
8383
}
8484

85-
private static string? GetValue(XmlReader xmlReader, string lineEnding)
85+
private static string GetValue(XmlReader xmlReader, string lineEnding)
8686
{
8787
var normalizedTextValue = NewlineRegex
8888
#if !NETSTANDARD2_0
8989
()
9090
#endif
9191
.Replace(xmlReader.Value, lineEnding);
9292

93-
return xmlReader.NodeType is XmlNodeType.Text ? normalizedTextValue
94-
: xmlReader.NodeType is XmlNodeType.Comment ? $"<!--{normalizedTextValue}-->"
95-
: xmlReader.NodeType is XmlNodeType.CDATA ? $"<![CDATA[{normalizedTextValue}]]>"
96-
: xmlReader.NodeType is XmlNodeType.ProcessingInstruction
97-
? $"<?{xmlReader.Name} {normalizedTextValue}?>"
98-
: null;
93+
return xmlReader.NodeType switch
94+
{
95+
XmlNodeType.Text => normalizedTextValue,
96+
XmlNodeType.Comment => $"<!--{normalizedTextValue}-->",
97+
XmlNodeType.CDATA => $"<![CDATA[{normalizedTextValue}]]>",
98+
XmlNodeType.ProcessingInstruction => $"<?{xmlReader.Name} {normalizedTextValue}?>",
99+
_ => string.Empty,
100+
};
99101
}
100102
}

Src/CSharpier.Core/Xml/XmlFormatter.cs

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static CodeFormatterResult Format(string xml, PrinterOptions printerOpt
2626

2727
var lineEnding = PrinterOptions.GetLineEnding(xml, printerOptions);
2828
var elements = RawNodeReader.ReadAllNodes(xml, lineEnding, xmlReader);
29-
var printingContext = new XmlPrintingContext
29+
var printingContext = new PrintingContext
3030
{
3131
Options = new PrintingContext.PrintingContextOptions
3232
{
@@ -63,48 +63,4 @@ internal static CodeFormatterResult Format(string xml, PrinterOptions printerOpt
6363
};
6464
}
6565
}
66-
67-
private static readonly JsonSerializerOptions XmlFormatterJsonSerializerOptions = new()
68-
{
69-
ReferenceHandler = ReferenceHandler.Preserve,
70-
};
71-
72-
private static void CreateMapping(
73-
XNode? xNode,
74-
XmlNode? xmlNode,
75-
Dictionary<XNode, XmlNode> mapping
76-
)
77-
{
78-
if (xNode == null || xmlNode == null)
79-
{
80-
return;
81-
}
82-
83-
mapping[xNode] = xmlNode;
84-
85-
if (xNode is not XContainer xContainer)
86-
{
87-
return;
88-
}
89-
90-
var index = 0;
91-
if (xmlNode.ChildNodes[0] is XmlDeclaration)
92-
{
93-
index++;
94-
}
95-
foreach (var xChild in xContainer.Nodes())
96-
{
97-
if (index > xmlNode.ChildNodes.Count)
98-
{
99-
break;
100-
}
101-
102-
CreateMapping(xChild, xmlNode.ChildNodes[index], mapping);
103-
104-
index++;
105-
}
106-
}
10766
}
108-
109-
// TODO 1679 kill this
110-
internal class XmlPrintingContext : PrintingContext { }

0 commit comments

Comments
 (0)