prettier / prettier/plugin-php

chained method wrapping inconsistent when comments inside arguments

Open
#2,171 0 comments 0 reactions 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

When a comment is added inside the argument of secondMethod below, it changes the way that the chained methods are wrapped in a way that doesn't seem intuitive for it to affect.

@prettier/plugin-php v0.19.3
Playground link

Input:

<?php

        $builder->firstMethod()->secondMethod([
            new ClassName('c-' . $some_long_variable, [
                EXTEND::THIS, LINE::SO, IT::HASNEWLINES
            ]),
           new ClassName('c-' . $some_long_variable, [
                EXTEND::THIS, LINE::SO, IT::HASNEWLINES
            ]),
        ]);

Output:

<?php

$builder
    ->firstMethod()
    ->secondMethod([
        new ClassName("c-" . $some_long_variable, [
            EXTEND::THIS,
            LINE::SO,
            IT::HASNEWLINES,
        ]),
        new ClassName("c-" . $some_long_variable, [
            EXTEND::THIS,
            LINE::SO,
            IT::HASNEWLINES,
        ]),
    ]);

@prettier/plugin-php v0.19.3
Playground link

Input:

<?php

        $builder->firstMethod()->secondMethod([
            new ClassName('c-' . $some_long_variable, [
                EXTEND::THIS, LINE::SO, IT::HASNEWLINES
            ]),
           //  comment 
           new ClassName('c-' . $some_long_variable, [
                EXTEND::THIS, LINE::SO, IT::HASNEWLINES
            ]),
        ]);

Output:

<?php

$builder->firstMethod()->secondMethod([
    new ClassName("c-" . $some_long_variable, [
        EXTEND::THIS,
        LINE::SO,
        IT::HASNEWLINES,
    ]),
    //  comment
    new ClassName("c-" . $some_long_variable, [
        EXTEND::THIS,
        LINE::SO,
        IT::HASNEWLINES,
    ]),
]);

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 two cases from the linked playground, comparing chained-method wrapping with and without the comment inside secondMethod's argument. Trace the formatter's handling of comments and chained calls, then add a regression fixture using the supplied input and outputs. Done means the comment no longer changes the wrapping unexpectedly and the fixture passes.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.