Intellij formatter force single line if go to next line - intellij-idea

Intellij formatter has something I hate very much and can't figure out a way to disable.
when pressing ctrl+alt+l to format code all my single line ifs without parentheses goes to one line
something like
if(true)
System.out.println("yes");
goes:
if(true) System.out.println("yes");
the multiline ifs with braces keep the original formatting but i hate very much this behavior... does anyone know how to change it?

Go to Settings/Preferences | Code Style | Java | Wrapping and Braces | Keep when reformatting and enable Line breaks option.

Related

Intellij is incorrectly formatting my `.yml` file, I cannot see any errors in my style settings. how can I fix it?

Intellij keeps formatting my spotbugs.yml file incorrectly, and so breaking the github action.
I cannot figure out why it's doing this:
It was working fine last week, I haven't made any changes to the formatting config, but now, every time I change focus from the file Intellij auto-formats like this, then saves it. How can I fix it?
The thing I don't get is what it's formatting to appears to be invalid yaml, right?
YAML has a syntax that makes it incompatible with indentation that is not 2 spaces. With 4 spaces, you have:
droggel:
jug:
- sequence item: with indentation
this line: isn't aligned to four spaces
nor are further indented lines:
if you indent relative four spaces
spam:
- same: problem
without: indenting the sequence item
This makes it hard for code formatters to get it right. Proper alignment would mean:
droggel:
jug:
- three spaces after the sequence item indicator.
that's horrible, nobody does that.
spam:
- alternatively this.
nobody does this either and it breaks
- - with nested sequences
I assume some bug in IntelliJ causes the formatter to be confused because of this. Generally it would be better to just use 2 space indentation which seems far more natural due to the problems described above. That should avoid confusing the formatter.

Formatting code in PhpStorm does not work as I need it to work

How to use automatic line wrap and code formatting together in PhpStorm? My PhpStorm version is 2019.3.1
My SQL statements and my Strings look like the pic below.
What do I have to do, that the automatic wrapped lines do NOT jump to column 1 in the editor?
What do I have to do, that the automatic wrapped lines do NOT jump to column 1 in the editor?
Configure it accordingly (affects soft wrapped lines only, obviously): Settings/Preferences | Editor | General | Soft Wraps | Use original line's indent for wrapped parts

IntelliJ IDEA: is there a way to format java code in a canonical way?

I have two java source files. Both represent the same class (semantically), but they were formatted differently.
For example, one of them contains the following line:
return Boolean.valueOf(Boolean.getBoolean("abc"));
While in the second file it looks like 2 lines:
return Boolean.valueOf(
Boolean.getBoolean("abc"));
In both cases, when I apply formatting (Ctrl+Alt+L), these lines do not change.
Is it possible to format them in some canonical way: that is, to get the same code if the only difference is formatting?
Equivalently: is there any way to remove all ignorable whitespace? Such a 'dried-out' program would then be easily restored using 'Reformat code'.
You should be able to do this if you turn off "Wrapping and Braces | Keep when reformatting | Line Breaks" in the Java code style settings.
Go to File > Settings > Ediotor > Code Style > java
in tab Wrapping and Braces uncheck line breaks
Apply and make (Ctrl+Alt+L) again.

IDEA break fromat when introduce local variable

I am trying to introduce local variable and IDEA breaks my formatting, what i doing wrong?
I have tried cntrl+enter at end of line and cntrl+alt+v.
Go to settings->Editor->Code style->Java-> Wrapping and braces at the Keep when formatting section enable line breaks.

IntelliJ Align arguments to opening parenthesis?

When I split arguments onto multiple lines in IntelliJ, it puts the argument at a slight indent from the line above. For example:
ClassName.staticMethod(argument1,
argument2,
argument3);
Quick, what are the arguments above? Okay, that's easy because of the example names I chose, but how about below? Which arguments are going to staticMethod below?
ClassName.staticMethod(this.instanceMethod(argument1,
argument2),
argument3);
staticMethod is taking the results of a call to instanceMethod and argment3, but with IntelliJ's default formatting, at a glance you'd completely miss the fact that argument2 is an argument for instanceMethod, not staticMethod.
This is a freaking terrible default behavior. How can I get it to properly line arguments up, as in the modified examples below?
ClassName.staticMethod(argument1,
argument2,
argument3);
ClassName.staticMethod(this.instanceMethod(argument1,
argument2),
argument3);
Settings | Editor | Code Style | Java | Wrapping and Braces | Method call arguments | [x] Align when multiline