Possible to make Prettier allow chaining functions on new lines?

Viewed 3253

I'm writing some Firebase functions. Out of the box, it comes with EsLint with eslint-plugin-promise (which is great). It seems that eslint-plugin-promise is bringing in prettier as well. I'm not used to prettier, but I've configured a few things to my liking in a .prettierrc file, but I can't figure out this Promise chaining problem.

I'm chaining Promise calls on new lines, but prettier is forcing me to put them onto one line.

My code:

module.exports = functions.firestore
    .document('thing/{thingId}')
    .onCreate((snap, context) => {
        // stuff
    });

What Prettier is reformatting to:

module.exports = functions.firestore.document('thing/{thingId}').onCreate((snap, context) => {
    // stuff
}

Prettier's version is worse in my opinion. It's harder to read and harder to diff.

Any idea how I can turn this off? I've just disabled Prettier for now, which I don't like since I like most of what Prettier does.

3 Answers

No, I do not believe so, at least not in the way you would like. You do have the option of ignoring the next block though.

Prettier offers an escape hatch to ignore a block of code or prevent entire files from being formatted.

You can find more info on this method here

So that this

matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)

// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)

Formats to this (for example)

matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);

// prettier-ignore
matrix(
1, 0, 0,
0, 1, 0,
0, 0, 1
)

This is behavior is changed in Prettier 2.

Yes, you can increase the printWidth which will let more calls fit on one line.

Related