]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/func-call-spacing.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / func-call-spacing.md
1 # require or disallow spacing between function identifiers and their invocations (func-call-spacing)
2
3 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:
4
5 ```js
6 alert('Hello');
7 alert ('Hello');
8
9 console.log(42);
10 console.log (42);
11
12 new Date();
13 new Date ();
14 ```
15
16 ## Rule Details
17
18 This rule requires or disallows spaces between the function name and the opening parenthesis that calls it.
19
20 ## options
21
22 This rule has a string option:
23
24 - `"never"` (default) disallows space between the function name and the opening parenthesis.
25 - `"always"` requires space between the function name and the opening parenthesis.
26
27 Further, in `"always"` mode, a second object option is available that contains a single boolean `allowNewlines` property.
28
29 ### never
30
31 Examples of **incorrect** code for this rule with the default `"never"` option:
32
33 ```js
34 /*eslint func-call-spacing: ["error", "never"]*/
35
36 fn ();
37
38 fn
39 ();
40 ```
41
42 Examples of **correct** code for this rule with the default `"never"` option:
43
44 ```js
45 /*eslint func-call-spacing: ["error", "never"]*/
46
47 fn();
48 ```
49
50 ### always
51
52 Examples of **incorrect** code for this rule with the `"always"` option:
53
54 ```js
55 /*eslint func-call-spacing: ["error", "always"]*/
56
57 fn();
58
59 fn
60 ();
61 ```
62
63 Examples of **correct** code for this rule with the `"always"` option:
64
65 ```js
66 /*eslint func-call-spacing: ["error", "always"]*/
67
68 fn ();
69 ```
70
71 #### allowNewlines
72
73 By default, `"always"` does not allow newlines. To permit newlines when in `"always"` mode, set the `allowNewlines` option to `true`. Newlines are never required.
74
75 Examples of **incorrect** code for this rule with `allowNewlines` option enabled:
76
77 ```js
78 /*eslint func-call-spacing: ["error", "always", { "allowNewlines": true }]*/
79
80 fn();
81 ```
82
83 Examples of **correct** code for this rule with the `allowNewlines` option enabled:
84
85 ```js
86 /*eslint func-call-spacing: ["error", "always", { "allowNewlines": true }]*/
87
88 fn (); // Newlines are never required.
89
90 fn
91 ();
92 ```
93
94 ## When Not To Use It
95
96 This rule can safely be turned off if your project does not care about enforcing a consistent style for spacing within function calls.
97
98 ## Related Rules
99
100 - [no-spaced-func](no-spaced-func.md) (deprecated)
101
102 ## Compatibility
103
104 - **JSCS**: [disallowSpacesInCallExpression](https://jscs-dev.github.io/rule/disallowSpacesInCallExpression)
105 - **JSCS**: [requireSpacesInCallExpression](https://jscs-dev.github.io/rule/requireSpacesInCallExpression)