最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用StandardJS,仅在'else'语句的错误行上出现花括号错误

网站源码admin16浏览0评论

使用StandardJS,仅在'else'语句的错误行上出现花括号错误

使用StandardJS,仅在'else'语句的错误行上出现花括号错误

我正在尝试使用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。该错误是由Standard在项目编译中以及在安装了StandardJS扩展的VS Code IDE中产生的。 (是的,我确实确保所有其他大括号都放在正确的位置!)

回答如下:

就像错误说的那样,您需要将右大括号放在与else之后的后续块相同的行上:

if (err.status === 'not found') {
  cb({ statusCode: 404 })
  return
} else {   // <--- now } is on same line as {
  cb({ statusCode: 500 })
  return
}
发布评论

评论列表(0)

  1. 暂无评论