Code Style Help
#14945
-
I have the above Babel generated JS code that constructs an object property conditionally. If I prettify the code, it turns into below:
Its indentation looks weird. Especially last Is this intended or a bug? Or is there any way I can improve output styling for conditional properties? |
Beta Was this translation helpful? Give feedback.
Answered by
kachkaev
Jun 17, 2023
Replies: 1 comment 1 reply
-
👋 @Cmeem! If you remove new line after {, the result will be more compact: Prettier 2.8.8 --parser babel Input: const options = {
active: true,
...('day' === 'hour' ? { hour: true
} : { day: true
})
}; Output: const options = {
active: true,
...("day" === "hour" ? { hour: true } : { day: true }),
}; Overall, it’s best to not worry about such things and focus on code logic rather than code style. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Cmeem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👋 @Cmeem! If you remove new line after {, the result will be more compact:
Prettier 2.8.8
Playground link
Input:
Output:
Overall, it’s best to not worry about such things and focus on code logic rather than code style.