Standard: Disallow parens around single-line JSX expressions

Created on 8 Feb 2017  路  3Comments  路  Source: standard/standard

This rule restricts the use of parentheses to only where they are necessary.

Currently, this rule is set to:

    "no-extra-parens": ["error", "functions"]

I would like to investigate enabling a few more of the restrictions. Specifically, requiring the following seems desirable:

const Component = (<div><p /></div>) // avoid

// ok
const Component = (
  <div>
    <p />
  </div>
)

http://eslint.org/docs/rules/no-extra-parens

blocked enhancement

Most helpful comment

All 3 comments

I attempted to set this rule to:

    "no-extra-parens": ["error", "all", {
      "conditionalAssign": false,
      "returnAssign": false,
      "nestedBinaryExpressions": false,
      "ignoreJSX": "multi-line"
    }],

but I ran into some issues.

We really just want to add the JSX enforcement and no other new restrictions. Unfortunately, to get the JSX enforcement, we need to change the first parameter from "function" to "all". This also enables checking for extra parens around all kind of expressions, like:

obj.set(x, y, (z ? 25 : undefined))

And this is just too restrictive, IMO. I'll open an issue on ESLint about adding additional options so we can just enforce no extra parens around functions and single-line JSX statements.

The issue didn't reach consensus with the ESLint team (back in Jan 2018) so we can't fix this.

If someone feels strongly about this, I'd love it if you could please open a new issue with the ESLint team and reference the original one I opened (https://github.com/eslint/eslint/issues/8174). It is possible that the new attempt will reach consensus with the team. If you open a new issue, lmk and I will re-open this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hzhu picture hzhu  路  3Comments

davidjamesstone picture davidjamesstone  路  3Comments

Alexsey picture Alexsey  路  3Comments

caesarsol picture caesarsol  路  3Comments

BinaryBen picture BinaryBen  路  3Comments