From 6dc01fa90418ca7eb995bfa42f7ef2eb207643fc Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:06:51 -0700 Subject: [PATCH 01/12] Fix ktlint 0.48 --- gradle.properties | 2 + lib/build.gradle | 16 +++-- .../KtLintCompat0Dot48Dot1Adapter.java} | 64 ++++++++++++++----- .../glue/ktlint/KtlintFormatterFunc.java | 4 +- .../diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../KtLintCompat0Dot48Dot1AdapterTest.java | 48 ++++++++++++++ .../resources/empty_class_body.kt | 3 + .../resources/fails_no_semicolons.kt | 3 + .../spotless/kotlin/KtLintStepTest.java | 4 +- 9 files changed, 119 insertions(+), 27 deletions(-) rename lib/src/{compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java => compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java} (57%) create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt create mode 100644 lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt diff --git a/gradle.properties b/gradle.properties index 577ed87535..001197ff4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,7 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 +org.gradle.parallel=true +org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug diff --git a/lib/build.gradle b/lib/build.gradle index 0cc258afca..826abf70a7 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.0', + '0.48.1', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' + compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,10 +105,16 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } +configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +} + // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) -test { useJUnitPlatform() } +tasks.withType(Test).configureEach { + useJUnitPlatform() +} jar { for (glue in NEEDS_GLUE) { diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java similarity index 57% rename from lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java rename to lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index 8235c535a5..e47f950a1b 100644 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,6 +15,9 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -23,15 +26,21 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLint; +import com.pinterest.ktlint.core.KtLintRuleEngine; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties; import com.pinterest.ktlint.core.api.EditorConfigDefaults; import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.api.UsesEditorConfigProperties; +import com.pinterest.ktlint.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.DisabledRulesEditorConfigPropertyKt; import com.pinterest.ktlint.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; import com.pinterest.ktlint.ruleset.experimental.ExperimentalRuleSetProvider; import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider; @@ -39,7 +48,23 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + //noinspection deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY()); + //noinspection KotlinInternalInJava,deprecation + list.add(DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } static class FormatterCallback implements Function2 { @Override @@ -47,7 +72,7 @@ public Unit invoke(LintError lint, Boolean corrected) { if (!corrected) { KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); } - return null; + return Unit.INSTANCE; } } @@ -66,7 +91,7 @@ public String format(final String text, final String name, final boolean isScrip EditorConfigOverride editorConfigOverride; if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEmptyEditorConfigOverride(); + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); } else { editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( RuleProvider::createNewRuleInstance).collect( @@ -74,17 +99,10 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( - name, - text, - allRuleProviders, - userData, - formatterCallback, - isScript, - false, - EditorConfigDefaults.Companion.getEmptyEditorConfigDefaults(), - editorConfigOverride, - false)); + EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + boolean isInvokedFromCli = false; + KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); + return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); } /** @@ -98,7 +116,7 @@ private static EditorConfigOverride createEditorConfigOverride(final List // Create a mapping of properties to their names based on rule properties and default properties Map> supportedProperties = Stream - .concat(ruleProperties, DefaultEditorConfigProperties.INSTANCE.getEditorConfigProperties().stream()) + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); @@ -109,6 +127,18 @@ private static EditorConfigOverride createEditorConfigOverride(final List EditorConfigProperty property = supportedProperties.get(entry.getKey()); if (property != null) { return new Pair<>(property, entry.getValue()); + } else if (entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to {ruleset} + String qualifiedRuleId = parts[0]; + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(qualifiedRuleId); + } else { + // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} + String qualifiedRuleId = parts[0] + ":" + parts[1]; + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(qualifiedRuleId); + } + return new Pair<>(property, entry.getValue()); } else { return null; } diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index fc64cdb23e..5be69e819c 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + this.adapter = new KtLintCompat0Dot48Dot1Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index b444f0f1a7..7efbb911e3 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -33,7 +33,7 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.48.0"; + private static final String DEFAULT_VERSION = "0.48.1"; static final String NAME = "ktlint"; static final String PACKAGE_PRE_0_32 = "com.github.shyiko"; static final String PACKAGE = "com.pinterest"; diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java new file mode 100644 index 0000000000..d4416d83f3 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -0,0 +1,48 @@ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class KtLintCompat0Dot48Dot1AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + Files.copy(is, path.resolve("empty_class_body.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class empty_class_body\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + Files.copy(is, path.resolve("fails_no_semicolons.kt")); + } + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); + } +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt new file mode 100644 index 0000000000..b84774d572 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt @@ -0,0 +1,3 @@ +class empty_class_body { + +} diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt new file mode 100644 index 0000000000..20ab460913 --- /dev/null +++ b/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt @@ -0,0 +1,3 @@ +class fails_no_semicolons { + val i = 0; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 94de314e0b..4ad9620d48 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -130,8 +130,8 @@ void works0_47_1() { } @Test - void works0_48_0() { - FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + void works0_48_1() { + FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + From 4550b66e70910b4733500a6fa4534197fbaa0dd6 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:13:36 -0700 Subject: [PATCH 02/12] Add change to changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index a7e3516607..d595ff8df6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 2936d3cbd6493cab8a2fd27d797b6f8fd2d920eb Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:14:54 -0700 Subject: [PATCH 03/12] Add link to issue in changelog --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index d595ff8df6..ee73f019a5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 +* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) From 41c3fe9f07ddfa7145e1e582de923537393e0c67 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:21:19 -0700 Subject: [PATCH 04/12] Update all change logs --- CHANGES.md | 4 +++- plugin-gradle/CHANGES.md | 3 +++ plugin-maven/CHANGES.md | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ee73f019a5..50e4d83141 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,9 @@ 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 +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) ### Changes -* Fix ktlint 0.48.x and bump to ktlint 0.48.1 ([#1444](https://github.com/diffplug/spotless/issues/1444)) * Bump the dev version of Gradle from `7.5.1` to `7.6` ([#1409](https://github.com/diffplug/spotless/pull/1409)) * We also removed the no-longer-required dependency `org.codehaus.groovy:groovy-xml` * Breaking changes to Spotless' internal testing infrastructure `testlib` ([#1443](https://github.com/diffplug/spotless/pull/1443)) @@ -19,6 +20,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `StepHarness` now operates on `Formatter` rather than a `FormatterStep` * `StepHarnessWithFile` now takes a `ResourceHarness` in its constructor to handle the file manipulation parts * Standardized that we test exception *messages*, not types, which will ease the transition to linting later on + * Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.31.1] - 2023-01-02 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index c5f464069f..56ed8d6c1e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Fixed * Prevent tool configurations from being resolved outside project ([#1447](https://github.com/diffplug/spotless/pull/1447) fixes [#1215](https://github.com/diffplug/spotless/issues/1215)) +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [6.12.1] - 2023-01-02 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 84e06aa847..bc706437fd 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* Support `ktlint` 0.48+ new rule disabling syntax ([#1456](https://github.com/diffplug/spotless/pull/1456)) fixes ([#1444](https://github.com/diffplug/spotless/issues/1444)) +### Changes +* Bump default `ktlint` version to latest `0.47.1` -> `0.48.1` ([#1456](https://github.com/diffplug/spotless/pull/1456)) ## [2.29.0] - 2023-01-02 ### Added From 954e6b58b5c02bbab86b0998cc1232717cba0c7f Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 14:33:30 -0700 Subject: [PATCH 05/12] Run spotless --- .../KtLintCompat0Dot48Dot1AdapterTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index d4416d83f3..a49de57a97 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -1,5 +1,22 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.diffplug.spotless.glue.ktlint.compat; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -10,8 +27,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import static org.junit.jupiter.api.Assertions.assertEquals; - public class KtLintCompat0Dot48Dot1AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { From 1a19da11f18dcdf60d821abda4ebd77a0a4e4648 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:34:22 -0700 Subject: [PATCH 06/12] Use older format function that doesn't load .editorconfig --- .../compat/KtLintCompat0Dot48Dot1Adapter.java | 18 ++++++++++++------ .../KtLintCompat0Dot48Dot1AdapterTest.java | 1 + .../spotless/kotlin/KtLintStepTest.java | 10 ++++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java index e47f950a1b..4329c18db9 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -26,7 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import com.pinterest.ktlint.core.KtLintRuleEngine; +import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.Rule; import com.pinterest.ktlint.core.RuleProvider; @@ -99,10 +98,17 @@ public String format(final String text, final String name, final boolean isScrip editorConfigOverrideMap); } - EditorConfigDefaults editorConfigDefaults = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - boolean isInvokedFromCli = false; - KtLintRuleEngine ktLintRuleEngine = new KtLintRuleEngine(allRuleProviders, editorConfigDefaults, editorConfigOverride, isInvokedFromCli); - return ktLintRuleEngine.format(text, Paths.get(name), formatterCallback); + return KtLint.INSTANCE.format(new KtLint.ExperimentalParams( + name, + text, + allRuleProviders, + userData, + formatterCallback, + isScript, + false, + EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(), + editorConfigOverride, + false)); } /** diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index a49de57a97..31e6caf824 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -55,6 +55,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map userData = new HashMap<>(); Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 4ad9620d48..1be0c7b72f 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -129,6 +129,16 @@ void works0_47_1() { "Wildcard import"); } + @Test + void works0_48_0() { + FormatterStep step = KtLintStep.create("0.48.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void works0_48_1() { FormatterStep step = KtLintStep.create("0.48.1", TestProvisioner.mavenCentral()); From 11971ab599ee730d3c1fc6b995198a31f7525f6a Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:43:03 -0700 Subject: [PATCH 07/12] Fix UTF-8 encoder errors --- .../ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java index 31e6caf824..ca9d603e5c 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -34,7 +35,7 @@ public void testDefaults(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } - String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt"))); + String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); @@ -50,7 +51,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } - String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt"))); + String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); Map userData = new HashMap<>(); From b853169fb7650db131b6cc8efa9b538c4613cde2 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 4 Jan 2023 15:56:42 -0700 Subject: [PATCH 08/12] Remove org.gradle settings --- gradle.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 001197ff4c..577ed87535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ # To fix metaspace errors org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1024m -Dfile.encoding=UTF-8 -org.gradle.parallel=true -org.gradle.caching=true name=spotless description=Spotless - keep your code spotless with Gradle org=diffplug From b6e90739d5deac7b356eaad74307b3c2dc061a0c Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 10:45:59 -0700 Subject: [PATCH 09/12] Change back to 0.48.0 --- lib/build.gradle | 12 ++++++------ .../compat/KtLintCompat0Dot48Dot0Adapter.java} | 2 +- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 4 ++-- .../compat/KtLintCompat0Dot48Dot0AdapterTest.java} | 14 +++++++------- .../resources/empty_class_body.kt | 0 .../resources/fails_no_semicolons.kt | 0 6 files changed, 16 insertions(+), 16 deletions(-) rename lib/src/{compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java => compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java} (99%) rename lib/src/{testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java => testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java} (81%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/empty_class_body.kt (100%) rename lib/src/{testCompatKtLint0Dot48Dot1 => testCompatKtLint0Dot48Dot0}/resources/fails_no_semicolons.kt (100%) diff --git a/lib/build.gradle b/lib/build.gradle index 826abf70a7..4cf4c66332 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -34,7 +34,7 @@ versionCompatibility { '0.45.2', '0.46.0', '0.47.0', - '0.48.1', + '0.48.0', ] targetSourceSetName = 'ktlint' } @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' - compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,8 +105,8 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } -configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) +configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { + extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard diff --git a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java similarity index 99% rename from lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java rename to lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java index 4329c18db9..f910576971 100644 --- a/lib/src/compatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1Adapter.java +++ b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java @@ -47,7 +47,7 @@ import kotlin.Unit; import kotlin.jvm.functions.Function2; -public class KtLintCompat0Dot48Dot1Adapter implements KtLintCompatAdapter { +public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 5be69e819c..fc64cdb23e 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -27,7 +27,7 @@ import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot45Dot2Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot46Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot47Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot1Adapter; +import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { @@ -44,7 +44,7 @@ public KtlintFormatterFunc(String version, boolean isScript, boolean useExperime int minorVersion = Integer.parseInt(version.split("\\.")[1]); if (minorVersion >= 48) { // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot1Adapter(); + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); } else if (minorVersion == 47) { // rename RuleSet to RuleProvider this.adapter = new KtLintCompat0Dot47Dot0Adapter(); diff --git a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java similarity index 81% rename from lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java rename to lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index ca9d603e5c..cccf71da12 100644 --- a/lib/src/testCompatKtLint0Dot48Dot1/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot1AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -28,11 +28,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -public class KtLintCompat0Dot48Dot1AdapterTest { +public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { Files.copy(is, path.resolve("empty_class_body.kt")); } String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); @@ -41,14 +41,14 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { + KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { Files.copy(is, path.resolve("fails_no_semicolons.kt")); } String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); @@ -59,7 +59,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } } diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/empty_class_body.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt diff --git a/lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt similarity index 100% rename from lib/src/testCompatKtLint0Dot48Dot1/resources/fails_no_semicolons.kt rename to lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt From 6b2e2c397f4405ff9c1ed264dcd78138d2e8bb87 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Fri, 6 Jan 2023 11:10:29 -0700 Subject: [PATCH 10/12] Use testCommonImplementation configuration --- lib/build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 4cf4c66332..e8c22d28b6 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -45,9 +45,9 @@ dependencies { compileOnly 'org.slf4j:slf4j-api:2.0.0' // zero runtime reqs is a hard requirements for spotless-lib // if you need a dep, put it in lib-extra - testImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" - testImplementation "org.assertj:assertj-core:$VER_ASSERTJ" - testImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" + testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT" + testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ" + testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN" // used for pom sorting sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0' @@ -106,7 +106,7 @@ dependencies { } configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { - extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot0CompileOnly) + extendsFrom(configurations.compatKtLint0Dot48Dot0CompileOnly) } // we'll hold the core lib to a high standard From 778f4859d4c06ad86df1e4a1982cb34456b329ed Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Sat, 7 Jan 2023 14:10:08 -0700 Subject: [PATCH 11/12] Use latest version-compatibility plugin --- lib/build.gradle | 10 +++------- settings.gradle | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index e8c22d28b6..115d27195f 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -91,9 +91,9 @@ dependencies { compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' - compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' + compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' + compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' + compatKtLint0Dot48Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' String VER_SCALAFMT="3.6.1" scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" @@ -105,10 +105,6 @@ dependencies { flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' } -configurations.named('testCompatKtLint0Dot48Dot0Implementation').configure { - extendsFrom(configurations.compatKtLint0Dot48Dot0CompileOnly) -} - // we'll hold the core lib to a high standard spotbugs { reportLevel = 'low' } // low|medium|high (low = sensitive to even minor mistakes) diff --git a/settings.gradle b/settings.gradle index 786baa1eba..741e4b6ccc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,7 +16,7 @@ pluginManagement { // https://github.com/radarsh/gradle-test-logger-plugin/blob/develop/CHANGELOG.md id 'com.adarshr.test-logger' version '3.2.0' // https://github.com/davidburstrom/version-compatibility-gradle-plugin/tags - id 'io.github.davidburstrom.version-compatibility' version '0.3.0' + id 'io.github.davidburstrom.version-compatibility' version '0.4.0' } } plugins { From 34097544d3ee6288fec976e30ac008b0d33b0ab4 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Sat, 7 Jan 2023 14:19:46 -0700 Subject: [PATCH 12/12] Factor out helper method --- .../KtLintCompat0Dot48Dot0AdapterTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index cccf71da12..fe4463468a 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -32,10 +32,7 @@ public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { - Files.copy(is, path.resolve("empty_class_body.kt")); - } - String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); + String text = loadAndWriteText(path, "empty_class_body.kt"); Map userData = new HashMap<>(); @@ -48,10 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException { @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { - Files.copy(is, path.resolve("fails_no_semicolons.kt")); - } - String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8); + String text = loadAndWriteText(path, "fails_no_semicolons.kt"); Map userData = new HashMap<>(); @@ -62,4 +56,12 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + }