Skip to content

Commit

Permalink
Better(?) way of dealing with breaking in VariableDeclarations
Browse files Browse the repository at this point in the history
closes #47
  • Loading branch information
belav committed May 31, 2021
1 parent c7685df commit b4cbbc3
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class ClassName
{
public dynamic ShortValue = new { Property = true };

public dynamic LongValue = new
{
One = "One",
Two = "Two",
ThreeThreeThree = "ThreeThreeThree"
};

public dynamic Value = new { NoName };
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class AnonymousObjectCreationExpressionTests : BaseTest
{
[Test]
public void BasicAnonymousObjectCreationExpression()
public void AnonymousObjectCreationExpressions()
{
this.RunTest(
"AnonymousObjectCreationExpression",
"BasicAnonymousObjectCreationExpression"
);
}
[Test]
public void MultipleProperties()
{
this.RunTest("AnonymousObjectCreationExpression", "MultipleProperties");
}
[Test]
public void NoNames()
{
this.RunTest("AnonymousObjectCreationExpression", "NoNames");
this.RunTest("AnonymousObjectCreationExpression", "AnonymousObjectCreationExpressions");
}
}
}
6 changes: 0 additions & 6 deletions Src/CSharpier.Tests/TestFiles/Comments/SpecialCases.cst
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ class ClassName
{
// indent
}

var x = new SomeClass
{
Property1 = true
// indent
};
}

void MethodName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CSharpier.Tests.TestFiles
public class ConditionalExpressionTests : BaseTest
{
[Test]
public void BasicConditionalExpression()
public void ConditionalExpressions()
{
this.RunTest("ConditionalExpression", "ConditionalExpressions");
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,27 @@ public class ClassName
Property4 = false,
Property5 = false
};

// leading comments
private static const string SomeName = "1";

public SomeClass SomeName; // trailing comments

public System.Text.StringBuilder NamespacedField;

public static Dictionary<Type, string> PropertiesByType
= new Dictionary<Type, string>();

public static Dictionary<
SomeLongTypeName,
SomeOtherLongTypeName_______________________________
> PropertiesByType = new Dictionary<
SomeLongTypeName,
SomeOtherLongTypeName_______________________________
>();
}

struct S
{
fixed int field[10];
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class FieldDeclarationTests : BaseTest
{
[Test]
public void BasicField()
public void FieldDeclarations()
{
this.RunTest("FieldDeclaration", "BasicField");
}
[Test]
public void FieldDeclarationComments()
{
this.RunTest("FieldDeclaration", "FieldDeclarationComments");
}
[Test]
public void FixedFieldWithSize()
{
this.RunTest("FieldDeclaration", "FixedFieldWithSize");
}
[Test]
public void NamespacedField()
{
this.RunTest("FieldDeclaration", "NamespacedField");
this.RunTest("FieldDeclaration", "FieldDeclarations");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class ImplicitElementAccessTests : BaseTest
{
[Test]
public void BasicImplicitElementAccess()
public void ImplicitElementAccesses()
{
this.RunTest("ImplicitElementAccess", "BasicImplicitElementAccess");
this.RunTest("ImplicitElementAccess", "ImplicitElementAccesses");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ class ClassName
longValue______________________________
}
};

void MethodName()
{
var x = new SomeClass
{
Property1 = true
// should indent
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public class ClassName
set;
}

public virtual ICollection<SomeObject> SomeLongNameThatForcesALineBreak { get; set; } =
public virtual ICollection<
SomeObject
> SomeLongNameThatForcesALineBreak { get; set; } =
new HashSet<SomeObject>();

public Dictionary<string, string> Properties { get; set; } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ class ClassName
{
var query1 = from c in customers select c;
query1 = from c in customers select c into d select d;
query1 =
from c in customers
join c1 in customers11111111111111111111111111111
on c1.GetHashCode() equals c.GetHashCode()
into e
select c into d
select d;

var query2 = from Customer c in customers select c;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
class ClassName
{
void MethodName()
int MethodName()
{
return 1 switch
{
1 => 100,
2 => 200,
3 when false => 300,
_ => throw new global::System.Exception()
};

var newState = (GetState(), action, hasKey) switch
{
(DoorState.Closed, Action.Open, _) => DoorState.Opened,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ namespace CSharpier.Tests.TestFiles
public class SwitchExpressionTests : BaseTest
{
[Test]
public void BasicSwitchExpression()
public void SwitchExpressions()
{
this.RunTest("SwitchExpression", "BasicSwitchExpression");
}
[Test]
public void SwitchWithRecursivePattern()
{
this.RunTest("SwitchExpression", "SwitchWithRecursivePattern");
this.RunTest("SwitchExpression", "SwitchExpressions");
}
}
}
1 change: 1 addition & 0 deletions Src/CSharpier/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private async Task FormatFile(string file, CancellationToken cancellationToken)
&& result.Code != fileReaderResult.FileContents
) {
// purposely avoid async here, that way the file completely writes if the process gets cancelled while running.
// ReSharper disable once MethodHasAsyncOverloadWithCancellation
this.FileSystem.File.WriteAllText(file, result.Code, fileReaderResult.Encoding);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ public static Doc Print(AssignmentExpressionSyntax node)
Node.Print(node.Left),
" ",
Token.Print(node.OperatorToken),
node.Right is QueryExpressionSyntax ? Doc.Null : " ",
Node.Print(node.Right)
node.Right is QueryExpressionSyntax
? Doc.Indent(Doc.Line, Node.Print(node.Right))
: Doc.Concat(" ", Node.Print(node.Right))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Doc Print(BaseFieldDeclarationSyntax node)
docs.Add(Token.PrintWithSuffix(eventFieldDeclarationSyntax.EventKeyword, " "));
}

docs.Add(Node.Print(node.Declaration), Token.Print(node.SemicolonToken));
docs.Add(VariableDeclaration.Print(node.Declaration), Token.Print(node.SemicolonToken));
return Doc.Concat(docs);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ public static Doc Print(EqualsValueClauseSyntax node)
separator = Doc.Null;
}
else if (
node.Value is AnonymousObjectCreationExpressionSyntax
|| node.Value is AnonymousMethodExpressionSyntax
|| node.Value is ConditionalExpressionSyntax
|| node.Value is ObjectCreationExpressionSyntax
|| node.Value is InitializerExpressionSyntax
|| node.Value is ParenthesizedLambdaExpressionSyntax
|| node.Value is InvocationExpressionSyntax
|| node.Value is SwitchExpressionSyntax
node.Value
is AnonymousObjectCreationExpressionSyntax
or AnonymousMethodExpressionSyntax
or ConditionalExpressionSyntax
or ObjectCreationExpressionSyntax
or InitializerExpressionSyntax
or ParenthesizedLambdaExpressionSyntax
or InvocationExpressionSyntax
or SwitchExpressionSyntax
) {
separator = " ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public static class QueryExpression
{
public static Doc Print(QueryExpressionSyntax node)
{
return Doc.Indent(
Doc.Line,
return Doc.Concat(
FromClause.Print(node.FromClause),
Doc.Line,
QueryBody.Print(node.Body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public static Doc Print(TypeArgumentListSyntax node)
{
return Doc.Concat(
Token.Print(node.LessThanToken),
Doc.Indent(SeparatedSyntaxList.Print(node.Arguments, Node.Print, Doc.Line)),
Doc.Indent(
Doc.SoftLine,
SeparatedSyntaxList.Print(node.Arguments, Node.Print, Doc.Line)
),
Doc.SoftLine,
Token.Print(node.GreaterThanToken)
);
}
Expand Down
Loading

0 comments on commit b4cbbc3

Please sign in to comment.