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.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

15reactions
CodingDivecommented, Sep 7, 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"
4reactions
webOS101commented, Jun 19, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsx-one-expression-per-line fix option inserts blank lines #1835
If the content of a tag contains only text, extra blank lines are inserted after the text (and the indentation is not correct)....
Read more >
Get the free jsx-one-expression-per-line fix option inserts blank lines
Get the free jsx-one-expression-per-line fix option inserts blank lines ... Fill Online. Quickly fill your document. Save, download, print and share.
Read more >
Best practice when adding whitespace in JSX - Stack Overflow
To add a space via JSX, simply put a string consisting of one space character in a JSX expression. The simplest way to...
Read more >
Rationale - Prettier
Prettier collapses multiple blank lines into a single blank line. Empty lines at the start and end of blocks (and whole files) are...
Read more >
JS.REACT.JSX.ONE.EXPRESSION.PER.LINE
This option limits every line in JSX to one expression each. This rule is automatically fixable using the --fix flag on the command...
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