简体   繁体   English

如何使用 Prettier 在代码块之间添加多行?

[英]How to add multiple lines between code blocks with Prettier?

I started using Prettier, but discovered that it doesn't have an option to control the number of blank lines between code blocks, and defaults to one.我开始使用 Prettier,但发现它没有控制代码块之间空行数的选项,默认为 1。

I want 2 blank lines:我想要 2 个空行:

const bar = 10;
// blank 1
// blank 2
function foo() {
  hello();
  world();
}
// blank 1
// blank 2
foo();
// blank 1
// blank 2
export foo;

But it defaults to 1 blank line:但它默认为 1 个空行:

const bar = 10;
// blank 1
function foo() {
  hello();
  world();
}
// blank 1
foo();
// blank 1
export foo;

How can I achieve this with Prettier?我如何使用 Prettier 实现这一目标?

(Or perhaps there is another way to do this. I was surprised how few configurable options are available in Prettier. I was hoping for more control.) (或者也许有另一种方法可以做到这一点。我很惊讶 Prettier 中可用的可配置选项很少。我希望有更多的控制。)

How to add multiple lines between code blocks with Prettier?如何使用 Prettier 在代码块之间添加多行?

You can't.你不能。

I was surprised how few configurable options are available in Prettier.我很惊讶 Prettier 中可用的可配置选项如此之少。 I was hoping for more control我希望有更多的控制

That is very intentional.这是非常有意的。 Prettier is an opinionated code formatter. One of those opinions is 1 line is enough 🌹其中一个意见是1行就足够了🌹

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

相关问题 如何防止 Prettier 将测试代码从 1 行变为多行 - How to prevent Prettier from breaking test code from 1 line to multiple lines 如何配置更漂亮,以便在 VSCODE 中将 jsx 属性格式化为多行? - How to configure prettier such that it formats jsx attributes in multiple lines in VSCODE? VS Code 上的 Prettier 会在保存时展开我的代码块。 如何预防? - Prettier on VS Code unfolds my code blocks on save . How to prevetn sthis? 如何在游戏中添加多个方块 - How to add multiple blocks to game 更漂亮的不纠正某些代码行的 printWidth - prettier not correcting for printWidth for certain lines of code 在 VS 代码中更漂亮,将属性拆分为多行(打印宽度不适用于 html)Angular - Prettier in VS code splitting attributes onto multiple lines ( print width doesn't work for html ) Angular Javascript:如何在代码块之间传输变量? - Javascript: How to transfer variables between code blocks? 如何通过使用Eslint + Prettier删除空行来区分JSON代码格式 - How to discriminate JSON code formatting by removing empty lines using Eslint + Prettier 你如何停止更漂亮或美化将 JS 对象分成多行? - How do you stop prettier or beautify breaking JS objects onto multiple lines? 更漂亮:在 function 括号和参数之间添加空格 - Prettier: add space between function parenthesis and parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM