Skip to content
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

jsx-one-expression-per-line fix option inserts blank lines #1835

Closed
webOS101 opened this issue Jun 19, 2018 · 10 comments · Fixed by #2799
Closed

jsx-one-expression-per-line fix option inserts blank lines #1835

webOS101 opened this issue Jun 19, 2018 · 10 comments · Fixed by #2799

Comments

@webOS101
Copy link
Contributor

webOS101 commented Jun 19, 2018

eslint-plugin-react 7.9.1

If the content of a tag contains only text, extra blank lines are inserted after the text (and the indentation is not correct). If the interior is a jsx expression, the output is correct.

	<div>
		<MyComponent>a</MyComponent>
		<MyOther>{a}</MyOther>
	</div>

results in:

	<div>
		<MyComponent>
a
		
		
		
		
		</MyComponent>
		<MyOther>
			{a}
		</MyOther>
	</div>

.eslintrc:

{
	"parser": "babel-eslint",
	"plugins": [
		"react",
		"babel"
	],
	"rules": {
		"indent": [1, "tab"],
		"react/jsx-one-expression-per-line": 1
	}
}

Note: If you leave out indent it does not insert the extra spaces following the string content but does not indent any of the fixed code.

@ljharb
Copy link
Member

ljharb commented Jun 19, 2018

The indentation shouldn't need to be correct; the jsx-indent rule handles that (not the indent rule).

If you disable the indent rule, are the extra lines added?

@webOS101
Copy link
Contributor Author

No, see the comment at the bottom. The result is this:

	<div>
		<MyComponent>
a
</MyComponent>
		<MyOther>
{a}
</MyOther>
	</div>

@webOS101
Copy link
Contributor Author

Further note: using "react/jsx-indent": [1, "tab"], also results in the extra blank lines being inserted.

@CodingDive
Copy link

CodingDive commented Sep 4, 2018

I had the same issue using prettier and prettier-eslint. Every time I saved, it created several new lines between the component and text.
Adding following line to my .eslintrc file fixed it for me.
"extends": ["prettier", "prettier/react"]

Below is my package.json since I'm not sure which package messed this up.

    "eslint": "5.5.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-babel": "5.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-react": "7.11.1",
    "eslint-config-prettier": "3.0.1",
    "prettier": "1.14.2",
    "prettier-eslint": "8.8.2",
    "prettier-eslint-cli": "4.7.1"

Joel-An added a commit to Joel-An/dev-cafe-client that referenced this issue Dec 22, 2018
eslint랑 prettier쪽 문제인 거 같은데 원인을 모르겠음
jsx-eslint/eslint-plugin-react#1835
이 글의 댓글을 보고 따라했더니 고쳐짐
@renaudbardet
Copy link

I am experiencing a similar problem:

<Button
  variant="outline-primary"
  onClick={auth.login}
>
  Login
</Button>

results in ESLint giving me
'Login' must be placed on a new line (react/jsx-one-expression-per-line)

--fix gives me a similar result to @webOS101

<Button
  variant="outline-primary"
  onClick={auth.login}
>

  Login
</Button>

and ESLint still complains
'Login' must be placed on a new line (react/jsx-one-expression-per-line)

If I wrap my content in a js string it works

<Button
  variant="outline-primary"
  onClick={auth.login}
>
  {'Login'}
</Button>

@saiichihashimoto
Copy link

This is still happening.

@ljharb
Copy link
Member

ljharb commented Jul 27, 2019

@saiichihashimoto yep, that's why the issue's still open :-) it's got a "help wanted" label if you'd like to submit a PR to fix it.

@saiichihashimoto
Copy link

I got confused, I thought it was closed :-P

@dumbokitty
Copy link

Is there any update on this issue? I've met the same problem. I need to turn off this rule to pass the lint. : (

@ljharb
Copy link
Member

ljharb commented Sep 20, 2020

Looks like it's since been fixed.

@ljharb ljharb closed this as completed in 08eda7a Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

6 participants