]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/function-paren-newline.md
68d38fad23fd38c1a42a5a840ca3837a5a202bfa
[pve-eslint.git] / eslint / docs / src / rules / function-paren-newline.md
1 ---
2 title: function-paren-newline
3 layout: doc
4 rule_type: layout
5 ---
6
7
8
9 Many style guides require or disallow newlines inside of function parentheses.
10
11 ## Rule Details
12
13 This rule enforces consistent line breaks inside parentheses of function parameters or arguments.
14
15 ### Options
16
17 This rule has a single option, which can either be a string or an object.
18
19 * `"always"` requires line breaks inside all function parentheses.
20 * `"never"` disallows line breaks inside all function parentheses.
21 * `"multiline"` (default) requires linebreaks inside function parentheses if any of the parameters/arguments have a line break between them. Otherwise, it disallows linebreaks.
22 * `"multiline-arguments"` works like `multiline` but allows linebreaks inside function parentheses if there is only one parameter/argument.
23 * `"consistent"` requires consistent usage of linebreaks for each pair of parentheses. It reports an error if one parenthesis in the pair has a linebreak inside it and the other parenthesis does not.
24 * `{ "minItems": value }` requires linebreaks inside function parentheses if the number of parameters/arguments is at least `value`. Otherwise, it disallows linebreaks.
25
26 Example configurations:
27
28 ```json
29 {
30 "rules": {
31 "function-paren-newline": ["error", "never"]
32 }
33 }
34 ```
35
36 ```json
37 {
38 "rules": {
39 "function-paren-newline": ["error", { "minItems": 3 }]
40 }
41 }
42 ```
43
44 Examples of **incorrect** code for this rule with the `"always"` option:
45
46 ::: incorrect
47
48 ```js
49 /* eslint function-paren-newline: ["error", "always"] */
50
51 function foo(bar, baz) {}
52
53 var foo = function(bar, baz) {};
54
55 var foo = (bar, baz) => {};
56
57 foo(bar, baz);
58 ```
59
60 :::
61
62 Examples of **correct** code for this rule with the `"always"` option:
63
64 ::: correct
65
66 ```js
67 /* eslint function-paren-newline: ["error", "always"] */
68
69 function foo(
70 bar,
71 baz
72 ) {}
73
74 var foo = function(
75 bar, baz
76 ) {};
77
78 var foo = (
79 bar,
80 baz
81 ) => {};
82
83 foo(
84 bar,
85 baz
86 );
87 ```
88
89 :::
90
91 Examples of **incorrect** code for this rule with the `"never"` option:
92
93 ::: incorrect
94
95 ```js
96 /* eslint function-paren-newline: ["error", "never"] */
97
98 function foo(
99 bar,
100 baz
101 ) {}
102
103 var foo = function(
104 bar, baz
105 ) {};
106
107 var foo = (
108 bar,
109 baz
110 ) => {};
111
112 foo(
113 bar,
114 baz
115 );
116 ```
117
118 :::
119
120 Examples of **correct** code for this rule with the `"never"` option:
121
122 ::: correct
123
124 ```js
125 /* eslint function-paren-newline: ["error", "never"] */
126
127 function foo(bar, baz) {}
128
129 function foo(bar,
130 baz) {}
131
132 var foo = function(bar, baz) {};
133
134 var foo = (bar, baz) => {};
135
136 foo(bar, baz);
137
138 foo(bar,
139 baz);
140 ```
141
142 :::
143
144 Examples of **incorrect** code for this rule with the default `"multiline"` option:
145
146 ::: incorrect
147
148 ```js
149 /* eslint function-paren-newline: ["error", "multiline"] */
150
151 function foo(bar,
152 baz
153 ) {}
154
155 var foo = function(
156 bar, baz
157 ) {};
158
159 var foo = (
160 bar,
161 baz) => {};
162
163 foo(bar,
164 baz);
165
166 foo(
167 function() {
168 return baz;
169 }
170 );
171 ```
172
173 :::
174
175 Examples of **correct** code for this rule with the default `"multiline"` option:
176
177 ::: correct
178
179 ```js
180 /* eslint function-paren-newline: ["error", "multiline"] */
181
182 function foo(bar, baz) {}
183
184 var foo = function(
185 bar,
186 baz
187 ) {};
188
189 var foo = (bar, baz) => {};
190
191 foo(bar, baz, qux);
192
193 foo(
194 bar,
195 baz,
196 qux
197 );
198
199 foo(function() {
200 return baz;
201 });
202 ```
203
204 :::
205
206 Examples of **incorrect** code for this rule with the `"consistent"` option:
207
208 ::: incorrect
209
210 ```js
211 /* eslint function-paren-newline: ["error", "consistent"] */
212
213 function foo(bar,
214 baz
215 ) {}
216
217 var foo = function(bar,
218 baz
219 ) {};
220
221 var foo = (
222 bar,
223 baz) => {};
224
225 foo(
226 bar,
227 baz);
228
229 foo(
230 function() {
231 return baz;
232 });
233 ```
234
235 :::
236
237 Examples of **correct** code for this rule with the `"consistent"` option:
238
239 ::: correct
240
241 ```js
242 /* eslint function-paren-newline: ["error", "consistent"] */
243
244 function foo(bar,
245 baz) {}
246
247 var foo = function(bar, baz) {};
248
249 var foo = (
250 bar,
251 baz
252 ) => {};
253
254 foo(
255 bar, baz
256 );
257
258 foo(
259 function() {
260 return baz;
261 }
262 );
263 ```
264
265 :::
266
267 Examples of **incorrect** code for this rule with the `"multiline-arguments"` option:
268
269 ::: incorrect
270
271 ```js
272 /* eslint function-paren-newline: ["error", "multiline-arguments"] */
273
274 function foo(bar,
275 baz
276 ) {}
277
278 var foo = function(bar,
279 baz
280 ) {};
281
282 var foo = (
283 bar,
284 baz) => {};
285
286 foo(
287 bar,
288 baz);
289
290 foo(
291 bar, qux,
292 baz
293 );
294 ```
295
296 :::
297
298 Examples of **correct** code for this rule with the consistent `"multiline-arguments"` option:
299
300 ::: correct
301
302 ```js
303 /* eslint function-paren-newline: ["error", "multiline-arguments"] */
304
305 function foo(
306 bar,
307 baz
308 ) {}
309
310 var foo = function(bar, baz) {};
311
312 var foo = (
313 bar
314 ) => {};
315
316 foo(
317 function() {
318 return baz;
319 }
320 );
321 ```
322
323 :::
324
325 Examples of **incorrect** code for this rule with the `{ "minItems": 3 }` option:
326
327 ::: incorrect
328
329 ```js
330 /* eslint function-paren-newline: ["error", { "minItems": 3 }] */
331
332 function foo(
333 bar,
334 baz
335 ) {}
336
337 function foo(bar, baz, qux) {}
338
339 var foo = function(
340 bar, baz
341 ) {};
342
343 var foo = (bar,
344 baz) => {};
345
346 foo(bar,
347 baz);
348 ```
349
350 :::
351
352 Examples of **correct** code for this rule with the `{ "minItems": 3 }` option:
353
354 ::: correct
355
356 ```js
357 /* eslint function-paren-newline: ["error", { "minItems": 3 }] */
358
359 function foo(bar, baz) {}
360
361 var foo = function(
362 bar,
363 baz,
364 qux
365 ) {};
366
367 var foo = (
368 bar, baz, qux
369 ) => {};
370
371 foo(bar, baz);
372
373 foo(
374 bar, baz, qux
375 );
376 ```
377
378 :::
379
380 ## When Not To Use It
381
382 If don't want to enforce consistent linebreaks inside function parentheses, do not turn on this rule.