Repository: eslint/eslint (JavaScript)

Issue:
no-confusing-arrow enable allowParens: true by default
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

    This template is for requesting a rule change. If you are here for another reason, please see below:

    1. To report a bug: https://eslint.org/docs/developer-guide/contributing/reporting-bugs
    2. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
    3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
    4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint

    Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->

**What rule do you want to change?**
no-confusing-arrow
**Does this change cause the rule to produce more or fewer warnings?**
fewer
**How will the change be implemented? (New option, new default behavior, etc.)?**
enable `allowParens: true` by default
**Please provide some example code that this change will affect:**

<!-- Put your code examples here -->
```js
var x = a => (1 ? 2 : 3);
```

**What does the rule currently do for this code?**
report an error.
**What will the rule do after it's changed?**
no error reported.
**Are you willing to submit a pull request to implement this change?**
yes.


Discussion:
Although this will probably result in strictly fewer warnings, I'm adding "breaking" label as users would need to change their configurations to preserve the current behavior if that's what they desire.

I'm :+1: for the change (as semver-major).
Really valuable change.
This proposal was accepted in [yesterday's TSC meeting](https://github.com/eslint/tsc-meetings/blob/137fbe2be55499cd75f28a008900803078d22dfd/notes/2019/2019-03-14.md#no-confusing-arrow-enable-allowparens-true-by-default).



Patch:
diff --git a/docs/rules/no-confusing-arrow.md b/docs/rules/no-confusing-arrow.md
index dca249f798b2..6947af0fb868 100644
--- a/docs/rules/no-confusing-arrow.md
+++ b/docs/rules/no-confusing-arrow.md
@@ -48,7 +48,7 @@ This rule accepts a single options argument with the following defaults:
 }
 ```
 
-`allowParens` is a boolean setting that can be `true` or `false`:
+`allowParens` is a boolean setting that can be `true`(default) or `false`:
 
 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
diff --git a/lib/rules/no-confusing-arrow.js b/lib/rules/no-confusing-arrow.js
index 79df9a513875..09d6e27d2160 100644
--- a/lib/rules/no-confusing-arrow.js
+++ b/lib/rules/no-confusing-arrow.js
@@ -41,7 +41,7 @@ module.exports = {
         schema: [{
             type: "object",
             properties: {
-                allowParens: { type: "boolean", default: false }
+                allowParens: { type: "boolean", default: true }
             },
             additionalProperties: false
         }],
@@ -53,8 +53,10 @@ module.exports = {
 
     create(context) {
         const config = context.options[0] || {};
+        const allowParens = config.allowParens || (config.allowParens === void 0);
         const sourceCode = context.getSourceCode();
 
+
         /**
          * Reports if an arrow function contains an ambiguous conditional.
          * @param {ASTNode} node - A node to check and report.
@@ -63,14 +65,14 @@ module.exports = {
         function checkArrowFunc(node) {
             const body = node.body;
 
-            if (isConditional(body) && !(config.allowParens && astUtils.isParenthesised(sourceCode, body))) {
+            if (isConditional(body) && !(allowParens && astUtils.isParenthesised(sourceCode, body))) {
                 context.report({
                     node,
                     messageId: "confusing",
                     fix(fixer) {
 
                         // if `allowParens` is not set to true dont bother wrapping in parens
-                        return config.allowParens && fixer.replaceText(node.body, `(${sourceCode.getText(node.body)})`);
+                        return allowParens && fixer.replaceText(node.body, `(${sourceCode.getText(node.body)})`);
                     }
                 });
             }


Test patch:
diff --git a/tests/lib/rules/no-confusing-arrow.js b/tests/lib/rules/no-confusing-arrow.js
index 7df2538a2d08..8c7efe6e287d 100644
--- a/tests/lib/rules/no-confusing-arrow.js
+++ b/tests/lib/rules/no-confusing-arrow.js
@@ -21,47 +21,55 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
 ruleTester.run("no-confusing-arrow", rule, {
     valid: [
         "a => { return 1 ? 2 : 3; }",
+        { code: "a => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
+
         "var x = a => { return 1 ? 2 : 3; }",
+        { code: "var x = a => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
+
         "var x = (a) => { return 1 ? 2 : 3; }",
+        { code: "var x = (a) => { return 1 ? 2 : 3; }", options: [{ allowParens: false }] },
+
+        "var x = a => (1 ? 2 : 3)",
         { code: "var x = a => (1 ? 2 : 3)", options: [{ allowParens: true }] }
     ],
     invalid: [
         {
             code: "a => 1 ? 2 : 3",
-            output: null,
+            output: "a => (1 ? 2 : 3)",
             errors: [{ messageId: "confusing" }]
         },
         {
-            code: "var x = a => 1 ? 2 : 3",
-            output: null,
+            code: "a => 1 ? 2 : 3",
+            output: "a => (1 ? 2 : 3)",
+            options: [{ allowParens: true }],
             errors: [{ messageId: "confusing" }]
         },
         {
-            code: "var x = (a) => 1 ? 2 : 3",
+            code: "a => 1 ? 2 : 3",
             output: null,
+            options: [{ allowParens: false }],
             errors: [{ messageId: "confusing" }]
         },
         {
-            code: "var x = a => (1 ? 2 : 3)",
-            output: null,
+            code: "var x = a => 1 ? 2 : 3",
+            output: "var x = a => (1 ? 2 : 3)",
             errors: [{ messageId: "confusing" }]
         },
         {
-            code: "a => 1 ? 2 : 3",
-            output: "a => (1 ? 2 : 3)",
+            code: "var x = a => 1 ? 2 : 3",
+            output: "var x = a => (1 ? 2 : 3)",
             options: [{ allowParens: true }],
             errors: [{ messageId: "confusing" }]
         },
         {
             code: "var x = a => 1 ? 2 : 3",
-            output: "var x = a => (1 ? 2 : 3)",
-            options: [{ allowParens: true }],
+            output: null,
+            options: [{ allowParens: false }],
             errors: [{ messageId: "confusing" }]
         },
         {
             code: "var x = (a) => 1 ? 2 : 3",
             output: "var x = (a) => (1 ? 2 : 3)",
-            options: [{ allowParens: true }],
             errors: [{ messageId: "confusing" }]
         }
     ]