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

Add checkstyle #3229

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Conversation

MysterAitch
Copy link
Member

This PR adds checkstyle to the build, to help minimise the amount of churn of e.g. import statements. The config is adapted from the default Sun style, with changes made to match our current codebase.

  • Where I have been able to get a "quick win" to adopt a consistent style then that is included within this PR (e.g. adding comments to public static final fields and making them UPPER_CASE, tweaking whitespace around operators, tweaking imports).

  • Where it's not feasible to apply the rule yet or the rule is in default sun style but might not be relevant / applicable to our project, I have added it to the suppressions (exceptions) file. Preferably these suppressions are limited to the relevant files, but there are some rules added as a global supression.

It's a TODO for future PRs to investigate whether the remaining "suppressed" checks are applicable or if they definitely don't apply / we don't care.

For example, there are lots of warnings about magic numbers where we use 31 in the hashCode() methods - maybe one day we will convert them all to use Objects.hashCode(...) but perhaps not right now and certainly not within this PR. Ditto for ensuring there is javadoc for all public methods/classes - this is something we probably should be doing, but there are too many places we don't have this that it's a substantial piece of work (assuming we want to do it - again a separate discussion / PR 👍 ).

@MysterAitch
Copy link
Member Author

I suspect the avoidStarImports rule might be a potentially controversial one.

Personally I have a mild preference to avoid start imports simply because

  • it is objective (otherwise, where is the cut-off where we want star imports?) and
  • diffs will show when/where uses of classes are added/removed (e.g. when introducing new AST nodes)

...but this is a weakly held view -- any advocates for star imports are welcome to comment and we can roll that bit back! 👍 😄

@koppor
Copy link
Contributor

koppor commented Sep 2, 2021

Nitpick 😇: There should be an ADR (refs #2714) on using custom checkstyle rules versus Google Java Style Guide. Besides the two spaces rule, I personally like it, because there is good tooling: Google Java Format: Formats the code, ...

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

2 participants