Skip to content

Enforce curly braces for JSX props with React elements #3184

@neutraali

Description

@neutraali

Hey there! I've dug around for a few days now, whenever I had a spare moment to dedicate to it, but I couldn't find a rule that would enforce curly braces for React elements as JSX props. I've tried using a combo of jsx-no-literals (which was mostly for strings) and curly-brace-presence but it didn't work (using --fix) for React element props. Here's some examples using jsx-curly-brace-presence with [1, "always"] as the value:

Initial input: <ExampleComponent text='Hello' component=<p>World!</p> />

Expected output: <ExampleComponent text={'Hello'} component={<p>World!</p>} />

Actual output: <ExampleComponent text={'Hello'} component=<p>World!</p> />

... The problem with not enclosing the JSX element props with curly braces is that it breaks certain parsers, for example the one esbuild happens to be using.

Libraries:

"babel-eslint": "10.1.0"
"eslint": "6.8.0"
"eslint-config-prettier": "6.10.0"
"eslint-config-recommended": "4.1.0"
"eslint-plugin-flowtype": "4.6.0"
"eslint-plugin-prettier": "3.1.2"
"eslint-plugin-react": "7.18.3"

Environment:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions