]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/function-call-argument-newline.md
import eslint 7.18.0
[pve-eslint.git] / eslint / docs / rules / function-call-argument-newline.md
CommitLineData
eb39fafa
DC
1# enforce line breaks between arguments of a function call (function-call-argument-newline)
2
3A number of style guides require or disallow line breaks between arguments of a function call.
4
5## Rule Details
6
7This rule enforces line breaks between arguments of a function call.
8
9## Options
10
11This rule has a string option:
12
13* `"always"` (default) requires line breaks between arguments
14* `"never"` disallows line breaks between arguments
15* `"consistent"` requires consistent usage of line breaks between arguments
16
17
18### always
19
20Examples of **incorrect** code for this rule with the default `"always"` option:
21
22```js
23/*eslint function-call-argument-newline: ["error", "always"]*/
24
25foo("one", "two", "three");
26
27bar("one", "two", {
28 one: 1,
29 two: 2
30});
31
32baz("one", "two", (x) => {
33 console.log(x);
34});
35```
36
37Examples of **correct** code for this rule with the default `"always"` option:
38
39```js
40/*eslint function-call-argument-newline: ["error", "always"]*/
41
42foo(
43 "one",
44 "two",
45 "three"
46);
47
48bar(
49 "one",
50 "two",
51 { one: 1, two: 2 }
52);
53// or
54bar(
55 "one",
56 "two",
57 {
58 one: 1,
59 two: 2
60 }
61);
62
63baz(
64 "one",
65 "two",
66 (x) => {
67 console.log(x);
68 }
69);
70```
71
72
73### never
74
456be15e 75Examples of **incorrect** code for this rule with the `"never"` option:
eb39fafa
DC
76
77```js
78/*eslint function-call-argument-newline: ["error", "never"]*/
79
80foo(
81 "one",
82 "two", "three"
83);
84
85bar(
86 "one",
87 "two", {
88 one: 1,
89 two: 2
90 }
91);
92
93baz(
94 "one",
95 "two", (x) => {
96 console.log(x);
97 }
98);
99```
100
101Examples of **correct** code for this rule with the `"never"` option:
102
103```js
104/*eslint function-call-argument-newline: ["error", "never"]*/
105
106foo("one", "two", "three");
107// or
108foo(
109 "one", "two", "three"
110);
111
112bar("one", "two", { one: 1, two: 2 });
113// or
114bar("one", "two", {
115 one: 1,
116 two: 2
117});
118
119baz("one", "two", (x) => {
120 console.log(x);
121});
122```
123
124### consistent
125
456be15e 126Examples of **incorrect** code for this rule with the `"consistent"` option:
eb39fafa
DC
127
128```js
129/*eslint function-call-argument-newline: ["error", "consistent"]*/
130
131foo("one", "two",
132 "three");
133//or
134foo("one",
135 "two", "three");
136
137bar("one", "two",
138 { one: 1, two: 2}
139);
140
141baz("one", "two",
142 (x) => { console.log(x); }
143);
144```
145
456be15e 146Examples of **correct** code for this rule with the `"consistent"` option:
eb39fafa
DC
147
148```js
149/*eslint function-call-argument-newline: ["error", "consistent"]*/
150
151foo("one", "two", "three");
152// or
153foo(
154 "one",
155 "two",
156 "three"
157);
158
159bar("one", "two", {
160 one: 1,
161 two: 2
162});
163// or
164bar(
165 "one",
166 "two",
167 { one: 1, two: 2 }
168);
169// or
170bar(
171 "one",
172 "two",
173 {
174 one: 1,
175 two: 2
176 }
177);
178
179baz("one", "two", (x) => {
180 console.log(x);
181});
182// or
183baz(
184 "one",
185 "two",
186 (x) => {
187 console.log(x);
188 }
189);
190```
191
192
193## When Not To Use It
194
195If you don't want to enforce line breaks between arguments, don't enable this rule.
196
197## Related Rules
198
199* [function-paren-newline](function-paren-newline.md)
200* [func-call-spacing](func-call-spacing.md)
201* [object-property-newline](object-property-newline.md)
202* [array-element-newline](array-element-newline.md)