Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new line in empty blocks #763

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/CSharpier.Tests/CodeFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void Format_Should_Get_Line_Endings_With_SyntaxTree(string lineEnding)
var syntaxTree = CSharpSyntaxTree.ParseText(code);
var result = CodeFormatter.Format(syntaxTree);

result.Should().Be("public class ClassName { }" + lineEnding);
result.Should().Be($"public class ClassName{lineEnding}{{{lineEnding}}}{lineEnding}");
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
namespace Namespace
{
[Obsolete]
class ClassOne { }
class ClassOne
{
}

[Obsolete]
[NoNewLine]
// do stuff
class ClassTwo { }
class ClassTwo
{
}

class ClassThree { }
class ClassThree
{
}
}
52 changes: 39 additions & 13 deletions Src/CSharpier.Tests/FormattingTests/TestFiles/AttributeLists.cst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ClassName
}

[Obsolete, NonSerialized]
void MethodName([In] string value) { }
void MethodName([In] string value)
{
}

[
Obsolete,
Expand All @@ -32,27 +34,37 @@ class ClassName
static extern bool NameEquals(string name, SecurityAttribute sa);

[Obsolete("Error", error: true)]
void NameColon() { }
void NameColon()
{
}

[return: Obsolete]
[method: Obsolete]
void Targets() { }
void Targets()
{
}

// leading
[Obsolete] // trailing
class ClassOne { }
class ClassOne
{
}

// leading with new line
[Obsolete] // more trailing
// leading before class
class ClassTwo { }
class ClassTwo
{
}

[LongAttributeWithParametersBreaking(
"someValue_____________",
"someValue_____________",
"someValue_____________"
)]
void LongAttribute() { }
void LongAttribute()
{
}

public void MethodName([FromBody] SomeParameter parameter)
{
Expand All @@ -70,18 +82,24 @@ class ClassName
return;
}

public void MethodWithAttributesOnTypeParameters<[SomeShort] T, K>() { }
public void MethodWithAttributesOnTypeParameters<[SomeShort] T, K>()
{
}

public void MethodWithAttributesOnTypeParameters<
[SomeLongAttribute__________________________] T,
K
>() { }
>()
{
}

public void MethodWithAttributesOnTypeParameters<
[SomeLongAttribute__________________________]
TSomeMuchLongerName___________________________________,
K
>() { }
>()
{
}

public void MethodWithAttributesOnTypeParameters<
[SomeAttributeWithParameters(
Expand All @@ -90,7 +108,9 @@ class ClassName
)]
TSomeMuchLongerName___________________________________,
K
>() { }
>()
{
}
}

[
Expand All @@ -101,14 +121,20 @@ class ClassName
),
AnotherAttribute
]
public class ClassName { }
public class ClassName
{
}

[GenericAttribute<string>()]
public class ClassName { }
public class ClassName
{
}

[Generic<
LongName______________________,
LongName______________________,
LongName______________________
>]
public class ClassName { }
public class ClassName
{
}
40 changes: 30 additions & 10 deletions Src/CSharpier.Tests/FormattingTests/TestFiles/BinaryExpressions.cst
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ class TestClass
one == two
|| someValue_______________
== thisWillIndent_______________________________________________________________
) { }
)
{
}

while (
one == two
|| someValue_______________
== thisWillIndent_______________________________________________________________
) { }
)
{
}

switch (
one == two
Expand Down Expand Up @@ -129,30 +133,38 @@ class TestClass
|| one - two > three
|| someLongThing - someOtherLongThing__________________________________
> anotherLongThing
) { }
)
{
}

if (
CallSomeMethod(
someParameter_____________________________________,
someParameter_____________________________________
) == 0
) { }
)
{
}

if (
someValue
&& CallSomeMethod(
someParameter_____________________________________,
someParameter_____________________________________
) == 0
) { }
)
{
}

if (
CallSomeMethod(
someParameter_____________________________________,
someParameter_____________________________________
) == 0
&& someValue
) { }
)
{
}

if (
CallMethod(
Expand All @@ -163,14 +175,18 @@ class TestClass
someParameter_____________________________________,
someParameter_____________________________________
)
) { }
)
{
}

if (
CallMethod(
someParameter_____________________________________,
someParameter_____________________________________
) || CallMethod(shortValue, "shortValue")
) { }
)
{
}

if (
CallMethod(
Expand All @@ -179,12 +195,16 @@ class TestClass
)
|| CallMethod(shortValue, "shortValue")
|| CallMethod(shortValue1, "shortValue1")
) { }
)
{
}

if (
CallSomeMethod(someParameter)
== someLongerValue_______________________________________________________________
) { }
)
{
}

return someValue != someOtherValue
&& someLongValue_____________________ == someOtherLongValue_____________________;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ namespace Namespace
public class Unformatted { }
// csharpier-ignore-end

public class FormatMe { }
public class FormatMe
{
}
}
56 changes: 42 additions & 14 deletions Src/CSharpier.Tests/FormattingTests/TestFiles/ClassDeclarations.cst
Original file line number Diff line number Diff line change
@@ -1,45 +1,69 @@
public class EmptyClass { }
public class EmptyClass
{
}

public static abstract class MoreModifiers { }
public static abstract class MoreModifiers
{
}

class NoModifiers { }
class NoModifiers
{
}

public class WithInterface : IInterface { }
public class WithInterface : IInterface
{
}

public class WithReallyLongNameInterface
: IReallyLongNameLetsMakeThisBreak___________________________ { }
: IReallyLongNameLetsMakeThisBreak___________________________
{
}

public class ThisIsSomeLongNameAndItShouldFormatWell1
: AnotherLongClassName,
AndYetAnotherLongClassName,
AndStillOneMore { }
AndStillOneMore
{
}

public class SimpleGeneric<T> where T : new() { }
public class SimpleGeneric<T> where T : new()
{
}

public class LongTypeConstraints<T>
where T : SomeLongNameThatJustKeepsGoing,
AndThenAnotherOneThatIsEvenLonger____________________ { }
AndThenAnotherOneThatIsEvenLonger______________________________
{
}

public class LongerClassNameWithLotsOfGenerics<
TLongName,
TAnotherLongName,
TThirdLongName__________________
> { }
>
{
}

public class LongerClassNameWithLotsOfGenerics<
TLongName,
TAnotherLongName,
TThirdLongName__________________
> : SomeBaseClass<TLongName> { }
> : SomeBaseClass<TLongName>
{
}

public class SimpleGeneric<T> : BaseClass<T> where T : new() { }
public class SimpleGeneric<T> : BaseClass<T> where T : new()
{
}

public class ThisIsSomeLongNameAndItShouldFormatWell2<T, T2, T3>
: AnotherLongClassName<T>,
AnotherClassName
where T : new(), AnotherTypeConstraint
where T2 : new()
where T3 : new() { }
where T3 : new()
{
}

public class IdentityDbContext<TUser, TRole, TKey>
: IdentityDbContext<
Expand All @@ -54,6 +78,10 @@ public class IdentityDbContext<TUser, TRole, TKey>
>
where TUser : IdentityUser<TKey>
where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey> { }
where TKey : IEquatable<TKey>
{
}

file class FileScopedType { }
file class FileScopedType
{
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
public class ClassName { }
public class ClassName
{
}

public class ClassName { }
public class ClassName
{
}
Loading