1 # Disallow arrow functions where they could be confused with comparisons (no-confusing-arrow)
3 Arrow functions (`=>`) are similar in syntax to some comparison operators (`>`, `<`, `<=`, and `>=`). This rule warns against using the arrow function syntax in places where it could be confused with a comparison operator.
5 Here's an example where the usage of `=>` could be confusing:
8 // The intent is not clear
9 var x = a => 1 ? 2 : 3;
10 // Did the author mean this
11 var x = function (a) { return 1 ? 2 : 3 };
13 var x = a <= 1 ? 2 : 3;
18 Examples of **incorrect** code for this rule:
21 /*eslint no-confusing-arrow: "error"*/
24 var x = a => 1 ? 2 : 3;
25 var x = (a) => 1 ? 2 : 3;
28 Examples of **correct** code for this rule:
31 /*eslint no-confusing-arrow: "error"*/
34 var x = a => (1 ? 2 : 3);
35 var x = (a) => (1 ? 2 : 3);
36 var x = a => { return 1 ? 2 : 3; };
37 var x = (a) => { return 1 ? 2 : 3; };
42 This rule accepts a single options argument with the following defaults:
47 "no-confusing-arrow": ["error", {"allowParens": true}]
52 `allowParens` is a boolean setting that can be `true`(default) or `false`:
54 1. `true` relaxes the rule and accepts parenthesis as a valid "confusion-preventing" syntax.
55 2. `false` warns even if the expression is wrapped in parenthesis
57 Examples of **incorrect** code for this rule with the `{"allowParens": false}` option:
60 /*eslint no-confusing-arrow: ["error", {"allowParens": false}]*/
62 var x = a => (1 ? 2 : 3);
63 var x = (a) => (1 ? 2 : 3);
68 * [no-constant-condition](no-constant-condition.md)
69 * [arrow-parens](arrow-parens.md)