版本

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 中引入。

資源

變更語言