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

Formatting for-loop #1464

Merged

Conversation

paul-dingemans
Copy link
Collaborator

Description

Keep formatting of for-loop in sync with default IntelliJ formatter until https://youtrack.jetbrains.com/issue/IDEA-293691/Format-Kotlin-for-loop is fixed. Now, code below does not throw indentation errors:

fun foo() {
    for (
    item in listOf(
        "a",
        "b"
    )) {
        println(item)
    }
}

The wrapping rule no longer forces the for-statement to be wrapped if only the expression contains a newline. So code above can be written as:

fun foo() {
    for (item in listOf(
        "a",
        "b"
    )) {
        println(item)
    }
}

Closes #1350

Checklist

  • PR description added
  • tests are added
  • CHANGELOG.md is updated

In case of adding a new rule:

  • README.md is updated
  • Rule has been applied on Ktlint itself and violations are fixed

…ntil https://youtrack.jetbrains.com/issue/IDEA-293691/Format-Kotlin-for-loop is fixed. The wrapping rule no longer forces the for-statement to be wrapped if only the expression contains a newline.

Closes pinterest#1350
@paul-dingemans paul-dingemans added this to the 0.46.0 milestone May 8, 2022
# Conflicts:
#	ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/IndentationRuleTest.kt
@paul-dingemans paul-dingemans merged commit 7bb931f into pinterest:master May 20, 2022
@paul-dingemans paul-dingemans deleted the 1350-for-loop-indentation branch May 20, 2022 18:05
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.

Intellij disagree with ktlint for code with for
1 participant