Non-associative arrays formatting is not consistent with associative arrays
Prettier 2.6.2
PHP Plugin 0.18.5
Input:
class Test
{
protected $array1 = [
'published', 'title', 'description', 'position', 'nid'];
protected $array2 = [
0=>'published', 'title', 'description', 'position', 'nid'];
}
Output:
class Test
{
protected $array1 = ['published', 'title', 'description', 'position', 'nid'];
protected $array2 = [
0 => 'published',
'title',
'description',
'position',
'nid',
];
}
Expected behavior:
class Test
{
protected $array1 = [
'published',
'title',
'description',
'position',
'nid',
];
protected $array2 = [
0 => 'published',
'title',
'description',
'position',
'nid',
];
}
If we break any array (associative or not) into multiple lines it should format the array as multiple lines, as it does for associative arrays. Also, this comment states that the multi-line format should be preserved.
Sorry, it is impossible, we can't rely on format sibling nodes, you can put \n in your array and it should be multi line
What do you mean by \n, @alexander-akait?
This is the "new line" representation for the char(10) on the ASCII table, and this is exactly what I'm doing.
@alexander-akait , Prettier PHP is making all our arrays one liners, we saw changes on files that were not supposed to change, like this one.
But just to make sure I understand:
Input:
class Test
{
protected $array1 = [
'published',
'title',
'description',
'position',
'nid',
];
}
Output:
class Test
{
protected $array1 = ['published', 'title', 'description', 'position', 'nid'];
}
Expected:
class Test
{
protected $array1 = [
'published',
'title',
'description',
'position',
'nid',
];
}
The idea is to keep the array style (single or multiline), and only make sure it's properly indented. Exactly as it does for associative arrays.
You are saying that this is impossible to happen because you would need to rely on format sibling nodes? And when we simple add a single => to an array you are not relying on it anymore? Because it starts working as it should, so what's the difference?