Keep the then () catch () format when using Prettier JS
I just started using the PrettierJS Plugin for VSCode and I am looking for a way to store my code for my service calls (and subsequent Promises).
I know you can add comments //prettier-ignore
just before the code block to preserve the code template, but since I am doing this throughout my application, I don’t want to add this comment line everywhere.
Right now, my code block looks like this:
return this.thingService.addThing(newThing)
.then(wonFunction)
.catch(lostFunction);
But when I do the Prettier format command, I get this:
return this.accessData.addRight(newRight).then(wonAddAccessRight).catch(lostAddAccessRight);
I want my code blocks to change without using comments //prettier-ignore
.
source to share
Prettier now automatically chunks three or more functions on separate lines (the current version as I write is 1.9.1), so the formatting is slightly different from what the OP asked:
return this.accessData
.addRight(newRight)
.then(wonAddAccessRight)
.catch(lostAddAccessRight);
But if you want to make it break if you only have 2 functions, there is a hack that should add a comment and Prettier will automatically break it:
return promise // force break
.then(didResolve)
.catch(didReject);
source to share