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

Make some effort to comply with style guide #1379

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tomwhoiscontrary
Copy link
Contributor

This relates to #1350, "Code base doesn't comply with JUnit's own coding style". It adds the Google Formatter to reformat the code, and Checkstyle to enforce compliance. It doesn't actually include a mass reformatting of code.

I'm not sure this is something you'd want to merge, but it might help understand the situation better.

Some observations:

  • JUnit differs from Google in that it uses four spaces from indentation. The Google Formatter can't do that. However, we can roughly restore four-space indentation with a fairly simple sed command (as given in the POM!). Also, we can suppress indentation-related violations in Checkstyle, so we won't fail the build because of our formatting.
  • By default, Checkstyle will only fail the build for 'errors', of which the codebase has none. However, the codebase has 1289 'warnings' (ignoring indentation), which still seem serious enough to want to fix.
  • Google Formatter actually doesn't fix all the problems Checkstyle finds. For example, it doesn't reorder imports. I get the impression that there is reformatting that Google Formatter can do on the command line that it can't do through its API, which is what the Maven plugin uses. After running the formatter, the codebase is down to 1113 warnings. However, after restoring indentation, it's back up to 1235 - even with indentation warnings ignored!

So, whilst you might well want Checkstyle as part of the build, i'm skeptical that the Google Formatter is actually useful.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the builds on Travis CI for jdk6 is failing. As far as I can see, this version of Checkstyle requires Java 7. If you could go on a lower version of Checkstyle, that might fix this build.
The actual problem is, if it should be possible to build Junit 4 on JDK 6? And if we don't build on JDK 6, does this imply that JUnit can no longer be used on JRE 6? And is this really still necessary, @kcooney and @marcphilipp ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should be possible to build it on JDK6. But to make sure we don't use any JDK > 5 APIs we should build using JDK 5.

Why shouldn't it be possible to use JUnit on JDK 6 if it wasn't build on JDK 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it was possible to disable Checkstyle in the JDK 6 build, would that be okay? It's not as if the source code is any different between the JDK 6 and JDK 7/8 builds. Using a JDK 6-compatible version of something in 2016 seems a bit ludicrous.

In fact, i would argue that what you really want to do is build all the classes under whatever JDK you are going to use to build the releases, and then run the tests on the various target JDKs, to more accurately simulate what happens to users. I have no idea how to get Maven and Travis to do that, though!

-->
<groupId>com.theoryinpractise</groupId>
<artifactId>googleformatter-maven-plugin</artifactId>
<version>1.0.6</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

The plugin allows one to configure AOSP style, which uses four spaces.

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.

None yet

4 participants