简体   繁体   English

Prettier/Eslint 在括号后保持换行符

[英]Prettier/Eslint maintain newline after bracket

I've recently looked into using Prettier to help maintain a consistent code structure.我最近研究了使用Prettier来帮助维护一致的代码结构。 I found the Prettier VSCode plugin and saw that it also had an option to use Prettier-eslint .我找到了Prettier VSCode 插件,发现它也有使用Prettier-eslint的选项。 For the most part, it's great, however there is one thing that Prettier does that really drives me nuts.在大多数情况下,这很棒,但是 Prettier 做的一件事真的让我发疯。

Let's say I have this in a render function on a React component:假设我在 React 组件的render函数中有这个:

return (
    <button
        onClick={
            (e) => {console.log('Hello, world!');}
        }
    >
        Click Me
    </button>
);

This is exactly how I would like the code to be formatted, but Prettier keeps turning it into this:这正是我希望代码格式化的方式,但 Prettier 一直将其变成这样:

return (
    <button
        onClick={(e) => {
            console.log('Hello, world!');
        }}
    >
        Click Me
    </button>
);

So, it's removing the newlines after the opening bracket and before the closing bracket.因此,它删除了左括号之后和右括号之前的换行符。

Is there an option to turn this off, or some kind of plugin that I can get to do so (for Prettier and/or Eslint)?有没有关闭它的选项,或者我可以关闭的某种插件(对于 Prettier 和/或 Eslint)? I searched around but couldn't find anything that quite covered this.我四处搜索,但找不到任何可以涵盖这一点的内容。

Thanks!谢谢!

You're probably not going to like the answer to this question.你可能不会喜欢这个问题的答案。 This is the type of thing Prettier is designed to stop, custom code style.这是 Prettier 旨在阻止的类型,自定义代码样式。 It's not very customizable on purpose.它不是故意可定制的。

"By far the biggest reason for adopting Prettier is to stop all the on-going debates over styles." “到目前为止,采用 Prettier 的最大原因是停止所有关于风格的争论。”

https://prettier.io/docs/en/option-philosophy.html https://prettier.io/docs/en/option-philosophy.html

Here's a list of all the options available: https://prettier.io/docs/en/options.html以下是所有可用选项的列表: https : //prettier.io/docs/en/options.html

Prettier seems to be the industry standard now, bringing JS development Prettier 现在似乎是行业标准,带来了 JS 开发

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

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