Skip to content

Commit

Permalink
Fix indent of multiline object declaration inside class
Browse files Browse the repository at this point in the history
Closes #2257
  • Loading branch information
paul-dingemans committed Sep 17, 2023
1 parent a38fb6f commit 0d24f4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed

* Fix ktlint cli parameter `--code-style` [#2238](https://github.com/pinterest/ktlint/pull/2238)
* Fix indent of multiline object declaration inside class `indent` [#2257](https://github.com/pinterest/ktlint/issue/2257)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ public class IndentationRule :
}

private fun ASTNode.isPartOfClassWithAMultilinePrimaryConstructor() =
parent { it.elementType == CLASS }
treeParent
.takeIf { it.elementType == CLASS }
?.findChildByType(PRIMARY_CONSTRUCTOR)
?.textContains('\n') == true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4651,7 +4651,7 @@ internal class IndentationRuleTest {
val code =
"""
class FooBar :
Foox,
Foo,
Bar {
// Do something
}
Expand All @@ -4666,6 +4666,22 @@ internal class IndentationRuleTest {
indentationRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Issue 2257 - Given a class containing an object declaration having a super type with parameters`() {
val code =
"""
class Foo(
foo: String,
) {
object Bar : Baz(
baz = "baz",
bar = "bar",
)
}
""".trimIndent()
indentationRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Given an if statement with multiple EOL comments between end of then and else`() {
val code =
Expand Down

0 comments on commit 0d24f4a

Please sign in to comment.