ESlint在与打开相同的列上强制执行函数等的结束括号

时间:2016-03-05 20:35:18

标签: javascript coding-style eslint

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

E.g

// 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

1 个答案:

答案 0 :(得分:0)

indent rule涵盖了您正在寻找的内容,但如果您只想查看这一个案例,那就太过分了。尝试将以下内容粘贴到online demo中以查看它给出的错误:

/* 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 */评论。它使用默认设置启用缩进规则,默认设置恰好是四个空格,但规则是可配置的。