Skip to content

[Feature Request] Align assignments in column #1192

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

Closed
xshaheen opened this issue Jun 27, 2021 · 1 comment
Closed

[Feature Request] Align assignments in column #1192

xshaheen opened this issue Jun 27, 2021 · 1 comment
Labels
Resolved-Duplicate This issue or pull request already exists Triaged This issue has been reviewed

Comments

@xshaheen
Copy link

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,
};
@JoeRobich
Copy link
Member

The Roslyn formatter does not currently support column alignment. Closing this issue as there are several open issues tracking support for this type of formatting dotnet/roslyn#51389, dotnet/roslyn#28729, and dotnet/roslyn#38241. Please vote them up and add any specific requirements that you might have.

@JoeRobich JoeRobich added Resolved-Duplicate This issue or pull request already exists Triaged This issue has been reviewed labels Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolved-Duplicate This issue or pull request already exists Triaged This issue has been reviewed
Projects
None yet
Development

No branches or pull requests

2 participants