版本

function-call-argument-newline

强制函数调用参数之间换行

🔧 可修复

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

重要提示

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

了解更多

许多风格指南要求或禁止在函数调用的参数之间换行。

规则详情

此规则强制函数调用的参数之间换行。

选项

此规则有一个字符串选项

  • "always" (默认) 要求参数之间换行
  • "never" 禁止参数之间换行
  • "consistent" 要求参数之间换行使用一致

always

使用默认 "always" 选项时,不正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "always"]*/

foo("one", "two", "three");

bar("one", "two", {
    one: 1,
    two: 2
});

baz("one", "two", (x) => {
    console.log(x);
});

使用默认 "always" 选项时,正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "always"]*/

foo(
    "one",
    "two",
    "three"
);

bar(
    "one",
    "two",
    { one: 1, two: 2 }
);
// or
bar(
    "one",
    "two",
    {
        one: 1,
        two: 2
    }
);

baz(
    "one",
    "two",
    (x) => {
        console.log(x);
    }
);

never

使用 "never" 选项时,不正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "never"]*/

foo(
    "one",
    "two", "three"
);

bar(
    "one",
    "two", {
        one: 1,
        two: 2
    }
);

baz(
    "one",
    "two", (x) => {
        console.log(x);
    }
);

使用 "never" 选项时,正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "never"]*/

foo("one", "two", "three");
// or
foo(
    "one", "two", "three"
);

bar("one", "two", { one: 1, two: 2 });
// or
bar("one", "two", {
    one: 1,
    two: 2
});

baz("one", "two", (x) => {
    console.log(x);
});

consistent

使用 "consistent" 选项时,不正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "consistent"]*/

foo("one", "two",
    "three");
//or
foo("one",
    "two", "three");

bar("one", "two",
    { one: 1, two: 2}
);

baz("one", "two",
    (x) => { console.log(x); }
);

使用 "consistent" 选项时,正确代码示例

在 Playground 中打开
/*eslint function-call-argument-newline: ["error", "consistent"]*/

foo("one", "two", "three");
// or
foo(
    "one",
    "two",
    "three"
);

bar("one", "two", {
    one: 1,
    two: 2
});
// or
bar(
    "one",
    "two",
    { one: 1, two: 2 }
);
// or
bar(
    "one",
    "two",
    {
        one: 1,
        two: 2
    }
);

baz("one", "two", (x) => {
    console.log(x);
});
// or
baz(
    "one",
    "two",
    (x) => {
        console.log(x);
    }
);

何时不使用

如果您不想强制参数之间换行,请不要启用此规则。

版本

此规则在 ESLint v6.2.0 中引入。

资源

更改语言