-
Notifications
You must be signed in to change notification settings - Fork 503
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 rule fails on every line after inline lambda in chain #1320
Comments
run |
I'm using the ktlint-gradle wrapper to run ktlint. I checked their changelogs instead and I think the default ktlint version is 0.42.1. |
I have the same issue. I reported it first to the lib I use for the gradle implementation, but I was sent here. Since that library updated the default ktlint version from 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:
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. 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 😅 |
@MeikeMertschFortum Your problem will be solved with #1284 |
Closed by #1284 |
Expected Behavior
ktlint indicates that the file has no formatting errors.
Observed Behavior
ktlint indicates that every line is missing one level of indentation after a line that has an inline lambda function that is not the last argument to a function, and that function is then chained.
Steps to Reproduce
With the following code sample,
run
./gradlew ktlintCheck
from ktlint-gradle to get the following errors:Mitigations
The following changes to the code sample circumvent the issue:
doWithLambda
in a variable, and then calltoDouble
on that on a separate line.doWithLambda
so that the lambda is the last argument. It does not matter if the lambda is in the parentheses or not.doWithLambda
.Putting a
return@doWithLambda
inside the lambda does not resolve the issue.Your Environment
RandomnessIcons.kt
; you have to manually change the Detekt version from 1.18.1 to 1.19.0The text was updated successfully, but these errors were encountered: