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

Omit public modifier on override function or constructor parameters #1550

Merged
merged 9 commits into from
May 19, 2023
Merged

Omit public modifier on override function or constructor parameters #1550

merged 9 commits into from
May 19, 2023

Conversation

Omico
Copy link
Contributor

@Omico Omico commented May 16, 2023

Fix #1548

@Omico
Copy link
Contributor Author

Omico commented May 17, 2023

If this looks good, should I push a commit to format the TypeSpecTest.kt? It's not nicely formatted now.

@Omico Omico requested review from JakeWharton and Egorand May 17, 2023 23:49
Omico added 2 commits May 18, 2023 01:04
Because it explicitly added public modifier
.build(),
)
.build()
// We cannot omit the public modifier here. The bytecode is different.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand what "The bytecode is different" means in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is what it means. Generated by Kotlin Bytecode from IntelliJ IDEA

image

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. If the intent is to explain why the "public" modifier can't be omitted, I don't think the reference to bytecode is very helpful. I'll provide suggestions on how to reword this, but please let me know if I misunderstood your intent.

@Egorand
Copy link
Collaborator

Egorand commented May 18, 2023

should I push a commit to format the TypeSpecTest.kt? It's not nicely formatted now.

We run Spotless on CI, so the build would've failed had this file been misformatted.

Will clean it up in a separate PR
@Omico
Copy link
Contributor Author

Omico commented May 18, 2023

We run Spotless on CI, so the build would've failed had this file been misformatted.

I have used Spotless for a long time too. The issue is ktlint somehow won't always cleanup/format imports. If we apply these changes, it won't break spotlessCheck. These changes are made by IntelliJ IDEA's Optimize Imports.

image

Also, I think it's kind of ugly here, maybe we should also add import com.squareup.kotlinpoet.KModifier.OVERRIDE

image

Maybe we can do this in a separate PR too.

@Egorand
Copy link
Collaborator

Egorand commented May 18, 2023

The issue is ktlint somehow won't always cleanup/format imports.

That's probably something we can/should report to ktlint to help get it fixed. In general, if IDE makes formatting changes that don't interfere with ktlint/spotless, it's fine to merge them. But I don't think it's very productive to apply this kind of formatting changes manually. That said, if you'd like to clean these up, we'll accept the PR.

Also, I think it's kind of ugly here, maybe we should also add import com.squareup.kotlinpoet.KModifier.OVERRIDE

Sure, but code styles are subjective. ktlint gives us good basic rules and will reject most glaring code style issues, and we don't care too much about things that ktlint doesn't catch.

Copy link
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

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

Great job!

@Omico Omico requested review from JakeWharton and Egorand May 18, 2023 22:36
Copy link
Collaborator

@Egorand Egorand left a comment

Choose a reason for hiding this comment

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

Thank you, looks great!

Will merge this once you've signed our CLA, please see contributing.md.

@Omico
Copy link
Contributor Author

Omico commented May 19, 2023

Signed!

@Omico Omico requested a review from Egorand May 19, 2023 12:10
@Egorand Egorand merged commit 17c2011 into square:master May 19, 2023
@Omico Omico deleted the omit-public-modifier branch May 19, 2023 12:24
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.

Omit modifier for override parameters in constructor and it's override function
3 participants