Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martinszeltins's avatar

How to format the object operator in VSCode?

I have tried Prettier but it is too "opinionated" for my taste. I am looking for something that could format the object operators to be at the same column. (VSCode has Format on Save)

For example if I have code like this:

// PHP

$post = $post->whereName($name)
         ->whereCount(5)
         ->get();

// JS

let time = moment.now()
    .format('Y-m-d')
    .toString()

then I would like to have my editor automatically format it to this

// PHP

$post = $post->whereName($name)
             ->whereCount(5)
             ->get();
 
// JS

let time = moment.now()
                 .format('Y-m-d')
                 .toString()
0 likes
2 replies
martinszeltins's avatar

Maybe I would need to roll my own formatter extension... Looking at the docs makes my head explode.

laracoft's avatar

Short of rolling your own formatter, I don't have a good answer.

However, I do have some experience to share.

I used to be very particular, but what is a few spaces and a small misalignment?

These days, I just stick to what can be automated so that the human is not pitted against the machine. :)

So long as the -> is aligned to a factor of 4 spaces, that's good enough for me.

Please or to participate in this conversation.