Skip to content

Commit

Permalink
Docs: Update no-confusing-arrow with the new default option (#11886)
Browse files Browse the repository at this point in the history
* Docs: Update examples with the new default option (refs #11503)

- Remove redundant sentence from the summary as the default for allowParens is now true.
- Update examples according to the new default.

* Docs: Fix examples

- Moved an example from correct to incorrect.
- Added a new correct example.
  • Loading branch information
zypA13510 authored and kaicataldo committed Jun 24, 2019
1 parent d07f3fa commit 566b7aa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/rules/no-confusing-arrow.md
@@ -1,6 +1,6 @@
# Disallow arrow functions where they could be confused with comparisons (no-confusing-arrow)

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. Even if the arguments of the arrow function are wrapped with parens, this rule still warns about it unless `allowParens` is set to `true`.
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:

Expand All @@ -23,7 +23,6 @@ Examples of **incorrect** code for this rule:

var x = a => 1 ? 2 : 3;
var x = (a) => 1 ? 2 : 3;
var x = (a) => (1 ? 2 : 3);
```

Examples of **correct** code for this rule:
Expand All @@ -32,6 +31,8 @@ Examples of **correct** code for this rule:
/*eslint no-confusing-arrow: "error"*/
/*eslint-env es6*/

var x = a => (1 ? 2 : 3);
var x = (a) => (1 ? 2 : 3);
var x = a => { return 1 ? 2 : 3; };
var x = (a) => { return 1 ? 2 : 3; };
```
Expand All @@ -43,7 +44,7 @@ This rule accepts a single options argument with the following defaults:
```json
{
"rules": {
"no-confusing-arrow": ["error", {"allowParens": false}]
"no-confusing-arrow": ["error", {"allowParens": true}]
}
}
```
Expand All @@ -53,10 +54,10 @@ This rule accepts a single options argument with the following defaults:
1. `true` relaxes the rule and accepts parenthesis as a valid "confusion-preventing" syntax.
2. `false` warns even if the expression is wrapped in parenthesis

Examples of **correct** code for this rule with the `{"allowParens": true}` option:
Examples of **incorrect** code for this rule with the `{"allowParens": false}` option:

```js
/*eslint no-confusing-arrow: ["error", {"allowParens": true}]*/
/*eslint no-confusing-arrow: ["error", {"allowParens": false}]*/
/*eslint-env es6*/
var x = a => (1 ? 2 : 3);
var x = (a) => (1 ? 2 : 3);
Expand Down

0 comments on commit 566b7aa

Please sign in to comment.