Improve formatting of Field with Array Initializer
// 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" };
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.
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_____________________", };
Also note that prettier doesn't do this for objects or arrays
var someSemiLongName_____________ = {
one: "one_____________________________________",
};
var someSemiLongName_____________ = [
"one_____________________________________",
];
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.
#269 is also related to this