I'm currently programming in Scala using the IntelliJ IDEA 2021.2.1 IDE. When I'm declaring a method, I usually do it like this:
def sum(a: Int, b: Int): Int =
{
val result: Int = a b
result
}
After the equal sign, I press "Enter" -> "{" -> "Enter". That gives the codestyle from above.
But for some reason, in IntelliJ each time I press "Enter" after the equal sing, the editor automatically inserts a "Tab", giving the codestyle from bellow:
def sum(a: Int, b: Int): Int =
{
val result: Int = a b
result
}
It's as if the editor thinks I'm programming in Python or something like that, or as if I were typing "Enter" -> "Tab" -> "{" -> "Enter".
I tried search that option in the codestyle but I did not found anything related to that.
Is there any way this can be resolved or made editable? I get quite a bit annoyed by that, so it would be very helpful if you could assist me with this.
For everything else, I hope you guys are having a nice week, best regards!
CodePudding user response:
First of all, as per Scala code conventions, you should write
def sum(a: Int, b: Int): Int = {
val result: Int = a b
result
}
Or even better (as your function body can be written as an expression instead of a blcok)
def sum(a: Int, b: Int): Int = a b
Or,
def sum(a: Int, b: Int): Int =
a b
And should not do this,
def sum(a: Int, b: Int): Int =
{
val result: Int = a b
result
}
IntelliJ has automatic code styling capabilities and it contains some simple conventions for many languages.
So, in this particular case. You should fix your code style.
But, if you really really want to disable this pretty useful auto indent thing, then you can completely disable it by setting everything (tab size, indent and continuation indent) to 0 in Preferences > Editor > Code Style > Scala > Tabs and Indents
.
But, if you are doing this then you will probably want to disable all other Code Style features as well.