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

SuppressNullableWarningExpression should break consistently with invocation expressions #598

Merged
merged 8 commits into from
Feb 28, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class ClassName
?.DoSomething___________________()
?.DoSomething___________________();

this.DoSomething___________________()!
.DoSomething___________________()!
.DoSomething___________________();

base.DoSomething___________________()
.DoSomething___________________()
.DoSomething___________________();
Expand Down Expand Up @@ -43,6 +47,14 @@ class ClassName
.Where(o => someLongCondition__________________________)
.Where(o => someLongCondition__________________________);

var someValue = someOtherValue!
.Where(o => someLongCondition__________________________)
.Where(o => someLongCondition__________________________);

var someValue = someOtherValue!.Thing!
.Where(o => someLongCondition__________________________)
.Where(o => someLongCondition__________________________);

var someValue = someOtherValue
.Where(o => someLongCondition__________________________)
.Where(o => someLongCondition__________________________)
Expand Down Expand Up @@ -79,12 +91,21 @@ class ClassName
someLongParameter____________________________
);

string.Equals(
firstParameter__________,
secondParameter_________,
StringComparison.OrdinalIgnoreCase
someValue.CallMethod(
someLongParameter____________________________,
someLongParameter____________________________
);

someValue!.CallMethod(
someLongParameter____________________________,
someLongParameter____________________________
);

CallSomeMethod(
someParameter____________________________________,
someParameter____________________________________
)!;

var someVariable = someObject.Property.CallMethod(
someValue => someValue.SomeProperty == someOtherValue___________________________________
);
Expand Down Expand Up @@ -193,5 +214,21 @@ class ClassName

this.CallMethod()
.CallMethod__________________(one_____________________, two_____________________);

var someValue = CallMethod__________________(longParameter________________________________)!
.CallMethod__________________();

var someValue = CallMethod__________________(longParameter________________________________)
.CallMethod__________________();

var someValue = CallMethod__________________(
longParameter_______________________________________
)!
.CallMethod__________________();

var someValue = CallMethod__________________(
longParameter_______________________________________
)
.CallMethod__________________();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ or IdentifierNameSyntax
}
},
Parent: { Parent: InvocationExpressionSyntax }
or PostfixUnaryExpressionSyntax
{
Parent: { Parent: InvocationExpressionSyntax }
}
},
ArgumentListLike.Print(node.OpenParenToken, node.Arguments, node.CloseParenToken)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ public static Doc PrintMemberChain(ExpressionSyntax node)

var forceOneLine =
groups.Count <= cutoff
&& !groups
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
.All(o => o.Last().Node is InvocationExpressionSyntax);
&& (
groups
.Skip(shouldMergeFirstTwoGroups ? 1 : 0)
.Any(
o =>
o.Last().Node
is not (
InvocationExpressionSyntax
or PostfixUnaryExpressionSyntax
{
Operand: InvocationExpressionSyntax
}
)
)
// if the last group contains just a !, make sure it doesn't end up on a new line
|| (
groups.Last().Count == 1
&& groups.Last()[0].Node is PostfixUnaryExpressionSyntax
)
);

if (forceOneLine)
{
Expand Down Expand Up @@ -113,6 +130,21 @@ And we want to work with them from Left to Right
);
FlattenAndPrintNodes(conditionalAccessExpressionSyntax.WhenNotNull, printedNodes);
}
else if (
expression is PostfixUnaryExpressionSyntax
{
Operand: InvocationExpressionSyntax
} postfixUnaryExpression
)
{
FlattenAndPrintNodes(postfixUnaryExpression.Operand, printedNodes);
printedNodes.Add(
new PrintedNode(
postfixUnaryExpression,
Token.Print(postfixUnaryExpression.OperatorToken)
)
);
}
else
{
printedNodes.Add(new PrintedNode(expression, Node.Print(expression)));
Expand Down Expand Up @@ -166,8 +198,11 @@ private static List<List<PrintedNode>> GroupPrintedNodes(List<PrintedNode> print
for (; index + 1 < printedNodes.Count; ++index)
{
if (
IsMemberish(printedNodes[index].Node)
&& IsMemberish(printedNodes[index + 1].Node)
(
IsMemberish(printedNodes[index].Node)
&& IsMemberish(printedNodes[index + 1].Node)
)
|| printedNodes[index].Node is PostfixUnaryExpressionSyntax
)
{
currentGroup.Add(printedNodes[index]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ internal static class PostfixUnaryExpression
{
public static Doc Print(PostfixUnaryExpressionSyntax node)
{
if (
node.Kind() is SyntaxKind.SuppressNullableWarningExpression
&& node.Operand is InvocationExpressionSyntax
)
{
return InvocationExpression.PrintMemberChain(node);
}

return Doc.Concat(Node.Print(node.Operand), Token.Print(node.OperatorToken));
}
}