Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to stop prettier from adding an extra tab for .then() {} statements after Promise.try?

So, I was wondering if it is possible to stop prettier from adding an extra tab for .then() {} statements after Promise.try or just simple return PromiseFn() .then(() => {})..

Usually, I write promise chains, that look something like this:

import Promise from "Bluebird"

Promise.try() {
  // code..
})
.then(() => {
  // more core
})
.then(() => {
 // more code
})

How prettier makes it look like:

Promise.try() {
  // code..
})
  .then(() => {
    // more core
  })
  .then(() => {
   // more code
  })

So I was wondering, if it is possible to stop prettier from adding the extra, non-needed tab before all the .then() statements?

like image 786
Rok Avatar asked Sep 06 '25 18:09

Rok


1 Answers

It seems Prettier is a very opinionated formatter...

But you may be able to flag to Prettier to ignore the next node

// prettier-ignore
Promise.try() {
  // code..
})
.then(() => {
  // more core
})
.then(() => {
 // more code
})

We dropped using Prettier in our project for this reason, it didn't allow for formatting how we wanted to. And TBH I'm not even sure the above will still work for what you want, but it seems the best option to try.

like image 161
Drew Reese Avatar answered Sep 08 '25 07:09

Drew Reese