javascript - 是否可以阻止 prettier 在 Promise.try 之后为 .then() {} 语句添加额外的选项卡?

标签 javascript ecmascript-6 visual-studio-code code-formatting prettier

所以,我想知道是否有可能阻止 prettier 在 Promise.try 之后为 .then() {} 语句添加额外的选项卡,或者只是简单的 返回 PromiseFn() .then(() => {})..

通常,我会编写 promise 链,看起来像这样:

import Promise from "Bluebird"

Promise.try() {
  // code..
})
.then(() => {
  // more core
})
.then(() => {
 // more code
})

它看起来有多漂亮:

Promise.try() {
  // code..
})
  .then(() => {
    // more core
  })
  .then(() => {
   // more code
  })

所以我想知道,是否有可能阻止 prettier 在所有 .then() 语句之前添加额外的、不需要的选项卡?

最佳答案

看起来 Prettier 是一个非常 opinionated格式化程序...

但是您可以将 Prettier 标记为 ignore下一个节点

// prettier-ignore
Promise.try() {
  // code..
})
.then(() => {
  // more core
})
.then(() => {
 // more code
})

出于这个原因,我们放弃了在我们的项目中使用 Prettier,它不允许按照我们想要的方式进行格式化。老实说,我什至不确定上面的内容是否仍然适用于你想要的,但这似乎是最好的尝试选择。

关于javascript - 是否可以阻止 prettier 在 Promise.try 之后为 .then() {} 语句添加额外的选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57938387/

相关文章:

javascript - ts.createProgram 正在生成意外的输出

javascript - 获取CKEditor中选择的坐标

javascript - 使用jquery动态创建表单并提交

javascript - 使用 web worker 进行 api 调用

json - 如何说服 VS code 接受 # 作为 JSON 文件中的注释?

javascript - jQuery 和 PHP : Calculate the sum and send it back to client

javascript - 使用 Map + Rest 运算符 (JavaScript)

javascript - ES6 ReactJS 警告 : React. createElement : type should not be null, 未定义、 bool 值或数字

python - Cython 无法正常工作,无法诊断问题

regex - VS Code 多行搜索和替换 HTML/XML 标签?