]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/implicit-arrow-linebreak.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / implicit-arrow-linebreak.md
1 # Enforce the location of arrow function bodies with implicit returns (implicit-arrow-linebreak)
2
3 An arrow function body can contain an implicit return as an expression instead of a block body. It can be useful to enforce a consistent location for the implicitly returned expression.
4
5 ## Rule Details
6
7 This rule aims to enforce a consistent location for an arrow function containing an implicit return.
8
9 See Also:
10
11 - [`brace-style`](https://eslint.org/docs/rules/brace-style) which enforces this behavior for arrow functions with block bodies.
12
13 ### Options
14
15 This rule accepts a string option:
16
17 - `"beside"` (default) disallows a newline before an arrow function body.
18 - `"below"` requires a newline before an arrow function body.
19
20 Examples of **incorrect** code for this rule with the default `"beside"` option:
21
22 ```js
23 /* eslint implicit-arrow-linebreak: ["error", "beside"] */
24
25 (foo) =>
26 bar;
27
28 (foo) =>
29 (bar);
30
31 (foo) =>
32 bar =>
33 baz;
34
35 (foo) =>
36 (
37 bar()
38 );
39 ```
40
41 Examples of **correct** code for this rule with the default `"beside"` option:
42
43 ```js
44 /* eslint implicit-arrow-linebreak: ["error", "beside"] */
45
46 (foo) => bar;
47
48 (foo) => (bar);
49
50 (foo) => bar => baz;
51
52 (foo) => (
53 bar()
54 );
55
56 // functions with block bodies allowed with this rule using any style
57 // to enforce a consistent location for this case, see the rule: `brace-style`
58 (foo) => {
59 return bar();
60 }
61
62 (foo) =>
63 {
64 return bar();
65 }
66 ```
67
68 Examples of **incorrect** code for this rule with the `"below"` option:
69
70 ```js
71 /* eslint implicit-arrow-linebreak: ["error", "below"] */
72
73 (foo) => bar;
74
75 (foo) => (bar);
76
77 (foo) => bar => baz;
78 ```
79
80 Examples of **correct** code for this rule with the `"below"` option:
81
82 ```js
83 /* eslint implicit-arrow-linebreak: ["error", "below"] */
84
85
86 (foo) =>
87 bar;
88
89 (foo) =>
90 (bar);
91
92 (foo) =>
93 bar =>
94 baz;
95 ```
96
97 ## When Not To Use It
98
99 If you're not concerned about consistent locations of implicitly returned arrow function expressions, you should not turn on this rule.
100
101 You can also disable this rule if you are using the `"always"` option for the [`arrow-body-style`](https://eslint.org/docs/rules/arrow-body-style), since this will disable the use of implicit returns in arrow functions.