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