5 - https://github.com/airbnb/javascript#arrows--one-arg-parens
10 Arrow functions can omit parentheses when they have exactly one parameter. In all other cases the parameter(s) must
11 be wrapped in parentheses. This rule enforces the consistent use of parentheses in arrow functions.
15 This rule enforces parentheses around arrow function parameters regardless of arity. For example:
27 Following this style will help you find arrow functions (`=>`) which may be mistakenly included in a condition
28 when a comparison such as `>=` was the intent.
42 The rule can also be configured to discourage the use of parens when they are not required:
56 This rule has a string option and an object one.
60 * `"always"` (default) requires parens around arguments in all cases.
61 * `"as-needed"` enforces no parens where they can be omitted.
63 Object properties for variants of the `"as-needed"` option:
65 * `"requireForBlockBody": true` modifies the as-needed rule in order to require parens if the function body is in an instructions block (surrounded by braces).
69 Examples of **incorrect** code for this rule with the default `"always"` option:
74 /*eslint arrow-parens: ["error", "always"]*/
82 a(foo => { if (true) {} });
87 Examples of **correct** code for this rule with the default `"always"` option:
92 /*eslint arrow-parens: ["error", "always"]*/
100 a.then((foo) => { if (true) {} });
107 One of the benefits of this option is that it prevents the incorrect use of arrow functions in conditionals:
116 console.log('bigger');
118 console.log('smaller');
120 // outputs 'bigger', not smaller as expected
123 The contents of the `if` statement is an arrow function, not a comparison.
125 If the arrow function is intentional, it should be wrapped in parens to remove ambiguity.
134 console.log('truthy value returned');
136 console.log('falsy value returned');
138 // outputs 'truthy value returned'
141 The following is another example of this behavior:
146 var a = 1, b = 2, c = 3, d = 4;
147 var f = a => b ? c: d;
151 `f` is an arrow function which takes `a` as an argument and returns the result of `b ? c: d`.
153 This should be rewritten like so:
158 var a = 1, b = 2, c = 3, d = 4;
159 var f = (a) => b ? c: d;
164 Examples of **incorrect** code for this rule with the `"as-needed"` option:
169 /*eslint arrow-parens: ["error", "as-needed"]*/
177 a((foo) => { if (true) {} });
178 const f = /** @type {number} */(a) => a + a;
179 const g = /* comment */ (a) => a + a;
180 const h = (a) /* comment */ => a + a;
185 Examples of **correct** code for this rule with the `"as-needed"` option:
190 /*eslint arrow-parens: ["error", "as-needed"]*/
198 a.then(foo => { if (true) {} });
203 const f = (/** @type {number} */a) => a + a;
204 const g = (/* comment */ a) => a + a;
205 const h = (a /* comment */) => a + a;
210 ### requireForBlockBody
212 Examples of **incorrect** code for the `{ "requireForBlockBody": true }` option:
217 /*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
232 Examples of **correct** code for the `{ "requireForBlockBody": true }` option:
237 /*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
246 a.then((foo) => { if (true) {} });
247 a((foo) => { if (true) {} });