Intellij Scala class definition formatting
Asked Answered
H

1

12

How can I get Intellij format my Scala class definition like this:

sealed class Traffic(
    private[this] val javaTraffic: Traffic.JavaTraffic,
    private[this] val sanitizer: Sanitizer)
  extends Serializable with Logger {

Basically 4 indents for member declaration on each line, and 2 indents for class inheritance.

Hetaera answered 3/12, 2015 at 22:7 Comment(7)
There are a ton of options inside the Preferences menu, under Editor > Code Style > Scala. As for which ones you specifically want, I'll leave that as an exercise for the reader...Denim
@soong I've been playing around with those settings for days but still couldn't get it work exactly the way I wantHetaera
if that's the case, you may be out of luck - it may be that the scala plugin developers didn't consider that specific case to be likely. Personally, I would expect the line with the closing parentheses to be all the way to the left, since the one with the opening parens was there. It may be they expect the same thing.Denim
Ofcourse you are free to use any style you like, but the Scala Style Guide, which is the de-facto standard way to format Scala code, disagrees with what you want.Intrepid
@Intrepid Actually what I want is exactly what Scala Style Guide suggestedHetaera
You may want to check out github.com/olafurpg/scalafmt. I don't think this is supported currently, but I may be wrong, and if it isn't you can ask for this.Lurdan
We are having the same problem IntelliJ, gave up a very long while ago and using manual formatting.Blear
G
3

Starting from version 2016.2 this can be done by making the next changes from the default under Settings > Editor > Code Style > Scala:

  1. Uncheck Method declaration parameters > Align when multiline under Wrapping and Braces.
  2. Check Alternate indentation for constructor args and parameter declarations under Other and set it to 4.

Downside is that this applies not only to constructor parameters, but to normal method declarations as well, so you can't have method params aligned with opening parenthesis. But I guess we'll have to live with that.

Garber answered 20/9, 2016 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.