Search code examples
javascriptprettier

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?


Solution

  • 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.