junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Code base doesn't comply with JUnit's own coding style

Open PeterWippermann opened this issue 7 years ago • 7 comments

I'd like to suggest to reformat all code under org.junit.* once to meet the defined formatting guidelines.

At the moment not all the files are formatted accordingly to that standard. This causes problems for contributors - especially in pull request. If you format the code you get a lot of extraneous diffs - just because of the reformatting - in addition to your actual changes.

I think it's not too late to do this formatting. Regarding existing PRs that tried to preserve the outdated styling: They would get extraneous diffs then of course, but if they apply the new format as well everything would be fine again. In addition, I think many of PRs are dead anyway, since many of them haven't seen any updates for months or even years.

As a result, contributing to JUnit 4 and reviewing the changes by the core team should become easier in the future.

PeterWippermann avatar Jul 24 '16 17:07 PeterWippermann

If you can find a way to guarantee that new code will use the new formatting regardless of what editor they use (for instance, with Spotless) then I'd be fine doing a reformat.

kcooney avatar Jul 24 '16 17:07 kcooney

All I can do is: import Google's code style in Eclipse. Change 2 space indentantion to 4 spaces. And run the formatting over all affected files.

PeterWippermann avatar Jul 24 '16 19:07 PeterWippermann

A non-Eclipse solution could be to use google-java-format. There's also a googleformatter-maven-plugin.

Stephan202 avatar Jul 24 '16 19:07 Stephan202

Thanks, @Stephan202

I'm going on vacation for a few days, but hopefully I can look into the Maven plugin next weekend.

kcooney avatar Jul 24 '16 23:07 kcooney

JUnit uses the Google style with the exception of different indentation.

The google-java-format tool doesn't support overriding the indentation.

If you want to enforce the style after reformatting, the tool of choice would be Checkstyle, via its Maven plugin. This supports using the Google style as a built-in custom configuration. Again, there's no way to override the indentation. You could use a modified copy of the configuration file, but that's under LGPL, so you immediately run into a license nightmare.

Would you consider dropping the indentation exception? If so, automating everything becomes fairly easy. Although you would then change every file.

tomwhoiscontrary avatar Oct 30 '16 22:10 tomwhoiscontrary

Great effort, @tomwhoiscontrary ! 👍

PeterWippermann avatar Oct 31 '16 09:10 PeterWippermann

The google-java-format tool doesn't support overriding the indentation.

I added a comment on PR #1379; seems four space indentation should be possible after all :).

Stephan202 avatar Nov 01 '16 22:11 Stephan202