简体   繁体   中英

How do I make Prettier format my code with indentation continuation?

If we are to follow Google JavaScript Style guide, then according to this:

https://google.github.io/styleguide/jsguide.html#formatting-indent

when wrapping long lines, "each line after the first (each continuation line) is indented at least +4 from the original line"

For example,

const v = 10 + 10 + 10 + 10 + ... // goes beyond line limit

Google JavaScript Style suggests, we line wrap like:

const v =
    10 + 10 + 10 + 10 + ...

See full example: https://github.com/saad-learns/prettier-example/blob/main/bar.js

But with prettier, we get

const v =
  10 + 10 + 10 + 10 + ...

See full example: https://github.com/saad-learns/prettier-example/blob/main/foo.js

I am not able to find a way to make Prettier follow Google JavaScript Style. Is there no option? or is Prettier's philosophy not compatible with Google's JavaScript Style?

So this has been asked by someone else in prettier github issue:

https://github.com/prettier/prettier/issues/11897

and the answer is they won't add any more options to support line continuation differently than block indent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM