-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[react/jsx-one-expression-per-line] moves text to the beginning of line #2318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
By itself it looks weird, but if you also enable the jsx-indent rule it will fix the indentation. |
@ljharb thank you for a quick answer! "rules": {
"react/jsx-one-expression-per-line": [2, { "allow": "none" }],
"react/jsx-indent": [2, 2]
} Unfortunately it doesn't work with plain text, but with tags - ok Before running <h1>Hi people<button/></h1> After applying eslint <h1>
Hi people
<button/>
</h1> |
The However That's why we're getting: <h1>
Hi people
<button/>
</h1> instead of <h1>
Hi people
<button/>
</h1> Surely there is some room for improvements here. |
I would expect it to reindent text nodes. |
@yannickcr @ljharb so it's a good reason for making PR 😃 |
Here's one possible workaround until the issue is fixed: Before running <h1><React.Fragment>Hi people</React.Fragment><button/></h1> After applying eslint <h1>
<React.Fragment>Hi people</React.Fragment>
<button/>
</h1> You can read more about React Fragments here if you don't know about them. But basically, the final rendered DOM tree will be like this: <h1>
Hi people
<button/>
</h1> You don't have to worry about |
Bumping this thread - are there any intentions to resolve this issue? Having to write react fragments to properly support this feature seems a bit excessive, especially for devs who aren't sure why fragments are being used. |
Yes, it should be fixed somehow. A PR with failing test cases would be a great start. |
Hi @ljharb, could I try to tackle this? |
@ROSSROSALES go for it! |
Hi @ljharb, I used @lkazberova code as a testing example. rules:
Sample Code Below:
Errors found from Eslint according to rules
After applying
Is there still a need to continue to look into this issue? |
@ROSSROSALES awesome - in that case, what we need is a PR adding a passing test case, and that PR can close this issue :-) |
@ljharb I will work on it! 👍 |
Hi! I tried to use "react/jsx-one-expression-per-line" rule, but its behaviour is very strange and I don't know how can I fix it.
Sandbox : https://codesandbox.io/s/gatsby-starter-default-f7u3w , please do
npm run lint
in terminalMy config
.eslintrc.json
Before running
eslint --fix
After applying eslint
The text was updated successfully, but these errors were encountered: