Skip to content

Commit f8ca125

Browse files
committed
Keeping property on the first line
1 parent fd3865b commit f8ca125

5 files changed

Lines changed: 24 additions & 29 deletions

File tree

Src/CSharpier.Core/CSharp/SyntaxPrinter/SyntaxNodePrinters/InvocationExpression.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,17 @@ private static bool ShouldMergeFirstTwoGroups(
359359

360360
if (
361361
firstNode
362-
is not (
363-
IdentifierNameSyntax { Identifier.Text.Length: <= 4 }
364-
or ThisExpressionSyntax
365-
or PredefinedTypeSyntax
366-
or BaseExpressionSyntax
362+
is not (
363+
IdentifierNameSyntax
364+
or ThisExpressionSyntax
365+
or PredefinedTypeSyntax
366+
or BaseExpressionSyntax
367+
)
368+
|| (
369+
groups[1].Count > 1
370+
&& firstNode is IdentifierNameSyntax { Identifier.Text.Length: > 4 }
371+
&& groups[1][0].Node is MemberAccessExpressionSyntax
372+
&& groups[1][1].Node is InvocationExpressionSyntax
367373
)
368374
)
369375
{

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/BinaryExpressions.test

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ class TestClass
201201
) ?? someOtherValue;
202202

203203
var x =
204-
someValue
205-
.Property
204+
someValue.Property
206205
.CallLongMethod_____________________________________()
207206
.CallMethod(
208207
someLongValue__________________________________________,
@@ -355,22 +354,19 @@ class TestClass
355354
) ?? someOtherValue;
356355

357356
var x =
358-
someValue
359-
.Property
357+
someValue.Property
360358
.CallLongMethod_____________________________________()
361359
.CallMethod__________()
362360
?? throw new Exception();
363361

364362
var x =
365-
someValue
366-
.Property
363+
someValue.Property
367364
.CallLongMethod_____________________________________()
368365
.CallMethod__________(someParameter)
369366
?? throw new Exception();
370367

371368
var x =
372-
someValue
373-
.Property
369+
someValue.Property
374370
.CallLongMethod_____________________________________()
375371
.CallLongMethod___________________________________________________()
376372
?? throw new Exception();

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChain_PropertiesConsistent.test

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ var someVariable = someObject
77
.CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________);
88

99
var someVariable = someObject
10-
.Property()
10+
.CallMethod()
1111
.CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________);
1212

13-
var someVariable = someObject
14-
.Property
13+
var someVariable = someObject.Property
1514
.CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________)
1615
.CallMethod();
1716

1817
var someVariable = someObject
19-
.Property()
18+
.CallMethod()
2019
.CallMethod(someValue => someValue.SomeProperty == someOtherValue___________________________)
2120
.CallMethod();
2221

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/MemberChains.test

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ var someValue = someOtherValue!
5252
.Where(o => someLongCondition__________________________)
5353
.Where(o => someLongCondition__________________________);
5454

55-
var someValue = someOtherValue
56-
.Thing
55+
var someValue = someOtherValue.Thing
5756
.Where(o => someLongCondition__________________________)
5857
.Where(o => someLongCondition__________________________);
5958

@@ -78,8 +77,7 @@ roleNames
7877
this.SomeProperty.Setup(o => longThing_______________________________________)
7978
);
8079

81-
roleNames
82-
.Value
80+
roleNames.Value
8381
.Where(o => o.SomeProperty____________________________________)
8482
.Select(o => o.SomethingElse);
8583

@@ -231,18 +229,15 @@ var someValue = CallMethod______________________(
231229
)
232230
.CallMethod__________________();
233231

234-
someThing_______________________
235-
.Property
232+
someThing_______________________.Property
236233
.CallMethod__________________()
237234
.CallMethod__________________();
238235

239-
someThing_______________________
240-
?.Property
236+
someThing_______________________?.Property
241237
.CallMethod__________________()
242238
.CallMethod__________________();
243239

244-
someThing_______________________
245-
.Property!
240+
someThing_______________________.Property!
246241
.CallMethod__________________()
247242
.CallMethod__________________();
248243

Src/CSharpier.Tests/FormattingTests/TestFiles/cs/SpreadElements.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ int[] someOtherArray =
1010

1111
List<KeyValuePair<string, string>> list =
1212
[
13-
.. attribute
14-
.Targets
13+
.. attribute.Targets
1514
.Select(target =>
1615
KeyValuePair.Create(
1716
target,

0 commit comments

Comments
 (0)