首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

implicit-arrow-linebreak

--fix命令行上的选项可以自动修复一些被这条规则反映的问题。

一个箭头函数体可以包含一个隐式返回,而不是一个块体。对隐式返回的表达式执行一致的位置可能很有用。

规则细节

此规则旨在为包含隐式返回的箭头函数强制实施一致的位置。

另见:

  • brace-style 这会为块体的箭头函数强制实施此行为。选项此规则接受字符串选项:
  • "beside" (默认)在箭头函数体之前不允许换行。
  • "below" 在箭头函数体之前需要一个换行符。

此规则的默认代码错误代码示例"beside"

/* eslint implicit-arrow-linebreak: ["error", "beside"] */

(foo) =>
  bar;

(foo) =>
  (bar);

(foo) =>
  bar =>
    baz;

(foo) =>
(
  bar()
);

具有默认选项的此规则的正确代码示例"beside"

/* eslint implicit-arrow-linebreak: ["error", "beside"] */

(foo) => bar;

(foo) => (bar);

(foo) => bar => baz;

(foo) => (
  bar()
);

// functions with block bodies allowed with this rule using any style
// to enforce a consistent location for this case, see the rule: `brace-style`
(foo) => {
  return bar();
}

(foo) =>
{
  return bar();
}

此规则的错误代码示例包含以下"below"选项:

/* eslint implicit-arrow-linebreak: ["error", "below"] */

(foo) => bar;

(foo) => (bar);

(foo) => bar => baz;

此规则的正确代码示例包含以下"below"选项:

/* eslint implicit-arrow-linebreak: ["error", "below"] */


(foo) =>
  bar;

(foo) =>
  (bar);

(foo) =>
  bar =>
    baz;

何时不使用它

如果您不关心隐式返回的箭头函数表达式的一致位置,则不应打开此规则。

如果您正在使用该"always"选项,您也可以禁用此规则arrow-body-style,因为这将禁止在箭头函数中使用隐式返回。

版本

该规则在 ESLint 4.12.0中引入。

资源

扫码关注腾讯云开发者

领取腾讯云代金券