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

问题描述 投票:0回答:1

我正在尝试使用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中产生的。 (是的,我确实确保所有其他大括号都放在正确的位置!)

javascript node.js lint standardjs
1个回答
0
投票

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

if (err.status === 'not found') {
  cb({ statusCode: 404 })
  return
} else {   // <--- now } is on same line as {
  cb({ statusCode: 500 })
  return
}
© www.soinside.com 2019 - 2024. All rights reserved.