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

SwitchExpression + Pattern edge cause causes extra line and poor formatting #408

Closed
belav opened this issue Aug 21, 2021 · 0 comments · Fixed by #411
Closed

SwitchExpression + Pattern edge cause causes extra line and poor formatting #408

belav opened this issue Aug 21, 2021 · 0 comments · Fixed by #411
Assignees
Milestone

Comments

@belav
Copy link
Owner

belav commented Aug 21, 2021

There are two issues

  1. The extra space before (FieldSymbol is added, if you format a second time it ends up with two spaces. But it stops there
  2. The formatting of the (FieldSymbol area..... leaves a little to be desired
class ClassName
{
    private static bool AreCloseEnough(Symbol original, Symbol updated)
    {
        return (original, updated) switch
        {
            (LambdaSymbol l, NamedTypeSymbol n) _ when n.IsDelegateType() => AreLambdaAndNewDelegateSimilar(l, n),
            (FieldSymbol { ContainingType: { IsTupleType: true }, TupleElementIndex: var oi } originalField, FieldSymbol { ContainingType: { IsTupleType: true }, TupleElementIndex: var ui } updatedField) =>
                originalField.Type.Equals(updatedField.Type, TypeCompareKind.AllNullableIgnoreOptions | TypeCompareKind.IgnoreTupleNames) && oi == ui,
            _ => original.Equals(updated, TypeCompareKind.AllNullableIgnoreOptions | TypeCompareKind.IgnoreTupleNames)
        };
    }
}

// Formats as

class ClassName
{
    private static bool AreCloseEnough(Symbol original, Symbol updated)
    {
        return (original, updated) switch
        {

            (LambdaSymbol l, NamedTypeSymbol n) _ when n.IsDelegateType()
              => AreLambdaAndNewDelegateSimilar(l, n),

            (FieldSymbol
            {
                ContainingType: { IsTupleType: true },
                TupleElementIndex: var oi
            } originalField, FieldSymbol
            {
                ContainingType: { IsTupleType: true },
                TupleElementIndex: var ui
            } updatedField)
              => originalField.Type.Equals(
                  updatedField.Type,
                  TypeCompareKind.AllNullableIgnoreOptions | TypeCompareKind.IgnoreTupleNames
              )
                  && oi == ui,
            _
              => original.Equals(
                  updated,
                  TypeCompareKind.AllNullableIgnoreOptions | TypeCompareKind.IgnoreTupleNames
              )
        };
    }
}
@belav belav self-assigned this Aug 21, 2021
@belav belav added this to the 0.9.9 milestone Aug 21, 2021
@belav belav changed the title Switch expression / Pattern Matching extra line + poorly formatted SwitchExpression + Pattern edge cause causes extra line and poor formatting Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant