Enforce line breaks between arguments of a function call
Some problems reported by this rule are automatically fixable by the --fix
command line option
A number of style guides require or disallow line breaks between arguments of a function call.
This rule enforces line breaks between arguments of a function call.
This rule has a string option:
"always"
(default) requires line breaks between arguments"never"
disallows line breaks between arguments"consistent"
requires consistent usage of line breaks between argumentsExamples 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);
});
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);
}
);
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);
}
);
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);
});
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); }
);
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);
}
);
If you don’t want to enforce line breaks between arguments, don’t enable this rule.
This rule was introduced in ESLint v6.2.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/function-call-argument-newline