Skip to content

useConsistentCurlyBraces

Diagnostic Category: lint/nursery/useConsistentCurlyBraces

Since: v1.8.2

Sources:

This rule enforces consistent use of curly braces inside JSX attributes and JSX children.

For situations where JSX expressions are unnecessary, please refer to the React doc and this page about JSX gotchas.

This rule will check for and warn about unnecessary curly braces in both JSX props and children.

<Foo>{'Hello world'}</Foo>
code-block.jsx:1:6 lint/nursery/useConsistentCurlyBraces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Should not have curly braces around expression.

> 1 │ <Foo>{‘Hello world’}</Foo>
^^^^^^^^^^^^^^^
2 │

JSX child does not need to be wrapped in curly braces.

Unsafe fix: Remove curly braces around the expression.

1 │ <Foo>{Hello·world}</Foo>
-- --
<Foo foo={'bar'} />
code-block.jsx:1:10 lint/nursery/useConsistentCurlyBraces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Should not have curly braces around expression.

> 1 │ <Foo foo={‘bar’} />
^^^^^^^
2 │

JSX attribute value does not need to be wrapped in curly braces.

Unsafe fix: Remove curly braces around the expression.

1 │ <Foo·foo={‘bar’}·/>
- -
<Foo foo=<Bar /> />
code-block.jsx:1:10 lint/nursery/useConsistentCurlyBraces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Should have curly braces around expression.

> 1 │ <Foo foo=<Bar /> />
^^^^^^^
2 │

JSX attribute value should be wrapped in curly braces. This will make the JSX attribute value more readable.

Unsafe fix: Add curly braces around the expression.

1 │ <Foo·foo={<Bar·/>}·/>
+ +
<>
<Foo>Hello world</Foo>
<Foo foo="bar" />
<Foo foo={5} />
<Foo foo={<Bar />} />
</>