Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure code style for Scala in IntelliJ IDEA

IntelliJ formats my test code like this:

  test("a configuration without classpath to analyze is not valid") {
                                                                  Configuration(
                                                                    None,
                                                                    Seq(),
                                                                    Seq(),
                                                                    Map(),
                                                                        Some(PrintConfiguration(print = Always("output")))
                                                                  ) should not be ('valid)
                                                                }

I hope we all agree that this is a rather stupid way to do this.

How can I configure IntelliJ in so that it moves Configuration and everything belonging to it over to the left, two spaces indented relative to test?

To clarify: most of the code gets indented properly, just code blocks in curly braces, that are parameters get aligne relative to the opening curly brace, not relative to the beginning of the function call.

like image 453
Jens Schauder Avatar asked Apr 02 '15 05:04

Jens Schauder


People also ask

How do I add code style to IntelliJ?

Apply a predefined code stylePress Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. To configure a scheme for new projects, go to File | New Projects Setup | Settings/Preferences for New Projects | Editor | Code Style. Select the language for which you want to configure the code style.

How do I fix code style in IntelliJ?

In the editor, select a code fragment you want to reformat. Before reformatting, you can take a look at the code style settings that are applied to the selected code: press Alt+Enter and click Adjust code style settings. From the main menu, select Code | Reformat Code or press Ctrl+Alt+L .

How can I beautify code in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.

What is IntelliJ code style?

Code style scheme settings are automatically applied every time IntelliJ IDEA generates, refactors, or reformats your code. The IDE comes with two pre-defined schemes: the Project scheme and the Default scheme. In the Project scheme, the settings that you configure apply only to your current project.


1 Answers

How about Settings -> CodeStyle -> Scala:

enter image description here

Also make sure to remove the "align when multiline settings" or set the "Do not align block expression parameters" on the Wrapping and Braces tab.

like image 93
dk14 Avatar answered Oct 21 '22 16:10

dk14