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

Update Checkstyle and associated rules #71

Closed
wants to merge 3 commits into from
Closed

Update Checkstyle and associated rules #71

wants to merge 3 commits into from

Conversation

paulerickson
Copy link
Contributor

@paulerickson paulerickson commented Apr 29, 2021

Our version of Checkstyle is out of date, does not enforce certain rules very well, and completely chokes on newer language elements such as switch expressions.

Unfortunately, that project uses sentimental versioning and broke some things without any clear migration guides 😒

Config changes that don't change behavior

The LineLength check only moved from one place to another

Javadoc allowMissingThrowsTags and allowThrowsTagsForSubclasses are no longer supported. Since we allowed these, it should be no change.

Javadoc allowMissingJavadoc and minLineCount moved to a new check. Since we allow missing, I have not added that check.

Javadoc scope apparently got renamed to accessModifiers

Unchanged config that changes behavior

Mainly I would highlight import groups. Checkstyle defines a fixed number of logical groups to be separated by a blank line; we have

  1. Standard (defined as java & javax)
  2. 1st party (defined as org.sonatype & com.sonatype)
  3. 3rd party (everything else)
  4. static

It enforces that there are blank lines between those groups and no additional blank lines within groups, whereas it used to permit extra blank lines. IMHO, this way of grouping and avoiding excess blank lines is good style and consistent with the existing rule, so I updated the IDEA config to be consistent. Unfortunately, Eclipse only groups packages, so its auto-organize import feature is fundamentally different.
EDIT: so I removed this check

Related to this, javax left the JDK in version 11, so whether it is 3rd party or standard is not a matter of style but JDK version. I updated the IDE configs to treat it as 3rd party, since that is current and consistent with Checkstyle.

The rule against unnecessary parentheses is enforced more rigidly now, and I had one or two other new violations with HDS, which seemed consistent with the existing rules.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
README.md Outdated
@@ -52,6 +52,8 @@ See [the Intellij documentation](https://www.jetbrains.com/help/idea/copying-cod
See [the eclipse documentation](http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcodestyle%2Fref-preferences-formatter.htm) for how to import the files into your IDE.
In addition, html indentation settings are not exported, but can be set to 2 spaces from Preferences -> Web -> HTML Files -> Editor -> "Indent using spaces". [Screenshot of the eclipse config here.](https://s3.amazonaws.com/uploads.hipchat.com/18157/88592/RSkQhq8UYnxf81Z/upload.png)

Note that Eclipse's _Organize Imports_ feature does not group imports by 1st party, 3rd party, etc. as defined by Checkstyle rules.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you cannot configure all major IDEs employed by our developers to meet the rules that Checkstyle seeks to enforce and fail on, then those rules have reached the end of their usefulness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm inclined to agree 43a3701

I tested a couple of ways in Eclipse, and whether you configure 0 or 1 blank lines between groups, it will mess up the grouping in an existing file when you do an automatic import that comes at the alphabetical beginning or end of a group 🤷

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@tneer
Copy link
Contributor

tneer commented Apr 30, 2021

@paulerickson Were you not able to create a branch on this project. We do have branch builds at https://jenkins.ci.sonatype.dev/job/bnr/job/tools/job/codestyle/job/feature-snapshots/

@tneer
Copy link
Contributor

tneer commented Apr 30, 2021

@ajdranse This seems to be a superset of your PR. Perhaps you can review and maybe close yours?

@ajdranse
Copy link

@ajdranse This seems to be a superset of your PR. Perhaps you can review and maybe close yours?

Sure thing, will do that today.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@paulerickson
Copy link
Contributor Author

@paulerickson Were you not able to create a branch on this project. We do have branch builds at https://jenkins.ci.sonatype.dev/job/bnr/job/tools/job/codestyle/job/feature-snapshots/

Oops, I hadn't even noticed my origin was a fork, but I do have permissions now, so I created https://github.com/sonatype/codestyle/pull/72/files to replace this

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