返回

ESLint 错误:箭头函数不能使用花括号(arrow-body-style)

ESLint 报错:Unexpected block statement surrounding arrow body

原因:ESLint 的 arrow-body-style 规则禁止箭头函数使用花括号包裹返回值,应直接返回。

错误:

res = () => {
  return new Promise().resolve(null);
}

正确:

res = () => new Promise().resolve(null);

如果确实需要多行语句,在 .eslintrc 中关闭该规则:"arrow-body-style": "off"


原文:

ESLint 报错:

Unexpected block statement surrounding arrow body; move the returned value immediately after the =>. [arrow-body-style]

原因: ESLint 的 arrow-body-style 规则不允许箭头函数使用花括号包裹返回值,应直接返回。

错误写法:

1  res = {
2    return new Promise().resolve(null);
3}

正确写法:

res = new Promise().resolve(null);

如果确实需要多行语句,可以关闭该规则:在 .eslintrc 中添加 "arrow-body-style": "off"

posted @ 2019-01-29 10:42  feige_hunter  阅读(4559)  评论(0)    收藏  举报