]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/func-call-spacing.md
542ac8b8538ebac00c87ee19bc222f26e65c4c76
[pve-eslint.git] / eslint / docs / src / rules / func-call-spacing.md
1 ---
2 title: func-call-spacing
3 layout: doc
4 rule_type: layout
5 related_rules:
6 - no-spaced-func
7 ---
8
9
10
11 When calling a function, developers may insert optional whitespace between the function's name and the parentheses that invoke it. The following pairs of function calls are equivalent:
12
13 ```js
14 alert('Hello');
15 alert ('Hello');
16
17 console.log(42);
18 console.log (42);
19
20 new Date();
21 new Date ();
22 ```
23
24 ## Rule Details
25
26 This rule requires or disallows spaces between the function name and the opening parenthesis that calls it.
27
28 ## Options
29
30 This rule has a string option:
31
32 * `"never"` (default) disallows space between the function name and the opening parenthesis.
33 * `"always"` requires space between the function name and the opening parenthesis.
34
35 Further, in `"always"` mode, a second object option is available that contains a single boolean `allowNewlines` property.
36
37 ### never
38
39 Examples of **incorrect** code for this rule with the default `"never"` option:
40
41 ::: incorrect
42
43 ```js
44 /*eslint func-call-spacing: ["error", "never"]*/
45
46 fn ();
47
48 fn
49 ();
50 ```
51
52 :::
53
54 Examples of **correct** code for this rule with the default `"never"` option:
55
56 ::: correct
57
58 ```js
59 /*eslint func-call-spacing: ["error", "never"]*/
60
61 fn();
62 ```
63
64 :::
65
66 ### always
67
68 Examples of **incorrect** code for this rule with the `"always"` option:
69
70 ::: incorrect
71
72 ```js
73 /*eslint func-call-spacing: ["error", "always"]*/
74
75 fn();
76
77 fn
78 ();
79 ```
80
81 :::
82
83 Examples of **correct** code for this rule with the `"always"` option:
84
85 ::: correct
86
87 ```js
88 /*eslint func-call-spacing: ["error", "always"]*/
89
90 fn ();
91 ```
92
93 :::
94
95 #### allowNewlines
96
97 By default, `"always"` does not allow newlines. To permit newlines when in `"always"` mode, set the `allowNewlines` option to `true`. Newlines are never required.
98
99 Examples of **incorrect** code for this rule with `allowNewlines` option enabled:
100
101 ::: incorrect
102
103 ```js
104 /*eslint func-call-spacing: ["error", "always", { "allowNewlines": true }]*/
105
106 fn();
107 ```
108
109 :::
110
111 Examples of **correct** code for this rule with the `allowNewlines` option enabled:
112
113 ::: correct
114
115 ```js
116 /*eslint func-call-spacing: ["error", "always", { "allowNewlines": true }]*/
117
118 fn (); // Newlines are never required.
119
120 fn
121 ();
122 ```
123
124 :::
125
126 ## When Not To Use It
127
128 This rule can safely be turned off if your project does not care about enforcing a consistent style for spacing within function calls.
129
130 ## Compatibility
131
132 * **JSCS**: [disallowSpacesInCallExpression](https://jscs-dev.github.io/rule/disallowSpacesInCallExpression)
133 * **JSCS**: [requireSpacesInCallExpression](https://jscs-dev.github.io/rule/requireSpacesInCallExpression)