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

Add NewLineAfterSuperCall Rule #25

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

hackertronix
Copy link
Contributor

@pedrodanielcsantos mentioned a formatting issue on my PR

So I've created a new rule to ensure we don't forget about it 🙂

super.visitNamedFunction(function)
function.bodyBlockExpression?.statements?.forEachIndexed { index, statement ->
if (statement.text?.startsWith("super") == true) {
if (statement.nextSibling.text.contains("\n\n")) return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's likely a cleaner way to do this, but I am not super on top of detekt APIs so for now sticking with this as it works!

Copy link

@pedrodanielcsantos pedrodanielcsantos left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the update @hackertronix ! 🚀

Left a couple of small suggestions, good to go after checking them.

To make it the whole package, you can publish a new version and update Todoist afterwards. 🙏

override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
function.bodyBlockExpression?.statements?.forEachIndexed { index, statement ->
if (statement.text?.startsWith("super") == true) {

Choose a reason for hiding this comment

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

Should we check here for super. (i.e. with the dot at the end), just for extra safety ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch


override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
function.bodyBlockExpression?.statements?.forEachIndexed { index, statement ->

Choose a reason for hiding this comment

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

A bit ironic but ... Can we add an empty line here, please? 😇😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LOL

import org.junit.jupiter.api.Test

@KotlinCoreEnvironmentTest
internal class NewLineAfterSuperCallTest(private val env: KotlinCoreEnvironment) {

Choose a reason for hiding this comment

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

👏

@hackertronix hackertronix merged commit 51e04ef into main Aug 9, 2024
4 checks passed
@hackertronix hackertronix deleted the prateek/new_line_after_super_rule branch August 9, 2024 13:52
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.

2 participants