防止 Prettier 将箭头函数格式化为多行

Prevent Prettier formating arrow functions to multiple lines

当我使用 vscode 在 Vue.js 中编写箭头函数时,我得到了意外的格式。

我想在 vscode 中更改自动格式化箭头功能时 Prettier 的设置。

预期:

<input type="file" @change="(event) => { files = event.target.files; }" accept=".csv" />

可接受:

<input 
    type="file"
    @change="(event) => {files = event.target.files;}"
    accept=".csv" 
/>

实际:

<input
    type="file"
    @change="
        (event) => {
            files = event.target.files;
        }
    "
    accept=".csv"
/>

我做了一些研究,发现已经有人请求此功能: https://github.com/prettier/prettier/issues/4125

对 prettier 进行了更改 (https://github.com/prettier/prettier/pull/6685),并于 2020 年在 prettier 2.0 中发布。 (https://prettier.io/blog/2020/03/21/2.0.0.html#improved-method-chain-breaking-heuristic-6685httpsgithubcomprettierprettierpull6685-by-mmkalhttpsgithubcommmkal)

但是看看你提供的例子,它显然仍然没有很好地工作:/

如果在 prettier 中有任何选项可以配置此行为,它应该在此处: https://prettier.io/docs/en/options.html 但我还没有找到任何对你的案子有帮助的东西。

在我看来你现在唯一能做的就是使用

<!-- prettier-ignore -->

..在你的台词之前。您可以在 html 中阅读更多关于 prettier ignore 的信息: https://prettier.io/docs/en/ignore.html#html