Skip to content

[Feature Request] Align assignments in column #1192

Description

@xshaheen

Add options to enable format code as following:

Object initializer:

// From
var foo = new X {
     short = "short member",
     longEnough = "long member",
}

// To
var foo = new X {
     short      = "short member",
     longEnough = "long member",
}

Tuple initializers

// From
var foo = (
    short: "short member",
    longEnough: "long member"
);

var foo = (
    short:      "short member",
    longEnough: "long member"
);

For enum:

// From
public enum X {
   Foo = 1,
   FooBar = 2,
   X = 3,
}

// To
public enum X {
   Foo    = 1,
   FooBar = 2,
   X      = 3,
}

Field assignment

// From
private string x = "x";
public Foo xxxxxxxx = "long name";

// To
private string x    = "x";
public Foo xxxxxxxx = "long name";

Variable assignment

// From
var x = 1;
var xxxxxx = 2;
var xxx = 2;

// To
var x      = 1;
var xxxxxx = 2;
var xxx    = 2;

Switch expressions

// From
var foo = op switch {
    op.Add => x + y,
    op.Subtract => x - y,
    op.Multiply => x * y,
    op.Divide => x / y
}

// To
var foo = op switch {
    op.Add      => x + y,
    op.Subtract => x - y,
    op.Multiply => x * y,
    op.Divide   => x / y
}

Property patterns

// From
bool matches = obj is Foo {
    Short: 1,
    LongEnough: 2,
};

// To
bool matches = obj is Foo {
    Short:      1,
    LongEnough: 2,
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolved-DuplicateThis issue or pull request already existsTriagedThis issue has been reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions