8

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
leros
  • 485
  • 6
  • 16

3 Answers3

2

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
)
aaronedmistone
  • 929
  • 10
  • 17
-2

This is behavior is changed in Prettier 2.

leros
  • 485
  • 6
  • 16
  • 1
    Can you say how it changed...? Here's the blog entry: https://prettier.io/blog/2020/03/21/2.0.0.html#improved-method-chain-breaking-heuristic-6685httpsgithubcomprettierprettierpull6685-by-mmkalhttpsgithubcommmkal – El Mac Apr 13 '20 at 13:50
-3

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

Andy Ray
  • 30,372
  • 14
  • 101
  • 138
  • That's the opposite of what I want to do. I put want to each call on one line for easier readability. – leros Dec 22 '18 at 00:17
  • oh, weird, with default settings mine formats the code on multiple lines. Maybe you've already set printWidth to something larger? – Andy Ray Dec 22 '18 at 00:41
  • I have expanded printWidth from 80 to 120, but that's independent of this problem. It seems like prettier prefers to chain function calls on one line as long as there is width available. – leros Dec 22 '18 at 03:57