question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react/jsx-curly-brace-presence "children" "always" complains about whitespace

See original GitHub issue
"eslint": "^4.18.2",
"eslint-plugin-react": "^7.6.1",

I have the prop: "react/jsx-curly-brace-presence":["error", { "props": "always", "children": "always" }], in my .eslintrc file because I’m trying to convert:

<div className="NameCapture_wrapper">
    <p className="NameCapture__question">
        What's your first name?
    </p>
    <NameCaptureNameInput/>
</div>

to:

<div className={`NameCapture_wrapper`}>
    <p className={`NameCapture__question`}>
        {`What's your first name?`}
    </p>
    <NameCaptureNameInput/>
</div>

but eslint is complaining about the whitespace:

  10:44  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence
  13:49  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence
  14:56  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence
  17:53  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence
  18:45  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence
  19:23  error  Need to wrap this literal in a JSX expression          react/jsx-curly-brace-presence

Below is what fixes it but I shouldn’t have to put all of my JSX on one line right?

<div className={`NameCapture_wrapper`}><p className={`NameCapture__question`}>{`What's your first name?`}</p><NameCaptureNameInput/></div>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dwiltcommented, Mar 16, 2018

@ljharb You’re correct, it would only be a string.

I wasn’t aware that you are able to have interpolations directly:

const test = `blah`;

<p className={`NameCapture__title`}>
    What's {test} your first name?
</p>

Thanks for your responses!

0reactions
ljharbcommented, Dec 5, 2019

I would expect both to warn or not warn the same.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react/jsx-curly-brace-presence "children" "always" complains ...
Actually the oneliner fixes it because it assumes that the whitespace surrounding the literal is significant, so that's correct behavior, but ...
Read more >
ESLint rule: react/jsx-curly-brace-presence
This issue is to consider enabling the rule for react/jsx-curly-brace-presence in our eslint config. This could be set up to catch two ...
Read more >
Ruby Style Guide
Use spaces around operators, after commas, colons and semicolons. Whitespace might be (mostly) irrelevant to the Ruby interpreter, but its proper use is...
Read more >
Harlowe 3.3.3 manual
This is a special version of the collapsing whitespace markup - an open curly brace { , followed by any number of =...
Read more >
JSX: The Confusing Parts - React Training
In JSX we can use curly braces to inject variables: ... Whitespace in HTML is something that either causes us problems or helps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found