【问题标题】:how to enforce method chained on a new line with eslint如何使用 eslint 强制执行链接在新行上的方法
【发布时间】:2023-02-06 03:42:46
【问题描述】:

我要这个:

const exists = await database.collection('products_info')
      .findOne({ date: LADate })

变成这样:

const exists = await database
      .collection('products_info')
      .findOne({ date: LADate })

我的eslintrc 上有这个:

'newline-per-chained-call': ['error', { ignoreChainWithDepth: 1 }]

ignoreChainWithDepth不接受少于1个

我们怎样才能做到这一点?

【问题讨论】:

    标签: javascript eslint


    【解决方案1】:

    我正好在找同样的东西,这似乎是一个已知的错误:https://github.com/eslint/eslint/issues/12970,但是因为他们已经冻结了文体规则并且不再接受更改,所以除了编写一个插件来处理它之外别无他法。

    【讨论】: