Skip to content

Commit f53b5db

Browse files
authored
Merge pull request #49 from JansthcirlU/48-add-editorconfig-and-format-step-in-pipeline
2 parents 2f7720f + d38f0ca commit f53b5db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+426
-175
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
# Basic formatting
55
indent_style = space
66
indent_size = 4
7-
end_of_line = crlf
7+
end_of_line = lf
88
insert_final_newline = true
99
trim_trailing_whitespace = true
1010

.github/workflows/build-and-test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- "main"
7+
78
pull_request:
89
branches:
910
- "main"
@@ -17,14 +18,22 @@ jobs:
1718
runs-on: ubuntu-latest
1819

1920
steps:
20-
- uses: actions/checkout@v4
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
2124
- name: Setup .NET
2225
uses: actions/setup-dotnet@v4
2326
with:
2427
dotnet-version: 8.0.x
28+
29+
- name: Check formatter rules
30+
run: dotnet format --verify-no-changes --verbosity diagnostic
31+
2532
- name: Restore dependencies
2633
run: dotnet restore
34+
2735
- name: Build
2836
run: dotnet build --no-restore
37+
2938
- name: Test
3039
run: dotnet test --no-build --verbosity normal

src/Mermaid.Flowcharts/Flowchart.cs

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public Flowchart(FlowchartTitle title, FlowchartDirection? direction = null) : t
3030

3131
public Flowchart AddNode(INode node)
3232
{
33-
if (node is Node nd && Nodes.Any(nd.Equals)) return this;
33+
if (node is Node nd && Nodes.Any(nd.Equals))
34+
{
35+
return this;
36+
}
3437

3538
_nodes.Add(node);
3639
return this;
@@ -60,12 +63,20 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
6063
{
6164
flowchartStringBuilder.AppendLine(node.ToMermaidString(indentations + 1, indentationText));
6265
}
63-
if (Subgraphs.Any()) flowchartStringBuilder.AppendLine();
66+
if (Subgraphs.Any())
67+
{
68+
flowchartStringBuilder.AppendLine();
69+
}
70+
6471
foreach (Subgraph subgraph in Subgraphs)
6572
{
6673
flowchartStringBuilder.AppendLine(subgraph.ToMermaidString(indentations + 1, indentationText));
6774
}
68-
if (_links.Any()) flowchartStringBuilder.AppendLine();
75+
if (_links.Any())
76+
{
77+
flowchartStringBuilder.AppendLine();
78+
}
79+
6980
foreach (Link link in _links)
7081
{
7182
flowchartStringBuilder.AppendLine(link.ToMermaidString(indentations + 1, indentationText));
@@ -75,15 +86,27 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
7586
Dictionary<NodeStyle, HashSet<NodeIdentifier>> distinctNodeStyles = [];
7687
foreach (Node node in AllNodes)
7788
{
78-
if (node.NodeStyle is null) continue;
89+
if (node.NodeStyle is null)
90+
{
91+
continue;
92+
}
7993

8094
// Add node style declaration
81-
if (!distinctNodeStyles.ContainsKey(node.NodeStyle)) distinctNodeStyles[node.NodeStyle] = [];
82-
distinctNodeStyles[node.NodeStyle].Add(node.Id);
95+
if (!distinctNodeStyles.TryGetValue(node.NodeStyle, out HashSet<NodeIdentifier>? value))
96+
{
97+
value = [];
98+
distinctNodeStyles[node.NodeStyle] = value;
99+
}
100+
101+
value.Add(node.Id);
83102
}
84103

85104
// Add node style declarations and assignments
86-
if (distinctNodeStyles.Any()) flowchartStringBuilder.AppendLine();
105+
if (distinctNodeStyles.Any())
106+
{
107+
flowchartStringBuilder.AppendLine();
108+
}
109+
87110
foreach ((NodeStyle nodeStyle, HashSet<NodeIdentifier> nodeIds) in distinctNodeStyles)
88111
{
89112
flowchartStringBuilder.AppendLine(nodeStyle.ToMermaidString(indentations + 1, indentationText));
@@ -94,20 +117,32 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
94117
Dictionary<StyleClass, HashSet<int>> distinctLinkStyles = [];
95118
foreach ((Link link, int index) in AllLinks.Select((l, i) => (l, i)))
96119
{
97-
if (link.LinkStyle is null) continue;
120+
if (link.LinkStyle is null)
121+
{
122+
continue;
123+
}
98124

99125
// Add link style declaration
100-
if (!distinctLinkStyles.ContainsKey(link.LinkStyle)) distinctLinkStyles[link.LinkStyle] = [];
101-
distinctLinkStyles[link.LinkStyle].Add(index);
126+
if (!distinctLinkStyles.TryGetValue(link.LinkStyle, out HashSet<int>? value))
127+
{
128+
value = [];
129+
distinctLinkStyles[link.LinkStyle] = value;
130+
}
131+
132+
value.Add(index);
102133
}
103134

104135
// Add link style declarations and assignments
105-
if (distinctLinkStyles.Any()) flowchartStringBuilder.AppendLine();
136+
if (distinctLinkStyles.Any())
137+
{
138+
flowchartStringBuilder.AppendLine();
139+
}
140+
106141
foreach ((StyleClass styleClass, HashSet<int> indices) in distinctLinkStyles)
107142
{
108143
flowchartStringBuilder.AppendLine($"{indentationText.Repeat(indentations + 1)}linkStyle {string.Join(',', indices)} {styleClass.ToMermaidString()}");
109144
}
110145

111146
return flowchartStringBuilder.ToString();
112147
}
113-
}
148+
}

src/Mermaid.Flowcharts/FlowchartDirection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ public enum FlowchartDirection
2222
/// Left to right
2323
/// </summary>
2424
LR
25-
}
25+
}

src/Mermaid.Flowcharts/FlowchartTitle.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ private FlowchartTitle(string text)
1515

1616
public static FlowchartTitle FromString(string text)
1717
{
18-
if (string.IsNullOrEmpty(text)) throw new ArgumentException("Flowchart title must not be null or empty.", nameof(text));
19-
if (text.Contains('\n') || text.Contains('\r')) throw new ArgumentException("Flowchart title must not contain new lines.", nameof(text));
20-
if (string.IsNullOrEmpty(text.Trim())) throw new ArgumentException("Flowchart title must not be whitespace.", nameof(text));
21-
18+
if (string.IsNullOrEmpty(text))
19+
{
20+
throw new ArgumentException("Flowchart title must not be null or empty.", nameof(text));
21+
}
22+
23+
if (text.Contains('\n') || text.Contains('\r'))
24+
{
25+
throw new ArgumentException("Flowchart title must not contain new lines.", nameof(text));
26+
}
27+
28+
if (string.IsNullOrEmpty(text.Trim()))
29+
{
30+
throw new ArgumentException("Flowchart title must not be whitespace.", nameof(text));
31+
}
32+
2233
return new(
2334
$"""
2435
---

src/Mermaid.Flowcharts/IMermaidPrintable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace Mermaid.Flowcharts;
33
public interface IMermaidPrintable
44
{
55
string ToMermaidString(int indentations = 0, string indentationText = " ");
6-
}
6+
}

src/Mermaid.Flowcharts/Links/LinkDirection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ public enum LinkDirection
66
FromTo,
77
ToFrom,
88
Both
9-
}
9+
}

src/Mermaid.Flowcharts/Links/LinkText.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ private LinkText(string text)
1717

1818
public static LinkText FromString(string value)
1919
{
20-
if (string.IsNullOrEmpty(value)) throw new ArgumentException("Link text must not be null or empty.", nameof(value));
21-
if (value.Contains('\n') || value.Contains('\r')) throw new ArgumentException("Link text must not contain new lines.", nameof(value));
20+
if (string.IsNullOrEmpty(value))
21+
{
22+
throw new ArgumentException("Link text must not be null or empty.", nameof(value));
23+
}
24+
25+
if (value.Contains('\n') || value.Contains('\r'))
26+
{
27+
throw new ArgumentException("Link text must not contain new lines.", nameof(value));
28+
}
29+
2230
int illegalCharacterIndex = value.AsSpan().IndexOfAny(IllegalCharacters);
23-
if (illegalCharacterIndex > -1) throw new ArgumentException($"Link text must not contain illegal character \"{value[illegalCharacterIndex]}\".", nameof(value));
31+
if (illegalCharacterIndex > -1)
32+
{
33+
throw new ArgumentException($"Link text must not contain illegal character \"{value[illegalCharacterIndex]}\".", nameof(value));
34+
}
35+
2436
return new(value);
2537
}
2638

@@ -29,4 +41,4 @@ public override string ToString()
2941

3042
public string ToMermaidString(int indentations = 0, string indentationText = " ")
3143
=> $"{indentationText.Repeat(indentations)}{Value}";
32-
}
44+
}

src/Mermaid.Flowcharts/Links/LinkType.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
3333
LinkThickness.Invisible => "~~~",
3434
_ => "---"
3535
};
36-
if (Thickness is LinkThickness.Invisible) return thickness;
36+
if (Thickness is LinkThickness.Invisible)
37+
{
38+
return thickness;
39+
}
3740

3841
string arrowLeft = (ArrowType, Direction) switch
3942
{

src/Mermaid.Flowcharts/Nodes/INode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public interface INode : IMermaidPrintable
88
public interface INode<TNode> : INode, IEquatable<TNode>
99
where TNode : INode<TNode>
1010
{
11-
12-
}
11+
12+
}

0 commit comments

Comments
 (0)