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

Improve formatting of Field with Array Initializer #290

Closed
belav opened this issue Jun 12, 2021 · 5 comments
Closed

Improve formatting of Field with Array Initializer #290

belav opened this issue Jun 12, 2021 · 5 comments
Assignees
Labels

Comments

@belav
Copy link
Owner

belav commented Jun 12, 2021

// currently formats like
        private static readonly string[] _defaultSources = new string[]
        {
            "https://api.nuget.org/v3/index.json"
        };
// but if it can fit onto two lines like this, that would be preferred
        private static readonly string[] _defaultSources =
            new string[] { "https://api.nuget.org/v3/index.json" };
@belav
Copy link
Owner Author

belav commented Aug 4, 2021

The code in RightHandSide is probably what needs to change, but there are a ton of edge cases that get ruined every time I attemp to figure out how to get this working.

@belav
Copy link
Owner Author

belav commented Aug 4, 2021

There is also the question of if

this should break, because it has multiple items
    private string[] SomeArray = new[]
    {
        "SomeValue_____________________",
        "SomeValue_____________________",
    };
// or if it should stick to one line, because it is short enough
    private string[] SomeArray =
        new[] { "SomeValue_____________________", "SomeValue_____________________", };

@belav
Copy link
Owner Author

belav commented Aug 4, 2021

Also note that prettier doesn't do this for objects or arrays

var someSemiLongName_____________ = {
  one: "one_____________________________________",
};
var someSemiLongName_____________ = [
  "one_____________________________________",
];

@belav
Copy link
Owner Author

belav commented Aug 7, 2021

As of 8/7 with the changes for #345, this can be done by printing ArrayCreationExpressionSyntax with Layout.BreakAfterOperator in RightHandSide

But that means we get this, which we don't want

    int[] array =
        new int[]
        {
            "someLongValue_____________________________________",
            "someLongValue_____________________________________"
        };

We could possibly try to determine the length of the right side and decide that way. Prettier does something like that in assignment.js.

@belav
Copy link
Owner Author

belav commented Aug 7, 2021

#269 is also related to this

@belav belav closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant