Closed asteele0 closed 7 months ago
Great issue report!
I'll be honest though - this isn't high on my list to fix. The code formatter support was a contribution, and the contributor then vanished; and it has several notable bugs. Honestly, I've been tempted to remove it entirely.
Nonetheless, if they ever do get high enough for me to look at, this one will be first on the list as I really appreciate the thorough report. Likewise, very open to contributions to fix this if you're keen.
I had a quick look, and it's odd. com.intellij.psi.codeStyle.CommonCodeStyleSettings
sets the simple options to false
, and our importer doesn't touch those settings:
public boolean KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false;
public boolean KEEP_SIMPLE_METHODS_IN_ONE_LINE = false;
public boolean KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE = false;
public boolean KEEP_SIMPLE_CLASSES_IN_ONE_LINE = false;
public boolean KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE = false;
When I tried importing a file locally then they stayed unset.
However, it does seem fair that we turn these off when using nl
or nlow
, as otherwise - as you say - there will be a conflict after formatting. So I shall give that a go.
I've had a go at fixing in 5.89.0 - can you please have a butchers and reopen if problems continue? As said, this isn't an area I have a lot of knowledge in, so it's entirely possible I've buggered it up or introduced new problems ... but let's hope not 🤞
It appears that no matter what the imported Checkstyle XML config is, these options are always set to true:
This can cause a mismatch between the resulting auto-formatted Java code and the Checkstyle inspection results.
Version
Reproducing
Given checkstyle.xml containing the following
When importing the configuration into Android Studio
With the following Java to format
This java code is unchanged when performing an auto-format, while Checkstyle presents an error:
Expected behavior
I would expect that when a configuration is imported as the code style, once auto-formatting has been performed, running Checkstyle against the code would not produce any warnings.
I can make a new issue, but I felt weird about making two back to back.
Spaces inside one line enum braces
With this whitespace configuration
This setting isn't enabled:
Checkstyle will error on
Expecting it to be