我试图使用StandardJS来帮助我的皮棉(也是因为我的主管让我这么做的)。它在很大程度上起了很大的作用。然而,今天我开始发现以前从未见过的错误,并报告说:
Closing curly brace does not appear on the same line as the subsequent block. (brace-style)
standard(brace-style)这是导致错误的代码:
if (err.status === 'not found') {
cb({ statusCode: 404 })
return
}
else { // THIS LINE causes the error
cb({ statusCode: 500 })
return
}为什么我会得到这个错误,以及如何防止它?
注意,我在这个项目中使用了StandardJS 8.6.0。此错误由项目编译中的标准程序生成,在安装了StandardJS扩展的VS代码IDE中生成。(是的,我真的确保我的其他花括号都在正确的位置!)
发布于 2019-11-05 07:05:57
正如错误说明的那样,您需要将结束的大括号放在与else后面的后续块相同的行上。
if (err.status === 'not found') {
cb({ statusCode: 404 })
return
} else { // <--- now } is on same line as {
cb({ statusCode: 500 })
return
}来自医生们关于标准衬里的一个例子:
将their语句与它们的大括号保持在同一行。 斯林特:支撑式 //✓确定if (条件){ // .} else { // .}/✗避免if (条件){ // .}{ // .}
发布于 2022-05-17 18:38:56
当您在打印文本eslint.中遇到以上错误时,请使用下面的格式
if (Logic1) {
//content1
} else if (Logic2) {
//content2
} else if (Logic3) {
//content3
} else {
//content4
}https://stackoverflow.com/questions/58706075
复制相似问题