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

🐛 Formatter breaks precedence when removing parentheses sometimes. #3089

Closed
1 task done
lgarron opened this issue Aug 20, 2022 · 2 comments
Closed
1 task done

🐛 Formatter breaks precedence when removing parentheses sometimes. #3089

lgarron opened this issue Aug 20, 2022 · 2 comments
Labels
S-To triage Status: user report of a possible bug that needs to be triaged

Comments

@lgarron
Copy link

lgarron commented Aug 20, 2022

Environment information

macOS 12.5.1
rome v0.8.0-next.ff4153b

What happened?

  1. Format the following:
const a = {};
const b = {};

const config = { useA: true };
if ("key" in (config.useA ? a : b)) {
	console.log(config);
}

The parentheses around config.useA ? a : b are removed:

// ...
if ("key" in config.useA ? a : b) {
// ...

But this has the following meaning:

if (("key" in config.useA) ? a : b) {

Fortunately, TypeScript will error if config.useA is a boolean (like in this case), although a bug will silently be introduced if it were replaced with a statement whose type is an Object.

Expected result

Rome preserves semantics while formatting. In this case, it must not remove the relevant parentheses.

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@lgarron lgarron added the S-To triage Status: user report of a possible bug that needs to be triaged label Aug 20, 2022
@MichaReiser
Copy link
Contributor

Thanks for reporting this bug.

I'll close this issue as it is fixed in the latest version (see playground) and the fix will be part of our next release (most likely fixed by #2427)

You can disable formatting of that line using // rome-ignore format: https://github.com/rome/tools/issues/3089 in the meantime.

@lgarron
Copy link
Author

lgarron commented Aug 22, 2022

the fix will be part of our next release (most likely fixed by #2427)

Thanks! Are there pre-built nightly or similar releases I can use in the meantime, or do I need to wait for a manual "proper" release?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-To triage Status: user report of a possible bug that needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants