Skip to content

Commit

Permalink
Disallow records as part of public API (#4279)
Browse files Browse the repository at this point in the history
* No public API records

* Add note in contributing

* Explain why

* Fix
  • Loading branch information
modmuss50 authored Dec 12, 2024
1 parent f906699 commit 5f43f98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ Fabric API makes strong backwards compatibility guarantees, by which contributor
- If vanilla exposes optionals in return types, then returning an optional is fine.
- Avoid requiring the user to cast to a subtype if possible.
- Adding methods to vanilla types can be done via interface injection.
- Avoid exposing java `record`s as public API.
- Records expose more than is necessary for most APIs, which makes them difficult to evolve.
- Prefer to expose an interface that is implemented by an impl record.

### API design patterns to consider

Expand Down
5 changes: 5 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,10 @@
<module name="MatchXpath">
<property name="query" value="//VARIABLE_DEF[./TYPE/IDENT[@text='var'] and not(./ASSIGN/EXPR/LITERAL_NEW)]"/>
</module>

<!-- 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>
</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package net.fabricmc.fabric.api.transfer.v1.storage.base;

//CHECKSTYLE.OFF: MatchXpath

/**
* An immutable object storing both a resource and an amount, provided for convenience.
* @param <T> The type of the stored resource.
Expand Down

0 comments on commit 5f43f98

Please sign in to comment.