From 82b1fe7561b3b503791454551b6ed1727b6d947e Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 3 Nov 2025 09:50:21 +0800 Subject: [PATCH] Drop support for older Ktlint versions --- CHANGES.md | 2 + lib/build.gradle | 15 -- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 157 ------------- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 206 ------------------ .../compat/KtLintCompat0Dot50Dot0Adapter.java | 169 -------------- .../glue/ktlint/KtlintFormatterFunc.java | 21 +- .../KtLintCompat0Dot48Dot0AdapterTest.java | 66 ------ .../resources/empty_class_body.kt | 3 - .../resources/fails_no_semicolons.kt | 3 - .../KtLintCompat0Dot49Dot0AdapterTest.java | 64 ------ .../resources/EmptyClassBody.kt | 3 - .../resources/FailsNoSemicolons.kt | 3 - .../KtLintCompat0Dot50Dot0AdapterTest.java | 64 ------ .../resources/EmptyClassBody.kt | 3 - .../resources/FailsNoSemicolons.kt | 3 - plugin-gradle/CHANGES.md | 2 + plugin-maven/CHANGES.md | 2 + .../spotless/kotlin/KtLintStepTest.java | 46 +--- 18 files changed, 10 insertions(+), 822 deletions(-) delete mode 100644 lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java delete mode 100644 lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java delete mode 100644 lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java delete mode 100644 lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java delete mode 100644 lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt delete mode 100644 lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt delete mode 100644 lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java delete mode 100644 lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt delete mode 100644 lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt delete mode 100644 lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java delete mode 100644 lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt delete mode 100644 lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt diff --git a/CHANGES.md b/CHANGES.md index 704c7b9364..ef02491061 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Bump default `ktfmt` version to latest `0.58` -> `0.59`. ([#2681](https://github.com/diffplug/spotless/pull/2681) ### Fixed - palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685)) +### Removed +* **BREAKING** Drop support for older Ktlint versions. ([#2711](https://github.com/diffplug/spotless/pull/2711)) ## [4.0.0] - 2025-09-24 ### Changes diff --git a/lib/build.gradle b/lib/build.gradle index 308871cfbb..e5262fb545 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -47,9 +47,6 @@ versionCompatibility { // we will support no more than 2 breaking changes at a time = 3 incompatible versions // we will try to drop down to only one version if a stable API can be maintained for a full year versions = [ - '0.48.0', - '0.49.0', - '0.50.0', '1.0.0', ] targetSourceSetName = 'ktlint' @@ -110,18 +107,6 @@ dependencies { strictly '1.7' // for JDK 8 compatibility } } - // ktlint oldest supported version - 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' - // ktlint previous supported version - compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0' - compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0' - compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.17' - // ktlint previous supported version - compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.50.0' - compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.50.0' - compatKtLint0Dot50Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.17' // ktlint latest supported version compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:1.0.0' compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:1.0.0' diff --git a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java b/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java deleted file mode 100644 index ce1a21d69d..0000000000 --- a/lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2023-2025 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 java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -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.RuleSetProviderV2; -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 kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; - -public class KtLintCompat0Dot48Dot0Adapter implements KtLintCompatAdapter { - - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; - - static { - //noinspection deprecation - DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( - CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), - DisabledRulesEditorConfigPropertyKt.getDISABLED_RULES_PROPERTY(), - DisabledRulesEditorConfigPropertyKt.getKTLINT_DISABLED_RULES_PROPERTY(), - IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), - IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), - InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), - MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); - } - - static class FormatterCallback implements Function2 { - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId(), lint.getDetail()); - } - return Unit.INSTANCE; - } - } - - @Override - public String format( - String unix, - Path path, - Path editorConfigPath, - Map editorConfigOverrideMap) { - final FormatterCallback formatterCallback = new FormatterCallback(); - - Set allRuleProviders = ServiceLoader.load(RuleSetProviderV2.class, RuleSetProviderV2.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); - - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); - } else { - editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( - RuleProvider::createNewRuleInstance).collect( - Collectors.toList()), - editorConfigOverrideMap); - } - EditorConfigDefaults editorConfig; - if (editorConfigPath == null || !Files.exists(editorConfigPath)) { - editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - } else { - editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath); - } - - return new KtLintRuleEngine( - allRuleProviders, - editorConfig, - editorConfigOverride, - false) - .format(unix, path, formatterCallback); - } - - /** - * Create EditorConfigOverride from user provided parameters. - */ - private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rules.stream() - .filter(UsesEditorConfigProperties.class::isInstance) - .flatMap(rule -> ((UsesEditorConfigProperties) rule).getEditorConfigProperties().stream()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) - .distinct() - .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - EditorConfigProperty property = supportedProperties.get(entry.getKey()); - - if (property == null && 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); - } - } - - if (property == null) { - return null; - } else { - return new Pair<>(property, entry.getValue()); - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(properties); - } -} diff --git a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java b/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java deleted file mode 100644 index 7e515cd62d..0000000000 --- a/lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2023-2025 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 java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; -import com.pinterest.ktlint.rule.engine.api.Code; -import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; -import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; -import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; -import com.pinterest.ktlint.rule.engine.api.LintError; -import com.pinterest.ktlint.rule.engine.core.api.Rule; -import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; -import com.pinterest.ktlint.rule.engine.core.api.RuleProviderKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; - -import kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; - -public class KtLintCompat0Dot49Dot0Adapter implements KtLintCompatAdapter { - - private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot49Dot0Adapter.class); - - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; - - static { - DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( - CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), - EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(), - IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), - IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), - InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), - MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(), - RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); - } - - private static final Method RULEID_METHOD; - private static final Method CREATE_RULESET_EXECUTION_METHOD; - private static final Method CREATE_RULE_EXECUTION_METHOD; - - static { - try { - RULEID_METHOD = LintError.class.getMethod("getRuleId-6XN97os"); - CREATE_RULESET_EXECUTION_METHOD = RuleExecutionEditorConfigPropertyKt.class.getMethod("createRuleSetExecutionEditorConfigProperty-fqiwTpU", String.class, RuleExecution.class); - CREATE_RULE_EXECUTION_METHOD = RuleExecutionEditorConfigPropertyKt.class.getMethod("createRuleExecutionEditorConfigProperty-U7AdEiY", String.class, RuleExecution.class); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - private static String getRuleId(LintError lint) { - try { - return (String) RULEID_METHOD.invoke(lint); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - private static EditorConfigProperty createRuleSetExecution(String id, RuleExecution execution) { - try { - return (EditorConfigProperty) CREATE_RULESET_EXECUTION_METHOD.invoke(null, id, execution); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - private static EditorConfigProperty createRuleExecution(String id, RuleExecution execution) { - try { - return (EditorConfigProperty) CREATE_RULE_EXECUTION_METHOD.invoke(null, id, execution); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - static class FormatterCallback implements Function2 { - - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - KtLintCompatReporting.report(lint.getLine(), lint.getCol(), getRuleId(lint), lint.getDetail()); - } - return Unit.INSTANCE; - } - } - - @Override - public String format( - String unix, - Path path, - Path editorConfigPath, - Map editorConfigOverrideMap) { - final FormatterCallback formatterCallback = new FormatterCallback(); - - Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); - - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); - } else { - editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( - RuleProvider::createNewRuleInstance).collect(Collectors.toList()), - editorConfigOverrideMap); - } - EditorConfigDefaults editorConfig; - if (editorConfigPath == null || !Files.exists(editorConfigPath)) { - editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - } else { - editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); - } - - // create Code and then set the content to match previous steps in the Spotless pipeline - Code code = Code.Companion.fromPath(path); - KtLintCompatAdapter.setCodeContent(code, unix); - return new KtLintRuleEngine( - allRuleProviders, - editorConfig, - editorConfigOverride, - false, - path.getFileSystem()) - .format(code, formatterCallback); - } - - /** - * Create EditorConfigOverride from user provided parameters. - */ - private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rules.stream() - .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) - .distinct() - .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - EditorConfigProperty property = supportedProperties.get(entry.getKey()); - - if (property == null && entry.getKey().startsWith("ktlint_")) { - String[] parts = entry.getKey().substring(7).split("_", 2); - if (parts.length == 1) { - // convert ktlint_{ruleset} to {ruleset} - String id = parts[0]; - property = createRuleSetExecution(id, RuleExecution.enabled); - } else { - // convert ktlint_{ruleset}_{rulename} to {ruleset}:{rulename} - String id = parts[0] + ":" + parts[1]; - property = createRuleExecution(id, RuleExecution.enabled); - } - } - - if (property == null) { - return null; - } else { - return new Pair<>(property, entry.getValue()); - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(properties); - } -} diff --git a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java b/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java deleted file mode 100644 index 437b9579bd..0000000000 --- a/lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2023-2025 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 java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.ServiceLoader; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; -import com.pinterest.ktlint.rule.engine.api.Code; -import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; -import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; -import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; -import com.pinterest.ktlint.rule.engine.api.LintError; -import com.pinterest.ktlint.rule.engine.core.api.Rule; -import com.pinterest.ktlint.rule.engine.core.api.RuleId; -import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; -import com.pinterest.ktlint.rule.engine.core.api.RuleProviderKt; -import com.pinterest.ktlint.rule.engine.core.api.RuleSetId; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; -import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; - -import kotlin.Pair; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; - -public class KtLintCompat0Dot50Dot0Adapter implements KtLintCompatAdapter { - - private static final Logger LOGGER = LoggerFactory.getLogger(KtLintCompat0Dot50Dot0Adapter.class); - - private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; - - static { - DEFAULT_EDITOR_CONFIG_PROPERTIES = List.of( - CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY(), - EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY(), - IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY(), - IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY(), - InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY(), - MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY(), - RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); - } - - static class FormatterCallback implements Function2 { - - @Override - public Unit invoke(LintError lint, Boolean corrected) { - if (!corrected) { - KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId().getValue(), lint.getDetail()); - } - return Unit.INSTANCE; - } - } - - @Override - public String format( - String unix, - Path path, - Path editorConfigPath, - Map editorConfigOverrideMap) { - final FormatterCallback formatterCallback = new FormatterCallback(); - - Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) - .stream() - .flatMap(loader -> loader.get().getRuleProviders().stream()) - .collect(Collectors.toUnmodifiableSet()); - - EditorConfigOverride editorConfigOverride; - if (editorConfigOverrideMap.isEmpty()) { - editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); - } else { - editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( - RuleProvider::createNewRuleInstance).collect(Collectors.toList()), - editorConfigOverrideMap); - } - EditorConfigDefaults editorConfig; - if (editorConfigPath == null || !Files.exists(editorConfigPath)) { - editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); - } else { - editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); - } - - // create Code and then set the content to match previous steps in the Spotless pipeline - Code code = Code.Companion.fromPath(path); - KtLintCompatAdapter.setCodeContent(code, unix); - return new KtLintRuleEngine( - allRuleProviders, - editorConfig, - editorConfigOverride, - true, - false, - path.getFileSystem()) - .format(code, formatterCallback); - } - - /** - * Create EditorConfigOverride from user provided parameters. - */ - private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { - // Get properties from rules in the rule sets - Stream> ruleProperties = rules.stream() - .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); - - // Create a mapping of properties to their names based on rule properties and default properties - Map> supportedProperties = Stream - .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) - .distinct() - .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); - - // Create config properties based on provided property names and values - @SuppressWarnings("unchecked") - Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() - .map(entry -> { - EditorConfigProperty property = supportedProperties.get(entry.getKey()); - - if (property == null && entry.getKey().startsWith("ktlint_")) { - String[] parts = entry.getKey().substring(7).split("_", 2); - if (parts.length == 1) { - // convert ktlint_{ruleset} to RuleSetId - RuleSetId id = new RuleSetId(parts[0]); - property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled); - } else { - // convert ktlint_{ruleset}_{rulename} to RuleId - RuleId id = new RuleId(parts[0] + ":" + parts[1]); - property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled); - } - } - - if (property == null) { - return null; - } else { - return new Pair<>(property, entry.getValue()); - } - }) - .filter(Objects::nonNull) - .toArray(Pair[]::new); - - return EditorConfigOverride.Companion.from(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 78a2e481c8..eb3a175fc4 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 @@ -22,9 +22,6 @@ import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.FormatterFunc; import com.diffplug.spotless.Lint; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot48Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot49Dot0Adapter; -import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat0Dot50Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompat1Dot0Dot0Adapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatAdapter; import com.diffplug.spotless.glue.ktlint.compat.KtLintCompatReporting; @@ -40,26 +37,10 @@ public KtlintFormatterFunc( Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); - int minorVersion = Integer.parseInt(versions[1]); if (majorVersion == 1) { this.adapter = new KtLintCompat1Dot0Dot0Adapter(); } else { - if (minorVersion >= 50) { - // Fixed `RuleId` and `RuleSetId` issues - // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing - // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point - this.adapter = new KtLintCompat0Dot50Dot0Adapter(); - } else if (minorVersion == 49) { - // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) - // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property - // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 - this.adapter = new KtLintCompat0Dot49Dot0Adapter(); - } else if (minorVersion == 48) { - // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); - } else { - throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); - } + throw new IllegalStateException("Ktlint versions < 1.0.0 not supported!"); } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; 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 deleted file mode 100644 index 9c6d31c5a1..0000000000 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2023-2025 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; -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; - -public class KtLintCompat0Dot48Dot0AdapterTest { - @Test - public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - var content = loadAndWriteText(path, "empty_class_body.kt"); - final Path filePath = Path.of(path.toString(), "empty_class_body.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); - assertEquals("class empty_class_body\n", formatted); - } - - @Test - public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - var content = loadAndWriteText(path, "fails_no_semicolons.kt"); - final Path filePath = Path.of(path.toString(), "fails_no_semicolons.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - // ktlint_filename is an invalid rule in ktlint 0.48.0 - editorConfigOverrideMap.put("ktlint_filename", "disabled"); - - String formatted = ktLintCompat0Dot48Dot0Adapter.format(content, filePath, null, 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 Files.readString(path.resolve(name)); - } - -} diff --git a/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt deleted file mode 100644 index b84774d572..0000000000 --- a/lib/src/testCompatKtLint0Dot48Dot0/resources/empty_class_body.kt +++ /dev/null @@ -1,3 +0,0 @@ -class empty_class_body { - -} diff --git a/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt b/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt deleted file mode 100644 index 20ab460913..0000000000 --- a/lib/src/testCompatKtLint0Dot48Dot0/resources/fails_no_semicolons.kt +++ /dev/null @@ -1,3 +0,0 @@ -class fails_no_semicolons { - val i = 0; -} diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java deleted file mode 100644 index d7128e1d54..0000000000 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2023-2025 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; -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; - -public class KtLintCompat0Dot49Dot0AdapterTest { - @Test - public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - var content = loadAndWriteText(path, "EmptyClassBody.kt"); - final Path filePath = Path.of(path.toString(), "EmptyClassBody.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - - String formatted = ktLintCompat0Dot49Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); - assertEquals("class EmptyClassBody\n", formatted); - } - - @Test - public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - var content = loadAndWriteText(path, "FailsNoSemicolons.kt"); - final Path filePath = Path.of(path.toString(), "FailsNoSemicolons.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - - String formatted = ktLintCompat0Dot49Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); - assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); - } - - private static String loadAndWriteText(Path path, String name) throws IOException { - try (InputStream is = KtLintCompat0Dot49Dot0AdapterTest.class.getResourceAsStream("/" + name)) { - Files.copy(is, path.resolve(name)); - } - return Files.readString(path.resolve(name)); - } - -} diff --git a/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt deleted file mode 100644 index 7da53fb78d..0000000000 --- a/lib/src/testCompatKtLint0Dot49Dot0/resources/EmptyClassBody.kt +++ /dev/null @@ -1,3 +0,0 @@ -class EmptyClassBody { - -} diff --git a/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt deleted file mode 100644 index 4cf05ceacf..0000000000 --- a/lib/src/testCompatKtLint0Dot49Dot0/resources/FailsNoSemicolons.kt +++ /dev/null @@ -1,3 +0,0 @@ -class FailsNoSemicolons { - val i = 0; -} diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java deleted file mode 100644 index 81698b44db..0000000000 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2023-2025 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; -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; - -public class KtLintCompat0Dot50Dot0AdapterTest { - @Test - public void testDefaults(@TempDir Path path) throws IOException { - KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - var content = loadAndWriteText(path, "EmptyClassBody.kt"); - final Path filePath = Path.of(path.toString(), "EmptyClassBody.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - - String formatted = KtLintCompat0Dot50Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); - assertEquals("class EmptyClassBody\n", formatted); - } - - @Test - public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { - KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - var content = loadAndWriteText(path, "FailsNoSemicolons.kt"); - final Path filePath = Path.of(path.toString(), "FailsNoSemicolons.kt"); - - Map editorConfigOverrideMap = new HashMap<>(); - editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - - String formatted = KtLintCompat0Dot50Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); - assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); - } - - private static String loadAndWriteText(Path path, String name) throws IOException { - try (InputStream is = KtLintCompat0Dot50Dot0AdapterTest.class.getResourceAsStream("/" + name)) { - Files.copy(is, path.resolve(name)); - } - return Files.readString(path.resolve(name)); - } - -} diff --git a/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt deleted file mode 100644 index 7da53fb78d..0000000000 --- a/lib/src/testCompatKtLint0Dot50Dot0/resources/EmptyClassBody.kt +++ /dev/null @@ -1,3 +0,0 @@ -class EmptyClassBody { - -} diff --git a/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt deleted file mode 100644 index 4cf05ceacf..0000000000 --- a/lib/src/testCompatKtLint0Dot50Dot0/resources/FailsNoSemicolons.kt +++ /dev/null @@ -1,3 +0,0 @@ -class FailsNoSemicolons { - val i = 0; -} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 987999e6d5..29cd9e8a93 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Use absolute path in the git pre push hook ### Fixed - palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685)) +### Removed +* **BREAKING** Drop support for older Ktlint versions. ([#2711](https://github.com/diffplug/spotless/pull/2711)) ## [8.0.0] - 2025-09-24 ### Changed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index fc51b506ef..eb2508f427 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,6 +8,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Use absolute path in the git pre push hook ### Fixed - palantirJavaFormat is no longer arbitrarily set to outdated versions on Java 17, latest available version is always used ([#2686](https://github.com/diffplug/spotless/pull/2686) fixes [#2685](https://github.com/diffplug/spotless/issues/2685)) +### Removed +* **BREAKING** Drop support for older Ktlint versions. ([#2711](https://github.com/diffplug/spotless/pull/2711)) ## [3.0.0] - 2025-09-24 ### Changes 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 0d520b8b0c..6fbef25a76 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 DiffPlug + * Copyright 2016-2025 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,46 +24,6 @@ import com.diffplug.spotless.TestProvisioner; class KtLintStepTest extends ResourceHarness { - @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-old.clean") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(no-wildcard-imports) Wildcard import"); - } - - @Test - 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-old.clean") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(no-wildcard-imports) Wildcard import"); - } - - @Test - void works0_49_0() { - FormatterStep step = KtLintStep.create("0.49.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import"); - } - - @Test - void works0_49_1() { - FormatterStep step = KtLintStep.create("0.49.1", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic-old.clean") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import"); - } - - @Test - void works0_50_0() { - FormatterStep step = KtLintStep.create("0.50.0", TestProvisioner.mavenCentral()); - StepHarnessWithFile.forStep(this, step) - .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") - .expectLintsOfResource("kotlin/ktlint/unsolvable.dirty").toBe("L1 ktlint(standard:no-wildcard-imports) Wildcard import"); - } - @Test void works1_0_0() { FormatterStep step = KtLintStep.create("1.0.0", TestProvisioner.mavenCentral()); @@ -83,14 +43,14 @@ void behavior() { @Test void equality() { new SerializableEqualityTester() { - String version = "0.48.0"; + String version = "1.0.0"; @Override protected void setupTest(API api) { // same version == same api.areDifferentThan(); // change the version, and it's different - version = "0.48.1"; + version = "1.0.1"; api.areDifferentThan(); }