eslint-plugin-react: react/jsx-curly-spacing not working

For some reasons, I can’t get the jsx-curly-spacing rule to report errors.

After enabling it (using the default airbnb settings), I set several use case and nothing is reported.

The config has the following setting so all these cases should be reported, but they are not in my case.

'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
{ something}
{something }
{ something }

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 36 (29 by maintainers)

Most upvoted comments

I think that perhaps an option to jsx-curly-spacing that enabled checking of child curlies would be appropriate here?

ESLint rules does not apply to {something} here ? If not we should support it in this rule imho.

Fixed in #1177

Each of the bugfixes is in a separate commit indeed. Separate PRs would mean some work on the tests (they are the most time-consuming), but I could do them if this would help.

Edit: oops, the first fix is mixed in with other things, unfortunately.

That’s up to @yannickcr

There were no tests for this behavior - I’ll add some.

Btw. I think there was a small bug: when only “spacing” was set in the extended options, the following line was setting “allowMultiline” to undefined:

var multiline = context.options[1] ? context.options[1].allowMultiline : true;

Then in all the following conditions !multiline was being checked, which yielded a different result than the default true value would.

Now I’ll be checking if the property exists on the config object (using the has package, I found it being used in other rules).

Ok, so how about this:

  1. By default config is for both attributes and children.
  2. If the user wants to configure attributes or children separately, they can pass an additional option object under a “children” or an “attributes” properties.

Examples:

  1. This config never allows spaces either for attributes or children:
['warning', 'never']
  1. This config never allows spaces for attributes, but completely ignores children:
['warning', 'never', {
  children: 'ignore'
}]
  1. This config never allows spaces or newlines around attribute expressions, but requires spaces in children and allows multiline expressions in children:
['warning', 'never', {
  allowMultiline: false,
  children: ['always', { allowMultiline: true }]
}]