Skip to content

Commit

Permalink
Fix indent of multiline object declaration inside class (#2266)
Browse files Browse the repository at this point in the history
Closes #2257
  • Loading branch information
paul-dingemans authored Sep 17, 2023
1 parent afe88df commit b135fe8
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)
* Ignore anonymous function in rule `function-naming` [#2260](https://github.com/pinterest/ktlint/issue/2260)
* Do not force blank line before function in right hand side of assignment `blank-line-before-declaration` [#2260](https://github.com/pinterest/ktlint/issue/2260)

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 b135fe8

Please sign in to comment.