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

Magnus Ihse Bursie ihse at openjdk.org
Thu Mar 6 16:13:59 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.

I think a .editorconfig file is a good idea. There is an old feature request about this... _checking_ ... actually, I see you've found and reused that JBS bug. :-)

However, as Erik says, you need to be super careful not to try to enforce something that is not already enforced. I do support you in extending the scope of what rules we enforce, but as Erik says, prepare for an uphill battle.

I suggest you follow slavishly what the `.jcheck/conf` file prescribes:


[checks "whitespace"]
files=.*.cpp|.*.hpp|.*.c|.*.h|.*.java|.*.cc|.*.hh|.*.m|.*.mm|.*.S|.*.md|.*.properties|.*.gmk|.*.m4|.*.ac|Makefile
ignore-tabs=.*.gmk|Makefile


The "whitespace" check enforces, afaik, two things:
1) That there are no trailing whitespaces on a line
2) That all leading whitespaces are space (i.e., that tabs are forbidden).

The latter rule is removed by the `ignore-tabs` rule, since Makefile ascribes semantic differences to leading space and tabs (yeah, I know, it's braindead) and we need to allow both.

Note that no other file than what is matched by the regexp above are checked for whitespace. As a consequence, trailing whitespaces are galore in text files, xml files, you name it. So a rule that such whitespaces should be stripped would be highly disruptive, at least until these files are fixed and an enforcement rule is added to the jcheck file.

I don't know enough of the .editorconfig format to know if it is possible to express these rules exact, but if not, you better aim for a subset, rather than a superset.

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

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


More information about the build-dev mailing list