[JSX] - should prettier keep blank lines after opening and before closing tags?
See original GitHub issuePrettier removes blank lines at the start and at the end of the blocks:
In
const func = () => {
const foo = 1
const bar = 2
const baz = 3
}
if (true) {
const foo = 1
const bar = 2
const baz = 3
}
Out
const func = () => {
const foo = 1;
const bar = 2;
const baz = 3;
};
if (true) {
const foo = 1;
const bar = 2;
const baz = 3;
}
But keeps extra one line in case of JSX tags:
In
const comp = (
<div>
<div>
foo
</div>
<div>
bar
</div>
<div>
baz
</div>
</div>
)
Out
const comp = (
<div>
<div>
foo
</div>
<div>
bar
</div>
<div>
baz
</div>
</div>
);
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Rationale - Prettier
The approach that Prettier takes is to preserve empty lines the way they were in the original source code. There are two additional...
Read more >Prettier not formatting empty line properly - Stack Overflow
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 >no-multiple-empty-lines - ESLint - Pluggable JavaScript Linter
This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines...
Read more >Prettier 2.0 “2020” · Prettier 中文网
Prettier had been adding newlines for every HTML template string, which could lead to unexpected whitespace in rendered HTML.
Read more >VS Code - You don't need a formatting extension (Prettier and ...
You can use the built-in formatters for a number of languages. ... newlineBetweenRules - Separate rulesets by a blank line. css.format.
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 Free
Top 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
Let’s summon @jlongster to make the final decision on this 😃
It’s also worth mentioning that the general situation of
[several block-starts in a row] [several sibling blocks] [several block-ends in a row]
is less likely to occur in js code than in jsx. So enforcing the no-opening-newlines and no-closing-newlines rule makes more sense in js than in jsx.
eg; I would prefer this code:
over this code:
but that happens so infrequently in JS (fortunately) that it’s not worth optimizing for. But it does happen pretty frequently in JSX.
Just my 2c (I’ve already committed the change to adopt this issue’s proposal)