如何防止 Prettier 将注释移至新行

abc*_*abc 11 prettier

我有一个用 prettier 格式化的打字稿项目。我的问题是当我保存这样的代码时:

const thing = await call({ // comment
  a: 1
});
Run Code Online (Sandbox Code Playgroud)

Prettier 将注释移至新行,这不是我想要的。

const thing = await call({
  // comment
  a: 1
});
Run Code Online (Sandbox Code Playgroud)

如何在保留所有其他格式设置的同时防止这种情况发生?

编辑:我不想使用其他格式化程序或// prettier-ignore. 我需要从配置文件中完成此操作.prettierrc.json

小智 0

根据我的经验,您可以指定代码的某些区域让 prettier 在.prettierignore使用与.gitignore. 您还可以忽略其文档的这一部分中的特定注释。