airlift / airbase

Base POM for Airlift
Apache License 2.0
48 stars 87 forks source link

Forbid code that would reformat poorly #389

Closed findepi closed 9 months ago

findepi commented 9 months ago

Current checkstyle rules somehow allow things like

void run() { throw new UnsupportedOperationException(); }

Runnable r = () -> { throw new RuntimeException(); }

Runnable asRunnable()
{ a_field++; }

void update()
{ throw new RuntimeException(); }

however, when such code is then auto-formatted by IntelliJ with Airbase codestyle, some whitespace is removed, resulting in a code that violates checkstyle rules. This state is undesired: sometimes a person working on a class file may need to undo auto-formatting so pass checkstyle checks.

The new rules aim to reduce such situation by recognizing some common would-format-incorrectly patterns.

findepi commented 9 months ago

I experience this in all recent Intellij versions. How do i go about diagnosing that?

martint commented 9 months ago

Look at the codestyle options and try to see which one is causing that? Maybe they introduced a new option that's defaulting to some other setting...

martint commented 9 months ago

FWIW, I'm running IntelliJ 2023.3.2 and I don't experience the problem there.

findepi commented 9 months ago

i already tried that, but didn't find an option for this. i am still at 2023.2.x (because 2023.3.2 did not appear to work stably for me), but will try 2023.3.2 (ultimate) too

findepi commented 9 months ago

switching to 2023.3.2 and importing https://github.com/airlift/codestyle/blob/master/IntelliJIdea2019/Airlift.xml anew did not make intellij retain code as is upon auto-formatting

Runnable r = () -> { throw new RuntimeException(); }

is there any additional configuration i should set to make it work?

martint commented 9 months ago

Do you have Spaces->Within->Code Braces turned on?

findepi commented 9 months ago

Do you have Spaces->Within->Code Braces turned on?

this indeed helps!

https://github.com/airlift/codestyle/pull/15