Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid code that would reformat poorly #389

Conversation

findepi
Copy link
Contributor

@findepi findepi commented Jan 10, 2024

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 findepi force-pushed the findepi/forbid-code-that-would-reformat-poorly-21f0d5 branch 3 times, most recently from 943e840 to a95f1d1 Compare January 10, 2024 15:01
Copy link
Member

@martint martint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a readable and concise way to format the code, so we shouldn't prevent it:

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

I'm not experiencing the issues with whitespace re-formatting that you mention, so I would suggest diagnosing that first.

@findepi findepi force-pushed the findepi/forbid-code-that-would-reformat-poorly-21f0d5 branch from a95f1d1 to ebb63fe Compare January 10, 2024 16:01
@findepi
Copy link
Contributor Author

findepi commented Jan 10, 2024

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

@martint
Copy link
Member

martint commented Jan 10, 2024

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
Copy link
Member

martint commented Jan 10, 2024

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

@findepi
Copy link
Contributor Author

findepi commented Jan 10, 2024

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

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 findepi force-pushed the findepi/forbid-code-that-would-reformat-poorly-21f0d5 branch from ebb63fe to 3f85bb6 Compare January 10, 2024 16:23
@findepi
Copy link
Contributor Author

findepi commented Jan 10, 2024

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
Copy link
Member

martint commented Jan 10, 2024

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

@findepi
Copy link
Contributor Author

findepi commented Jan 10, 2024

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

this indeed helps!

airlift/codestyle#15

@findepi findepi closed this Jan 10, 2024
@findepi findepi deleted the findepi/forbid-code-that-would-reformat-poorly-21f0d5 branch January 10, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants