ESlint 在与开头相同的列上强制使用函数等的右括号

ESlint enforce closing brackets for functions etc on same column as opening

本文关键字:函数 开头 ESlint      更新时间:2023-09-26

如何在出现左括号的同一列上对函数等强制执行右括号/括号

例如

// throws error
app.get('/', function (req, response) {
 }); // bracket/parentheses is *not on same* column as opening

// this is valid
app.get('/', function (req, response) {
}); // bracket/parentheses is on *same* column as opening

缩进规则涵盖了您要查找的内容,但如果这一种情况是您想要检查的全部内容,那就太过分了。尝试将以下内容粘贴到在线演示中,以查看它给出的错误:

/* eslint indent: 2 */
// throws error
app.get('/', function (req, response) {
 }); // bracket/parentheses is *not on same* column as opening

// this is valid
app.get('/', function (req, response) {
}); // bracket/parentheses is on *same* column as opening

重要的部分是开头的/* eslint indent: 2 */评论。它使用默认设置启用缩进规则,这些设置恰好是四个空格,尽管该规则是可配置的。