Reputation: 363
This is for IntelliJ 2016.2.
I'm cleaning up some code that's causing CheckStyle violations and halting our CI build, and it appears to be happening because of IntelliJ's code style rules. I can fix these manually, but there are two problems with that: the editor applies these rules indiscriminately and it's a lot to fix manually. And if anyone runs code formatting again, it sets the indentation back the way it wants.
Specifically, the indentation on multiline method signatures looks like this:
And I would like the parameters on subsequent lines to be indented 4 spaces to the right of the start of the previous line, not the opening parenthesis.
Interestingly, format-as-you-type does this correctly for me, but when I use the code formatter it reformats it as above.
I can get some of the way by going to Tabs and Indents in the preferences and setting "continuation indent" to 0:
But this rule gets applied universally, making other stuff look really bad, and it doesn't accept negative values.
I've gone to "Editor.Code Style.Java.Wrapping and Braces.Method declaration parameters" in the preferences and tried just about everything there. I have "Chop down if long", but because of the indentation rule, this makes the line longer. Nowhere do I see a way to specify where it should start the indentation from or how much it should indent the line.
This, combined with the observation that formatting for method calls exhibit expected behavior (but, aggravatingly, not constructor calls!), makes me think that this is a bug. IntelliJ's formatter appears to be hard-coded to use the continuation indent from the open parenthesis, and not the method declaration itself.
Is there anything I have missed or some viable workaround?
Upvotes: 11
Views: 2752
Reputation: 223
You can find the relevant setting in:
Settings/Preferences > Editor > Code Style > [Your Language, eg. Java]
Look for a checkbox labeled "Align when multiline", and unselect it.
(Answer taken from here.)
Upvotes: 4
Reputation: 5524
Now it must be possible to import "Code style" in intellij from checkstyle configuration.
Below is the excerpt from the official response to the feature request
- Please install CheckStyle-IDEA plugin (http://plugins.jetbrains.com/plugin/1065?pr=idea), it can be found via plug-in repository (Settings|Plugins|Browse repositories).
- Go to Settings|Editor|Code Style, choose a code style you want to import CheckStyle configuration to.
- Click Manage...|Import.., choose "CheckStyle Configuration" and select a corresponding CheckStyle configuration file. Click OK. At the end you will see a message "CheckStyle configuration settings were imported to ... scheme".
With this, Idea should be maintaining the formatting rules that checkstyle defines.
Upvotes: 0