Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow unnecessary curly braces in JSX props and children. (react/jsx-curly-brace-presence) #1366

Closed
feross opened this issue Aug 15, 2019 · 1 comment

Comments

@feross
Copy link
Member

feross commented Aug 15, 2019

This rule allows you to disallow unnecessary curly braces in JSX props and children.

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md

When { props: "never", children: "never" } is set, the following patterns will be given warnings.

<App>{'Hello world'}</App>;
<App prop={'Hello world'} attr={"foo"} />;

They can be fixed to:

<App>Hello world</App>;
<App prop="Hello world" attr="foo" />;

  • If the rule is set to get rid of unnecessary curly braces and the template literal inside a JSX expression has no expression, it will throw a warning and be fixed with quotes. For example:
<App prop={`Hello world`}>{`Hello world`}</App>;

will be warned and fixed to:

<App prop='Hello world'>Hello world</App>;

  • If the rule is set to get rid of unnecessary curly braces(JSX expression) and there are characters that need to be escaped in its JSX form, such as quote characters, forbidden JSX text characters, escaped characters and anything that looks like HTML entity names, the code will not be warned because the fix may make the code less readable.

The following patterns will not be given a warning even if 'never' is passed.

<Color text={"\u00a0"} />
<App>{"Hello \u00b7 world"}</App>;
<style type="text/css">{'.main { margin-top: 0; }'}</style>;
/**
 * there's no way to inject a whitespace into jsx without a container so this
 * will always be allowed.
 */
<App>{' '}</App>
<App>{'     '}</App>
@feross
Copy link
Member Author

feross commented Aug 15, 2019

Shipping in standard 14.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2021
suchitg8 pushed a commit to suchitg8/standard that referenced this issue Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

1 participant