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.

Multiline wrapping issues for JSX Parameters

See original GitHub issue

Versions:

  • prettier-eslint version: 12.0.0
  • prettier-eslint-cli version: 5.0.1
  • node version: 15.6.0
  • yarn version: 1.22.10

Have you followed the debugging tips?

Yes

Relevant code or config

To Reproduce:

  1. Clone this repo
  2. Run yarn
  3. Run yarn lint
  4. Notice the changes in src/Foo.tsx

Relevant files / code:

eslintrc.js:

...
rules: {
  'react/jsx-max-props-per-line': [2, { maximum: 1 }],
  'react/jsx-indent-props': [2, 2],
  'react/jsx-first-prop-new-line': [2, 'multiline'],
   'react/jsx-wrap-multilines': [
      'error',
      {
        "declaration": "parens-new-line",
        "assignment": "parens-new-line",
        "return": "parens-new-line",
        "arrow": "parens-new-line",
      },
    ],
  ...
}
...

What I did:

Created this sample component with the above listed rules:

import React from 'react';

const Bar: React.FC<any> = () => <h1>testing</h1>;

const Foo: React.FC = () => {
  const fn = (element: React.ReactElement) => {};

  fn(<Bar propOne="propOne" propTwo="propTwo" />);

  const parentFn = (): void => fn(<Bar propOne="propOne" propTwo="propTwo" />);

  const element = <Bar propOne="propOne" propTwo="propTwo" />;

  return <h1>hello world</h1>;
};

export default Foo;

What happened:

Ran the command prettier-eslint --write 'src/**/*.{js,jsx,ts,tsx}' and got the following result:

import React from 'react';

const Bar: React.FC<any> = () => <h1>testing</h1>;

const Foo: React.FC = () => {
  const fn = (element: React.ReactElement) => {};

  fn(<Bar
    propOne="propOne"
    propTwo="propTwo"
  />);

  const parentFn = (): void => fn(<Bar
    propOne="propOne"
    propTwo="propTwo"
  />);

  const element = (
<Bar
  propOne="propOne"
  propTwo="propTwo"
/>
);

  return <h1>hello world</h1>;
};

export default Foo;

Suggested solution:

Ideally it would be better if jsx elements are returned on a new line when they are a function parameter. Also, I’m not sure what is wrong with the element declaration and the lack of indenting.

Ideal solution:

import React from 'react';

const Bar: React.FC<any> = () => <h1>testing</h1>;

const Foo: React.FC = () => {
  const fn = (element: React.ReactElement) => {};

  fn(
    <Bar
      propOne="propOne"
      propTwo="propTwo"
    />,
  );

  const parentFn = (): void => fn(
    <Bar
      propOne="propOne"
      propTwo="propTwo"
    />,
  );

  const element = (
    <Bar
      propOne="propOne"
      propTwo="propTwo"
    />
  );

  return <h1>hello world</h1>;
};

export default Foo;

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kylemhcommented, Aug 15, 2022

They did make a reproduction to be fair! Just need a new one 😛

1reaction
kylemhcommented, Aug 15, 2022

@jimmy-e can you see if this is still an issue? A lot has changed since OP. It could’ve been a prettier bug, an eslint bug, or it could still be a bug on our end.

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-react/jsx-wrap-multilines.md at master
Wrapping multiline JSX in parentheses can improve readability and/or convenience. Rule Details. This rule optionally takes a second parameter in the form of...
Read more >
How to render a multi-line text string in React
It pretty much solves your all issues including line breaks and tab spaces. Cheerzz... eg: Your render will look something like below
Read more >
flex-wrap - CSS: Cascading Style Sheets - MDN Web Docs
The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, ......
Read more >
MultiLine Text / Break Text in React Native
Example of MultiLine Text / Break Text in React Native, we will see how can you break the text in multi line using...
Read more >
eslint-plugin-react
Start using eslint-plugin-react in your project by running `npm i ... jsx-wrap-multilines, Disallow missing parentheses around multiline JSX ...
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