Multiline wrapping issues for JSX Parameters
See original GitHub issueVersions:
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:
- Clone this repo
- Run
yarn
- Run
yarn lint
- 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:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
They did make a reproduction to be fair! Just need a new one 😛
@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.