Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Put closing curly on new line for empty blocks. #2406

Closed
Tracked by #2403
MichaReiser opened this issue Apr 13, 2022 · 4 comments · Fixed by #2540
Closed
Tracked by #2403

Put closing curly on new line for empty blocks. #2406

MichaReiser opened this issue Apr 13, 2022 · 4 comments · Fixed by #2540
Labels
A-Formatter Area: formatter good first issue Good for newcomers I-Easy Implementation: easy task, usually a good fit for new contributors

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 13, 2022

Rome's formatter collapses empty block statements on a single line whereas Prettier enforces a line break before the closing } for the following statements.

  • for..in
  • for..of
  • with
  • switch
  • switch case

Playground

Input

// Line break before closing `}`
if (true) {}
if (true) {} else {}

for (x in []) {}
for (x of []) {}

with({}) {}


switch ("test") {
}

switch ("test") {
  case "test": {}
}

test: {}

try {
} catch {
} finally {
}

// No Line breaks
class Test {}
interface X {}
type X = {};

function test() {}

for (;;) {}
while (true) {}
do {} while (true);

Prettier

// Line break before closing `}`
if (true) {
}
if (true) {
} else {
}

for (x in []) {
}
for (x of []) {
}

with ({}) {
}

switch ("test") {
}

switch ("test") {
	case "test": {
	}
}

test: {
}

try {
} catch {
} finally {
}

// No Line breaks
class Test {}
interface X {}
type X = {};

function test() {}

for (;;) {}
while (true) {}
do {} while (true);

Rome

// Line break before closing `}`
if (true) {
}
if (true) {
} else {
}

for (x in []) {}
for (x of []) {}

with({}) {}

switch ("test") {}

switch ("test") {
	case "test":
		{}
}

test: {}

try {} catch {} finally {}

// No Line breaks
class Test {}
interface X {}
type X = {};

function test() {}

for (;;) {}
while (true) {}
do {} while (true);
@MichaReiser MichaReiser added good first issue Good for newcomers A-Formatter Area: formatter labels Apr 13, 2022
@ematipico
Copy link
Contributor

ematipico commented Apr 13, 2022

I think here we should diverge and make everything look the same. If we liked prettier style (breaking before closing curly bracket), then we should apply the same behaviour to all the cases.

For example this:

// prettier
while (true) {}
with ({}) {
}

Why one case it breaks while the other it doesn't?

@MichaReiser
Copy link
Contributor Author

MichaReiser commented Apr 13, 2022

My understanding is that it doesn't break for the more traditional loops like a for(;;) or the while loops because there are valid use cases where you don't need a body

while (iter.next() != null) {}
console.log(iter.current);

@ematipico
Copy link
Contributor

Although do {} while () needs a body, I mean... I can't find a case where a do/while might have an empty body. In this case breaking might make sense? That's weird

@MichaReiser
Copy link
Contributor Author

Although do {} while () needs a body, I mean... I can't find a case where a do/while might have an empty body. In this case breaking might make sense? That's weird

But then you probably want to keep while and do while consistent.

@ematipico ematipico added the I-Easy Implementation: easy task, usually a good fit for new contributors label May 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter good first issue Good for newcomers I-Easy Implementation: easy task, usually a good fit for new contributors
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants