gpt4 book ai didi

javascript - 在 eslint 中启用 space-before-blocks 时,仅强制使用一个空格而不是多个空格

转载 作者:行者123 更新时间:2023-11-28 04:36:49 28 4
gpt4 key购买 nike

如何正确配置规则以强制在带大括号的代码块之前仅包含一个空格而不是多个空格或制表符?

到目前为止我一直在使用:

/* globals isCorrect, aValue callback */
/*eslint space-before-blocks: "error"*/

if (isCorrect) { // That should be incorrect, more than one space
callback('correct');
} else if(aValue == 5) { // That should be correct, only one space
callback('aValue');
} else { // That is also incorrect, tabs!
callback('incorrect');
}

最佳答案

您可以使用no-multi-spaces为了那个原因!将 /* no-multi-spaces: "error"*/ 添加到您的示例中,并在 demo 中尝试它:

/* globals isCorrect, aValue callback */
/* eslint space-before-blocks: "error" */
/* eslint no-multi-spaces: "error" */

if (isCorrect) { // That should be incorrect, more than one space
callback('correct');
} else if(aValue == 5) { // That should be correct, only one space
callback('aValue');
} else { // That is also incorrect, tabs!
callback('incorrect');
}

这应该会给你你想要的错误:

5:17 - Multiple spaces found before '{'. (no-multi-spaces)
9:13 - Multiple spaces found before '{'. (no-multi-spaces)

关于javascript - 在 eslint 中启用 space-before-blocks 时,仅强制使用一个空格而不是多个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44131569/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com