prettier / prettier/plugin-php
Non-associative arrays formatting is not consistent with associative arrays
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.9k
- Forks
- 139
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported input with the Prettier PHP plugin versions listed in the issue and compare the output with the expected formatting. Start by tracing the plugin's array-formatting behavior, including the linked comment from issue 1401. Done means multiline non-associative arrays preserve their line breaks and match the shown expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100