prettier / prettier/plugin-php

Non-associative arrays formatting is not consistent with associative arrays

Open
#1,990 3 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.