简体   繁体   English

如何让 Prettier 格式化我的代码并继续缩进?

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

If we are to follow Google JavaScript Style guide, then according to this:如果我们要遵循谷歌 JavaScript 风格指南,那么根据这个:

https://google.github.io/styleguide/jsguide.html#formatting-indent 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"换行时,“第一行(每个续行)之后的每一行都从原始行缩进至少 +4”

For example,例如,

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

Google JavaScript Style suggests, we line wrap like: Google JavaScript 样式建议,我们换行如下:

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

See full example: https://github.com/saad-learns/prettier-example/blob/main/bar.js查看完整示例: https://github.com/saad-learns/prettier-example/blob/main/bar.js

But with prettier, we get但是有了 prettier,我们得到

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

See full example: https://github.com/saad-learns/prettier-example/blob/main/foo.js查看完整示例: 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.我找不到让 Prettier 遵循 Google JavaScript Style 的方法。 Is there no option?没有选择吗? or is Prettier's philosophy not compatible with Google's JavaScript Style?还是 Prettier 的哲学与 Google 的 JavaScript 风格不兼容?

So this has been asked by someone else in prettier github issue:所以这已经被其他人在更漂亮的 github 问题中问到:

https://github.com/prettier/prettier/issues/11897 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.答案是他们不会添加更多选项来支持与块缩进不同的行继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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