Formatting Scala code in IntelliJ

I have Scala code like this:

def myMethod(myInt: Int, myFloat: Float, myString: String): Unit = {
//method body
I want to format it exactly like this if the line is too long:

def myMethod(
    myInt: Int,
    myFloat: Float,
    myString: String): Unit = {
    //method body
So the caveat is that each parameter has to be in it's own line and needs to indented by 4 spaces. I have tried the Settings > Editor > Code Style > Java, under the "Wrapping and Braces" tab, and selected the "Wrap always" option for "Method declaration parameters". But that doesn't indent the code correctly. Anyway to do this?

Comment actions Permalink

you can use the scalafmt plugin to format scala code, it's much better then the built in code formatter.

Comment actions Permalink

Combination of "wrap always" and "New line after '('" settings on and "align when multiline" setting off for Method declaration parameters will allow the formatting you want with built-in formatter.


Please sign in to leave a comment.