2 title: no-confusing-arrow
6 - no-constant-condition
12 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.
14 Here's an example where the usage of `=>` could be confusing:
17 // The intent is not clear
18 var x = a => 1 ? 2 : 3;
19 // Did the author mean this
20 var x = function (a) {
24 var x = a <= 1 ? 2 : 3;
29 Examples of **incorrect** code for this rule:
34 /*eslint no-confusing-arrow: "error"*/
37 var x = a => 1 ? 2 : 3;
38 var x = (a) => 1 ? 2 : 3;
43 Examples of **correct** code for this rule:
48 /*eslint no-confusing-arrow: "error"*/
50 var x = a => (1 ? 2 : 3);
51 var x = (a) => (1 ? 2 : 3);
55 var x = a => { return 1 ? 2 : 3; };
62 This rule accepts two options argument with the following defaults:
67 "no-confusing-arrow": [
69 { "allowParens": true, "onlyOneSimpleParam": false }
75 `allowParens` is a boolean setting that can be `true`(default) or `false`:
77 1. `true` relaxes the rule and accepts parenthesis as a valid "confusion-preventing" syntax.
78 2. `false` warns even if the expression is wrapped in parenthesis
80 Examples of **incorrect** code for this rule with the `{"allowParens": false}` option:
85 /*eslint no-confusing-arrow: ["error", {"allowParens": false}]*/
87 var x = a => (1 ? 2 : 3);
88 var x = (a) => (1 ? 2 : 3);
93 `onlyOneSimpleParam` is a boolean setting that can be `true` or `false`(default):
95 1. `true` relaxes the rule and doesn't report errors if the arrow function has 0 or more than 1 parameters, or the parameter is not an identifier.
96 2. `false` warns regardless of parameters.
98 Examples of **correct** code for this rule with the `{"onlyOneSimpleParam": true}` option:
103 /*eslint no-confusing-arrow: ["error", {"onlyOneSimpleParam": true}]*/
107 (a = b) => 1 ? 2 : 3;
108 ({ a }) => 1 ? 2 : 3;