最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Preserve then() catch() format when using Prettier JS - Stack Overflow

programmeradmin3浏览0评论

I just started using the PrettierJS Plugin for VSCode and I am looking for a way to preserve my code format of my service calls (and subsequent Promises).

I know you can add the //prettier-ignore ments just before the code block to preserve the code pattern, but since i do this all over my app, i do not want to add that ment-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 mand i get this:

    return this.accessData.addRight(newRight).then(wonAddAccessRight).catch(lostAddAccessRight);

I want a way to preserve my code blocks from changing without using the //prettier-ignore ments.

I just started using the PrettierJS Plugin for VSCode and I am looking for a way to preserve my code format of my service calls (and subsequent Promises).

I know you can add the //prettier-ignore ments just before the code block to preserve the code pattern, but since i do this all over my app, i do not want to add that ment-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 mand i get this:

    return this.accessData.addRight(newRight).then(wonAddAccessRight).catch(lostAddAccessRight);

I want a way to preserve my code blocks from changing without using the //prettier-ignore ments.

Share Improve this question asked Jul 18, 2017 at 17:06 MaylorTaylorMaylorTaylor 5,07116 gold badges51 silver badges79 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Prettier now automatically breaks a chain of 3 or more functions in separate lines (current version as I'm writing is 1.9.1), so the formatting is a bit different from what OP requested:

return this.accessData
  .addRight(newRight)
  .then(wonAddAccessRight)
  .catch(lostAddAccessRight);

But if you wanted to force it to break if you have only 2 functions, there's a hack that is to add a ment and Prettier will automatically break it:

return promise // force break
  .then(didResolve)
  .catch(didReject);
发布评论

评论列表(0)

  1. 暂无评论