-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Replace kotlin public data class
es with Poko compiler plugin generated ones
#2136
Replace kotlin public data class
es with Poko compiler plugin generated ones
#2136
Conversation
ktlint-test/src/main/kotlin/com/pinterest/ktlint/test/KtLintAssertThat.kt
Show resolved
Hide resolved
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.
This worked out differently than I expected beforehand when just (quickly) reading the Poko documentation. Overall, the code changes do not seem too intrusive to me.
Would it be possible to define some gradle task that fails the build it it finds something like "public data class" in the source code? Because, I really believe that I will forget about not using data class in public API.
Also nice to see that the binary-compatibility-validator requires changes.
f00e95d
to
d80d1c9
Compare
I did a bit of research, but I couldn't find any standard solution. If I had to come up with some custom ideas then:
|
Alternative to scanning
It would be possible, but it would be a rule that should not be exposed because public data classes are valid to be used in case ktlint is used on a project that is not exposing an API.
True, except that I made this remark because I know that I going to forget about it. Also, it doesn't warn a contributor about making this mistake. [edit] Last days, I slowly come to the believe that it is okay, to have no additional check. We can document this as a FAQ for ktlint developers. |
b0e29ce
to
5d4a032
Compare
Scanning
Absolutely 👍 Assuming this project used one of the gradle plugins, my idea was to do something like:
but with CLI, I'd have to produce Anyway, in the first iteration, I can propose a bash script that runs on CI. If the bash script turns out unreliable and/or if I find enough motivation - I'll try to come up with a project-specific Rule for ktlint, as a replacement for the bash script. |
For now, let's proceed with the current check you have added. |
Fixes #2133
Description
This is a quick attempt to replace public
data class
es withequals
/hashCode
/toString
methods generated by Poko compiler plugin.From my understanding the alternative are:
equals
/hashCode
/toString
manually via IDE - but this is the least preferred option, since it's super easy to forget updating their implementation, when modifying the classequals/
hashCode(calls like
==,
List#distinct()or
Collection#contains` etc) and then refactor the implementation to use custom comparators.I'm opening this PR to gather some feedback, show the diff as a proof how it can be done, and maybe someone has any better idea 😉
Checklist
Before submitting the PR, please check following (checks which are not relevant may be ignored):
Closes #<xxx>
orFixes #<xxx>
(replace<xxx>
with issue number)CHANGELOG.md
is updatedDocumentation is updated. See difference between snapshot and release documentation