版本

implicit-arrow-linebreak

强制箭头函数体的位置

🔧 可修复

此规则报告的某些问题可以通过 --fix 命令行 选项自动修复

重要提示

此规则在 ESLint v8.53.0 中被弃用。请使用 @stylistic/eslint-plugin-js 中的相应规则

了解更多

箭头函数体可以包含作为表达式的隐式返回,而不是块体。对于强制隐式返回表达式的一致位置,这可能很有用。

规则详情

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

选项

此规则接受字符串选项

  • "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;

何时不使用

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

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

版本

此规则在 ESLint v4.12.0 中引入。

资源

更改语言