Skip to content

Commit

Permalink
A delegate property which starts on the same line as the property dec…
Browse files Browse the repository at this point in the history
…laration should not have an extra indentation. This fixes a regression bug introduced by the fix of pinterest#1340.

Closes pinterest#1510
  • Loading branch information
paul-dingemans committed Jun 21, 2022
1 parent 1cce447 commit cc24bad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import com.pinterest.ktlint.core.ast.isPartOfComment
import com.pinterest.ktlint.core.ast.isWhiteSpace
import com.pinterest.ktlint.core.ast.isWhiteSpaceWithNewline
import com.pinterest.ktlint.core.ast.isWhiteSpaceWithoutNewline
import com.pinterest.ktlint.core.ast.lineNumber
import com.pinterest.ktlint.core.ast.nextCodeSibling
import com.pinterest.ktlint.core.ast.nextLeaf
import com.pinterest.ktlint.core.ast.nextSibling
Expand Down Expand Up @@ -446,7 +447,9 @@ public class IndentationRule :
}) ?: return
val nextSibling = n.treeNext
if (!ctx.ignored.contains(p) && nextSibling != null) {
if (p.treeParent.elementType == PROPERTY_DELEGATE) {
if (p.treeParent.elementType == PROPERTY_DELEGATE &&
p.treeParent?.lineNumber() != p.treeParent.prevCodeSibling()?.lineNumber()
) {
expectedIndent += 2
logger.trace { "$line: ++dot-qualified-expression in property delegate -> $expectedIndent" }
ctx.ignored.add(p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,16 @@ internal class IndentationRuleTest {
.isFormattedAs(formattedCode)
}

@Test
fun `Issue 1510 - Given a dot-qualified-expression as delegated property value starting on same line as previous code sibling`() {
val code =
"""
val locale: Locale by option
.default()
""".trimIndent()
indentationRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 1340 - Given a dot-qualified-expression wrapped in a block as delegated property value`() {
val code =
Expand Down

0 comments on commit cc24bad

Please sign in to comment.