RFR: 8311227: Add .editorconfig so IDEs would pick up the common settings automatically: indent, trim trailing whitespace

David Linus Briemann duke at openjdk.org
Mon Mar 10 09:03:40 UTC 2025


On Wed, 19 Feb 2025 12:27:58 GMT, David Linus Briemann <duke at openjdk.org> wrote:

> Add an .editorconfig to define indentation, trim trailing whitespace and open curly brace position for C++ and Java.
> This allows various editors to easily infer basics of the coding style.

Thank you both for your input. I added an editorconfig locally because because I have other defaults for C++, so my editor can switch to "JDK mode" when working in this project. I put the file into my local .gitignore but thought this might make sense to have it in the repo. Then I found the JBS issue and opened the PR to get the ball rolling.

> The `indent_brace_style` isn't listed as an official property of EditorConfig

You are right. It seems to be only some extension proposal. I removed it.

> What does `indent_style = tab` actually mean for makefiles? [...]

I agree, this seems unnecessary. I also removed this part.


As for the coding style (indentation), I followed the official style guides to define this. 

For C++ we have <https://github.com/openjdk/jdk/blob/master/doc/hotspot-style.md#whitespace>

which states:
> Indentation levels are two columns.

and

> Tabs are not allowed in code.

so the given config seemed a logical result.

For Java I referred to this <https://www.oracle.com/java/technologies/javase/codeconventions-indentation.html> which states:

> Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).

To be honest, this is a bit unclear to me. So maybe I got it wrong in defining 4 spaces here.



I guess the question is: are these guidelines obligatory and if so why can we not define this in an editorconfig?


EDIT:
I would not see much sense in only adding the `trim_trailing_whitespace` option. Then vital settings are missing and I have a file that conflicts with my local one :)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23693#issuecomment-2709852460


More information about the build-dev mailing list