Skip to content

Commit

Permalink
Add some extra new lines (#36)
Browse files Browse the repository at this point in the history
New lines between the last using statement and namespace decl. Add
trailing new line at the end of the namespace.
  • Loading branch information
jhendrixMSFT authored Sep 24, 2024
1 parent b60b9b9 commit 1ee2673
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/csharp-spacing-2024-8-24-11-22-26.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@alloy-js/csharp"
---

add extra new-lines to improve readability
6 changes: 3 additions & 3 deletions packages/csharp/src/components/SourceFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ export function SourceFile(props: SourceFileProps) {
<core.Scope name={props.path} kind="source-file">
{using.length > 0 ? (
<>
<UsingDirective namespaces={using} />{"\n"}
<UsingDirective namespaces={using} />{"\n\n"}
</>
) : undefined}namespace {namespaceCtx.name}{!props.children && " {}"}{props.children &&
) : undefined}namespace {namespaceCtx.name}{!props.children && " {}\n"}{props.children &&
<>
{"\n{"}
{props.children}
{"}"}
{"}\n"}
</>
}
</core.Scope>
Expand Down
8 changes: 8 additions & 0 deletions packages/csharp/test/class.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ it("declares class with no members", () => {
{
public class TestClass;
}
`);
});

Expand All @@ -34,6 +35,7 @@ it("declares class with some members", () => {
private int memberTwo;
}
}
`);
});

Expand All @@ -54,6 +56,7 @@ it("declares class with some methods", () => {
private virtual void MethodTwo() {}
}
}
`);
});

Expand Down Expand Up @@ -82,6 +85,7 @@ it("declares class with params and return type", () => {
public string MethodOne(int intParam, string stringParam) {}
}
}
`);
});

Expand Down Expand Up @@ -141,6 +145,7 @@ it("uses refkeys for members, params, and return type", () => {
}
}
}
`);
});

Expand All @@ -166,6 +171,7 @@ it("declares class with generic parameters", () => {
private U memberTwo;
}
}
`);
});

Expand Down Expand Up @@ -196,6 +202,7 @@ it("declares class with constructor", () => {
public TestClass() {}
}
}
`);
});

Expand Down Expand Up @@ -245,5 +252,6 @@ it("declares class with constructor params and assigns values to fields", () =>
}
}
}
`);
});
6 changes: 6 additions & 0 deletions packages/csharp/test/enum.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ it("declares enum with no members", () => {
{
public enum TestEnum;
}
`);
});

Expand All @@ -34,6 +35,7 @@ it("declares enum with members", () => {
Two
}
}
`);
});

Expand All @@ -54,6 +56,7 @@ it("applies naming policy to enum and members", () => {
Two
}
}
`);
});

Expand Down Expand Up @@ -87,6 +90,7 @@ it("can reference things by refkey", () => {
TestEnum;
TestEnum.Two;
}
`);
});

Expand Down Expand Up @@ -129,6 +133,7 @@ it("can reference things by refkey across files", () => {
OtherEnum;
OtherEnum.Bar;
}
`);

expect(res.contents[1].path).toBe("Other.cs");
Expand All @@ -143,5 +148,6 @@ it("can reference things by refkey across files", () => {
OtherEnum;
OtherEnum.Bar;
}
`);
});
4 changes: 4 additions & 0 deletions packages/csharp/test/namespace.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ it("defines multiple namespaces and source files with unique content", () => {
{
public class Model1;
}
`);

expect(res.contents[1].path).equals("Model2.cs");
Expand All @@ -39,6 +40,7 @@ it("defines multiple namespaces and source files with unique content", () => {
{
public class Model2;
}
`);

expect(res.contents[2].path).equals("Model3.cs");
Expand All @@ -47,6 +49,7 @@ it("defines multiple namespaces and source files with unique content", () => {
{
public class Model3;
}
`);

expect(res.contents[3].path).equals("Model4.cs");
Expand All @@ -55,5 +58,6 @@ it("defines multiple namespaces and source files with unique content", () => {
{
public class Model4;
}
`);
});
4 changes: 4 additions & 0 deletions packages/csharp/test/projectdirectory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ it("defines a project directory file with multiple source files", () => {
{
public class TestClass1;
}
`);

expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
Expand All @@ -51,6 +52,7 @@ it("defines a project directory file with multiple source files", () => {
{
public class TestClass2;
}
`);
});

Expand Down Expand Up @@ -94,6 +96,7 @@ it("defines a project directory file with multiple source files and a custom TFM
{
public class TestClass1;
}
`);

expect(srcDir.contents[1].path).equals("~/projects/TestProject/src/Test2.cs");
Expand All @@ -102,5 +105,6 @@ it("defines a project directory file with multiple source files and a custom TFM
{
public class TestClass2;
}
`);
});
2 changes: 2 additions & 0 deletions packages/csharp/test/sourcefile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ it("defines multiple source files with unique content", () => {
{
public class TestClass1;
}
`);

expect(res.contents[1].path).equals("Test2.cs");
Expand All @@ -31,6 +32,7 @@ it("defines multiple source files with unique content", () => {
{
public class TestClass2;
}
`);
});

Expand Down
7 changes: 7 additions & 0 deletions packages/csharp/test/using.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ it("uses a single namespace", () => {

expect(res.contents[0].contents).toBe(coretest.d`
using Foo;
namespace TestCode {}
`);
});

Expand All @@ -30,7 +32,9 @@ it("uses multiple namespaces", () => {
expect(res.contents[0].contents).toBe(coretest.d`
using Bar.Baz;
using Foo;
namespace TestCode {}
`);
});

Expand Down Expand Up @@ -80,11 +84,13 @@ it("adds using statement across namespaces", () => {
Two
}
}
`);

expect(res.contents[1].contents).toBe(coretest.d`
using Models;
using System;
namespace Client
{
public class Client
Expand All @@ -93,5 +99,6 @@ it("adds using statement across namespaces", () => {
}
TestEnum.Two;
}
`);
});

0 comments on commit 1ee2673

Please sign in to comment.