function-call-argument-newline
在函数调用的参数之间强制换行
此规则报告的一些问题可通过 --fix 命令行 选项自动修复
This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.
许多风格指南要求或不允许函数调用的参数之间换行。
🌐 A number of style guides require or disallow line breaks between arguments of a function call.
规则详情
🌐 Rule Details
此规则强制在函数调用的参数之间换行。
🌐 This rule enforces line breaks between arguments of a function call.
选项
🌐 Options
此规则有一个字符串选项:
🌐 This rule has a string option:
"always"(默认)要求在参数之间换行"never"不允许在参数之间换行"consistent"需要在参数之间保持一致的换行使用
always
使用默认 "always" 选项时,该规则的错误代码示例:
🌐 Examples of incorrect code for this rule with the default "always" option:
/*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" 选项时,该规则的正确代码示例:
🌐 Examples of correct code for this rule with the default "always" option:
/*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" 选项时违反此规则的错误代码示例:
🌐 Examples of incorrect code for this rule with the "never" option:
/*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" 选项时,此规则的正确代码示例:
🌐 Examples of correct code for this rule with the "never" option:
/*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" 选项时违反此规则的错误代码示例:
🌐 Examples of incorrect code for this rule with the "consistent" option:
/*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" 选项时,此规则的正确代码示例:
🌐 Examples of correct code for this rule with the "consistent" option:
/*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);
}
);
何时不使用
🌐 When Not To Use It
如果你不想在参数之间强制换行,请不要启用此规则。
🌐 If you don’t want to enforce line breaks between arguments, don’t enable this rule.
相关规则
版本
此规则是在 ESLint v6.2.0 中引入。