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.
Go to Settings/Preferences | Editor | Code Style, select your programming language, and open the Wrapping and Braces tab. In the Keep when reformatting section, select the formatting rules which you want to ignore and deselect those which should be applied. Reformat your code ( Ctrl+Alt+L ).
You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings. You can also display the Reformat File dialog with ⌥⇧⌘L (macOS), or Ctrl+Alt+Shift+L (Windows/Linux).
From the main menu, select Code | Reformat Ctrl+Alt+L . If you need to add additional options before reformatting, from the main menu, select Code | Reformat File Ctrl+Alt+Shift+L and in the Reformat File dialog make the required settings.
Starting from version 2016.2 this can be done by making the next changes from the default under Settings > Editor > Code Style > Scala
:
Method declaration parameters > Align when multiline
under Wrapping and Braces
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With