From 566b7aa5d61fb31cd47fe4da7820b07cf9bde1ec Mon Sep 17 00:00:00 2001 From: Yuping Zuo Date: Mon, 24 Jun 2019 23:02:46 +0800 Subject: [PATCH] Docs: Update no-confusing-arrow with the new default option (#11886) * 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. --- docs/rules/no-confusing-arrow.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-confusing-arrow.md b/docs/rules/no-confusing-arrow.md index 6947af0fb86..dccf11e9f1b 100644 --- a/docs/rules/no-confusing-arrow.md +++ b/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: @@ -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: @@ -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; }; ``` @@ -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}] } } ``` @@ -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);