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

Indentation Curiosity #565

Closed
MeikeMertschFortum opened this issue Jan 8, 2022 · 1 comment
Closed

Indentation Curiosity #565

MeikeMertschFortum opened this issue Jan 8, 2022 · 1 comment

Comments

@MeikeMertschFortum
Copy link

MeikeMertschFortum commented Jan 8, 2022

Hi there. I just updated org.jlleitschuh.gradle.ktlint from 10.0.0 to 10.2.1 and in one of my classes I get now surprising complaints about the indentation.

Here's the class code:

class Mailbox(private val topic: String) {

    companion object {
        fun fromMailAddress(mail: String) = Mailbox(getTopicFrom(mail))
    }

    fun expectSubscriptionMailIn(waitingTimeInSeconds: Int): Email =
        waitUntil({ it.isSubConfirmation() }, "Subscription mail for $topic", waitingTimeInSeconds).first()

    fun expectSessionReportIn(waitingTimeInSeconds: Int): String =
        waitUntil({ it.isSessionReport() }, "Session Report for $topic", waitingTimeInSeconds).first()
            .returnReportLink()

    fun expectErrorMailIn(waitingTimeInSeconds: Int, errorCode: String): Email =
        waitUntil({ it.isErrorMessage(errorCode) }, "Error mail for $topic", waitingTimeInSeconds).first()

    fun expectOfflineMailIn(waitingTimeInSeconds: Int): Email =
        waitUntil({ it.isOfflineError() }, "Offline mail for $topic", waitingTimeInSeconds).first()

    fun expectFleetInvitationIn(waitingTimeInSeconds: Int): String =
        waitUntil({ it.isFleetInvite() }, "Fleet invite for $topic", waitingTimeInSeconds).first()
            .findLink()

    fun expectMailsBySubject(vararg subjectCandidates: String) =
        waitUntil({ subjectCandidates.contains(it.subject) }, "Mail for $topic", 60)

    fun subscribeToAwsNotifications(): Mailbox = apply {
        val subscriptionEmail = expectSubscriptionMailIn(90)
        subscriptionEmail.subscribe()
    }

    private fun waitUntil(predicate: Predicate<Email>, alias: String, waitingTimeInSeconds: Int): List<Email> =
        checkMailsFor(predicate, alias, waitingTimeInSeconds, topic)
}

now the check failed as follows:

> Task :ktlintTestSourceSetCheck FAILED
.../Mailbox.kt:19:1 Unexpected indentation (4) (should be 8)
.../Mailbox.kt:20:1 Unexpected indentation (8) (should be 12)
.../Mailbox.kt:21:1 Unexpected indentation (12) (should be 20)
.../Mailbox.kt:23:1 Unexpected indentation (4) (should be 12)
.../Mailbox.kt:24:1 Unexpected indentation (8) (should be 16)
.../Mailbox.kt:26:1 Unexpected indentation (4) (should be 16)
.../Mailbox.kt:27:1 Unexpected indentation (8) (should be 20)
.../Mailbox.kt:29:1 Unexpected indentation (4) (should be 20)
.../Mailbox.kt:30:1 Unexpected indentation (8) (should be 24)
.../Mailbox.kt:31:1 Unexpected indentation (12) (should be 32)
.../Mailbox.kt:33:1 Unexpected indentation (4) (should be 24)
.../Mailbox.kt:34:1 Unexpected indentation (8) (should be 28)
.../Mailbox.kt:36:1 Unexpected indentation (4) (should be 24)

if I run the formatter, I end up with this:

class Mailbox(private val topic: String) {

    companion object {
        fun fromMailAddress(mail: String) = Mailbox(getTopicFrom(mail))
    }

    fun expectSubscriptionMailIn(waitingTimeInSeconds: Int): Email =
        waitUntil({ it.isSubConfirmation() }, "Subscription mail for $topic", waitingTimeInSeconds).first()

        fun expectSessionReportIn(waitingTimeInSeconds: Int): String =
            waitUntil({ it.isSessionReport() }, "Session Report for $topic", waitingTimeInSeconds).first()
                    .returnReportLink()

            fun expectErrorMailIn(waitingTimeInSeconds: Int, errorCode: String): Email =
                waitUntil({ it.isErrorMessage(errorCode) }, "Error mail for $topic", waitingTimeInSeconds).first()

                fun expectOfflineMailIn(waitingTimeInSeconds: Int): Email =
                    waitUntil({ it.isOfflineError() }, "Offline mail for $topic", waitingTimeInSeconds).first()

                    fun expectFleetInvitationIn(waitingTimeInSeconds: Int): String =
                        waitUntil({ it.isFleetInvite() }, "Fleet invite for $topic", waitingTimeInSeconds).first()
                                .findLink()

                        fun expectMailsBySubject(vararg subjectCandidates: String) =
                            waitUntil({ subjectCandidates.contains(it.subject) }, "Mail for $topic", 60)

                        fun subscribeToAwsNotifications(): Mailbox = apply {
                            val subscriptionEmail = expectSubscriptionMailIn(90)
                            subscriptionEmail.subscribe()
                        }

                        private fun waitUntil(predicate: Predicate<Email>, alias: String, waitingTimeInSeconds: Int): List<Email> =
                            checkMailsFor(predicate, alias, waitingTimeInSeconds, topic)
                    }

I don't really understand why. It feels like the equal signs work almost as opening parentheses but not closing ones.
Even more curious is that this is the only file in the project that has this issue (but I am almost certain it is also the only one that contains only single expression functions that are longer than a single line (with exception of the companion object)

And I am pretty convinced that this format is not how it should be. Ktlint usually gives me beautiful code (yay!), but this doesn't look right 😅

EDIT: I tried the versions backwards and it works with 10.1.0 but not with 10.2.0

@JLLeitschuh
Copy link
Owner

This is more likely an issue with Ktlint, not this plugin. You may want to open an issue there

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

No branches or pull requests

2 participants