IntelliJ Scala Plugin's case class indentation is absurd

18.1k views Asked by At

When a case class has many fields and their names are long, it is often a good idea to write each field in each line like:

case class Person (
  name: String,
  age: Int
)

This resembles C/C++ struct definition and totally readable even when the case class becomes bigger. But IntelliJ IDEA's default Scala plugin automatically changes its indentation:

case class Person (
                    name: String,
                    age: Int
                    )

which looks weird to me, but the Scala Style Guide doesn't mention anything about case class indentation.

I couldn't find anything in the IDE settings that can change this behaviour. Is there an option to make the auto-indentation work like the way I described above or disable auto-indentation for case classes?

1

There are 1 answers

6
Micho On BEST ANSWER

Try File -> Settings... -> Code Style -> Scala

There are lots of settings to customize your code formatting in there.

In the "Wrapping and Braces" tab, under "Method declaration parameters":

  • check "use normal indent for parameters"
  • uncheck "Align when multiline"

This will change it to the example you provided.

If you want it to use the indenting in "Continuation indent" under "Tabs and Indent" you have to have both of the option above unchecked.