IntelliJ Idea: Align on Colon for Scala Case Class

2019-09-09 13:01发布

问题:

Is there a way to prevent Idea from reformatting multiline case class members?

Intended result
(position of the colon is not so important, but the alignment of the type annotations would be great)

case class ApiError(
  timestamp : LocalDateTime,
  status    : Int,
  code      : Option[String],
  message   : String
)

I've spent some time in the Code Styling settings for Scala and am stuck with code styling like this:

case class ApiError(
  timestamp: LocalDateTime,
  status: Int,
  code: Option[String],
  message: String
)

I am okay with cluttering the code with @formatter:off, but it would be awesome if there was a better way.

回答1:

Just like Madoc commented, those kind of formats may lead to huge changes when adding a new line. Also, while pretty in small cases, it doesn't scale, and it seems we are programming in tables...