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.

Add exception option in jsx-curly-newline for object literals

See original GitHub issue

Hello!

Like react/jsx-curly-spacing, it would be nice if there was an option to specify newline behavior for object literals (or other specific types of contents) in JSX.

For example, the config:

'react/jsx-curly-newline': ['error', {
  multiline: 'require',
  singleline: 'forbid',
}],

requires the following:

<Transition
  { ...transitionProps }
  config={
    {
      clamp: true,
      friction: 25,
      tension: 350,
    }
  }>
  {
    (item) => (style) => (
      <animated.div style={ style }>
        { this.props.children(item) }
      </animated.div>
    )
  }
</Transition>

However I would like to express object literals like the following example, while also forcing any other types of multiline values to have newlines:

<Transition
  { ...transitionProps }
  config={{
    clamp: true,
    friction: 25,
    tension: 350,
  }}>
  {
    (item) => (style) => (
      <animated.div style={ style }>
        { this.props.children(item) }
      </animated.div>
    )
  }
</Transition>

Right now I am using multiline: consistent to allow this, but it has the downside of allowing blocks like:

  { (item) => (style) => (
      <animated.div style={ style }>
        { this.props.children(item) }
      </animated.div>
  ) }

which is something I don’t want allowed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
UncleClaptoncommented, Jul 8, 2019

I wasn’t exactly going for consistency as much as I was trying to remove new lines that I saw as superfluous.

However now that you’ve mentioned it, the inconsistency would make things more confusing to those who don’t see it the same way. Thanks, I didn’t consider that!

I suppose this could be closed unless someone else wants this feature.

0reactions
DOOMDANYcommented, Oct 25, 2021

Do you have any news in this topic, I really would like to have those exceptions as features 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add exception option in jsx-curly-newline for object literals
Hello! Like react/jsx-curly-spacing , it would be nice if there was an option to specify newline behavior for object literals (or other specific ......
Read more >
Object initializer - JavaScript - MDN Web Docs - Mozilla
An object initializer is a comma-delimited list of zero or more pairs of property names and associated values of an object, ...
Read more >
object-property-newline - ESLint - Pluggable JavaScript Linter
Optional Exception. The rule offers one object option, allowAllPropertiesOnSameLine (a deprecated synonym is allowMultiplePropertiesPerLine ). If you set it to ...
Read more >
Named arguments in JavaScript - The If Works
It did not have the Map class it does now, and it has object literals, so we can make up ad-hoc objects without...
Read more >
Self-references in object literals / initializers - Stack Overflow
(Felix's is particularly clever, but requires creating and destroying a temporary function, adding complexity; and either leaves an extra property on the object...
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