From bae5344f302acccb587679a9fe0976f866336a07 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Wed, 28 Jun 2023 21:50:46 +0200 Subject: [PATCH] Fix indent when property value is wrapped Closes #2095 --- CHANGELOG.md | 1 + .../ktlint/ruleset/standard/rules/PropertyWrappingRule.kt | 2 +- .../ktlint/ruleset/standard/rules/PropertyWrappingRuleTest.kt | 4 ---- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594b130ee0..ad5cf178e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ At this point in time, it is not yet decided what the next steps will be. Ktlint * Ignore property with name `serialVersionUID` in `property-naming` ([#2045](https://github.com/pinterest/ktlint/issues/2045)) * Prevent incorrect reporting of violations in case a nullable function type reference exceeds the maximum line length `parameter-list-wrapping` ([#1324](https://github.com/pinterest/ktlint/issues/1324)) * Prevent false negative on `else` branch when body contains only chained calls or binary expression ([#2057](https://github.com/pinterest/ktlint/issues/2057)) +* Fix indent when property value is wrapped to next line ([#2095](https://github.com/pinterest/ktlint/issues/2095)) ### Changed diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt index 88f3afdd43..2ffdb330c1 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRule.kt @@ -146,7 +146,7 @@ public class PropertyWrappingRule : ) LOGGER.trace { "$line: " + ((if (!autoCorrect) "would have " else "") + "inserted newline before ${node.text}") } if (autoCorrect) { - node.upsertWhitespaceBeforeMe(node.indent()) + node.upsertWhitespaceBeforeMe(indentConfig.childIndentOf(node)) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRuleTest.kt index 8cadc91bd3..52535a0d16 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/rules/PropertyWrappingRuleTest.kt @@ -24,7 +24,6 @@ internal class PropertyWrappingRuleTest { """.trimIndent() propertyWrappingRuleAssertThat(code) .setMaxLineLength() - .addAdditionalRuleProvider { IndentationRule() } .hasLintViolation(2, 34, "Missing newline after \":\"") .isFormattedAs(formattedCode) } @@ -46,7 +45,6 @@ internal class PropertyWrappingRuleTest { """.trimIndent() propertyWrappingRuleAssertThat(code) .setMaxLineLength() - .addAdditionalRuleProvider { IndentationRule() } .hasLintViolation(2, 30, "Missing newline before \"TypeWithALongName\"") .isFormattedAs(formattedCode) } @@ -69,7 +67,6 @@ internal class PropertyWrappingRuleTest { """.trimIndent() propertyWrappingRuleAssertThat(code) .setMaxLineLength() - .addAdditionalRuleProvider { IndentationRule() } .hasLintViolations( LintViolation(2, 50, "Missing newline after \"=\""), LintViolation(3, 49, "Missing newline before \"TypeWithALongName(123)\""), @@ -93,7 +90,6 @@ internal class PropertyWrappingRuleTest { """.trimIndent() propertyWrappingRuleAssertThat(code) .setMaxLineLength() - .addAdditionalRuleProvider { IndentationRule() } .hasLintViolation(2, 50, "Missing newline before \"TypeWithALongName(123)\"") .isFormattedAs(formattedCode) }