# no-confusing-arrow
Disallow arrow functions where they could be confused with comparisons.
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
Here’s an example where the usage of => could be confusing:
// The intent is not clear
var x = a => 1 ? 2 : 3;
// Did the author mean this
var x = function (a) { return 1 ? 2 : 3 };
// Or this
var x = a >= 1 ? 2 : 3;
# Incorrect Code Examples
var x = a => 1 ? 2 : 3;
var x = (a) => 1 ? 2 : 3;
# Config
| Name | Type | Description |
|---|---|---|
allowParens | bool | Relaxes the rule and accepts parenthesis as a valid "confusion-preventing" syntax.true by default. |
More incorrect examples
a => 1 ? 2 : 3
var x = a => 1 ? 2 : 3
var x = (a) => 1 ? 2 : 3
More correct examples
a => { return 1 ? 2 : 3; }
var x = a => { return 1 ? 2 : 3; }
var x = (a) => { return 1 ? 2 : 3; }
var x = a => (1 ? 2 : 3)