IntelliJ Scala Plugin's case class indentation is absurd

ScalaIntellij IdeaIndentationCase Class

Scala Problem Overview


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?

Scala Solutions


Solution 1 - Scala

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlyomiView Question on Stackoverflow
Solution 1 - ScalaMichoView Answer on Stackoverflow