-
Notifications
You must be signed in to change notification settings - Fork 421
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
Disallow records as part of public API #4279
Conversation
<!-- Prevent public records in API packages --> | ||
<module name="MatchXpath"> | ||
<property name="query" value="//RECORD_DEF[./MODIFIERS/LITERAL_PUBLIC][//PACKAGE_DEF//DOT/IDENT[@text='api']]"/> | ||
</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to add a custom error message here, as I don't think this will generate failures that are easy to understand if you don't know about the record rule. I don't know much about configuring checkstyle but custom messages seem possible: https://stackoverflow.com/a/18252466
@@ -16,6 +16,8 @@ | |||
|
|||
package net.fabricmc.fabric.api.transfer.v1.storage.base; | |||
|
|||
//CHECKSTYLE.OFF: MatchXpath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These MatchXpath
checks could have different IDs so that they can be suppressed individually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not aware of a way to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well, I guess leave it then
Request for comment
Prevent the use of public records in API classes as this has come up a few times in reviews so would like to get some proper feedback on this. Its only a minor thing, but happens enough I think we should enforce it.
Why
Alternative
The following example record in an API class
would become
and the actual record lives in an impl package:
Where it make a lot of sense to use a record e.g
ResourceAmount
we can opt allow it. If anyone has any thoughts (for or against) please let them be known in this PR.