From 4f62769da7ba656ee47e9596d7f5b0f9c531c650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:06:17 +0100 Subject: [PATCH 1/5] fixes continuation indent in ktfmt default formatter --- .../spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- .../com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 11 +++++++++++ .../main/resources/kotlin/ktfmt/continuation.clean | 6 ++++++ .../main/resources/kotlin/ktfmt/continuation.dirty | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.clean create mode 100644 testlib/src/main/resources/kotlin/ktfmt/continuation.dirty diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index 72e0e50e3c..e34f7b4755 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -78,7 +78,7 @@ private FormattingOptions createFormattingOptions() { formattingOptions.getStyle(), ktfmtFormattingOptions.getMaxWidth().orElse(formattingOptions.getMaxWidth()), ktfmtFormattingOptions.getBlockIndent().orElse(formattingOptions.getBlockIndent()), - ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getBlockIndent()), + ktfmtFormattingOptions.getContinuationIndent().orElse(formattingOptions.getContinuationIndent()), ktfmtFormattingOptions.getRemoveUnusedImport().orElse(formattingOptions.getRemoveUnusedImports()), formattingOptions.getDebuggingPrintOpsAfterFormatting()); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 4ae266cc23..25ecbc598d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,6 +19,8 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; +import java.io.IOException; + class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception { @@ -36,6 +38,15 @@ void testKtfmt() throws Exception { assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean"); } + @Test + void testContinuation() throws Exception { + writePomWithKotlinSteps(""); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/continuation.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/continuation.clean"); + } + @Test void testKtfmtStyle() throws Exception { writePomWithKotlinSteps(""); diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.clean b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean new file mode 100644 index 0000000000..11677928fc --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.clean @@ -0,0 +1,6 @@ +fun myFunction() { + val location = + restTemplate.postForLocation( + "/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} diff --git a/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty new file mode 100644 index 0000000000..3652274d12 --- /dev/null +++ b/testlib/src/main/resources/kotlin/ktfmt/continuation.dirty @@ -0,0 +1,4 @@ +fun myFunction() { + val location = restTemplate.postForLocation("/v1/my-api", mapOf("name" to "some-name", "url" to "https://www.google.com")) + return location +} From 8c74020fd505ecbc46db645b7fa330cbf5fd9514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 14:16:52 +0100 Subject: [PATCH 2/5] adds a summary of the change to plugin-maven/CHANGES.md --- plugin-maven/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 567d880f4f..0e656e24ec 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.32.0] - 2023-02-05 ### Added From ce086ba1382f618a2cb0b93c9f2fac02f19cfdb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Wed, 8 Feb 2023 21:34:29 +0100 Subject: [PATCH 3/5] adds entry about continuation indent to the other changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 5f1a1ffa9f..86a9eeabf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [2.34.1] - 2023-02-05 ### Changes diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index e3234584b8..9927b56f07 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Maven plugin with `ktfmt` default style uses correct continuation indent ([#1562](https://github.com/diffplug/spotless/pull/1562)) ## [6.14.1] - 2023-02-05 ### Fixed From 3e1ea286ca1d203e32f80b557e3fde54c91fa79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Thu, 9 Feb 2023 12:33:03 +0100 Subject: [PATCH 4/5] updates copyright --- .../com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java index e34f7b4755..80f4a42fcd 100644 --- a/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java +++ b/lib/src/ktfmt/java/com/diffplug/spotless/glue/ktfmt/KtfmtFormatterFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 DiffPlug + * Copyright 2022-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4cb02f30d815992dc23ef9dc8f4e20bd9b9c3147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20L=C3=B8nne?= Date: Fri, 10 Feb 2023 12:59:00 +0100 Subject: [PATCH 5/5] runs spotlessApply and removes an unused import --- .../test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 25ecbc598d..e452c5d56b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -19,8 +19,6 @@ import com.diffplug.spotless.maven.MavenIntegrationHarness; -import java.io.IOException; - class KtfmtTest extends MavenIntegrationHarness { @Test void testKtfmt() throws Exception {