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

Fix indent of multiline object declaration inside class #2266

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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