I want to add curly braces in IntelliJ to single line statements. Lets say I have:
if(x)
print(y)
I want IntelliJ to automatically format that to:
if(x){
print(y)
}
I want to add curly braces in IntelliJ to single line statements. Lets say I have:
if(x)
print(y)
I want IntelliJ to automatically format that to:
if(x){
print(y)
}
File -> Settings -> Editor -> Code style -> Java -> Wrapping and braces -> if/while/for() statement -> Force braces -> Always
Under File > Settings > Editor > Code Style > Java on the tab "Wrapping and Braces" under "'if()' statement", set "Force braces" to "Always". And the same for "'for()' statement", "'while()' statement" and "'do ... while' statement".
When you reformat (Ctrl+Alt+L), or complete the statement using Ctrl+Shift+Enter, IntelliJ will add the braces for you.
For thoses (like me) who struggle finding this option in Rider, it is located just right here : Editor > Code Style > C# > Syntax Style > Braces
See image, then you have to select "Enforce Always".
© 2022 - 2025 — McMap. All rights reserved.