From 83ad9774a18f20621e09307f6fca30d1e20aed78 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 17:24:04 +0300 Subject: [PATCH 01/10] Upgrade diktat to 1.2.0 --- lib/build.gradle | 2 +- .../glue/diktat/DiktatFormatterFunc.java | 13 ++++----- .../diffplug/spotless/kotlin/DiktatStep.java | 28 ++++++------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 2eb0f3e0e5..97897b68bb 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -51,7 +51,7 @@ dependencies { ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-experimental:$VER_KTLINT" ktlintCompileOnly "com.pinterest.ktlint:ktlint-ruleset-standard:$VER_KTLINT" - String VER_DIKTAT = "1.1.0" + String VER_DIKTAT = "1.2.0" diktatCompileOnly "org.cqfn.diktat:diktat-rules:$VER_DIKTAT" // used for markdown formatting diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java index 1374bebb10..5a5762f4b6 100644 --- a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -20,8 +20,8 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider; +import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.KtLint; -import com.pinterest.ktlint.core.KtLint.Params; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; @@ -33,15 +33,13 @@ public class DiktatFormatterFunc implements FormatterFunc.NeedsFile { private final List rulesets; - private final Map userData; private final Function2 formatterCallback; private final boolean isScript; private final ArrayList errors = new ArrayList<>(); - public DiktatFormatterFunc(boolean isScript, Map userData) { + public DiktatFormatterFunc(boolean isScript) { rulesets = Collections.singletonList(new DiktatRuleSetProvider().get()); - this.userData = userData; this.formatterCallback = new FormatterCallback(errors); this.isScript = isScript; } @@ -65,17 +63,18 @@ public Unit invoke(LintError lintError, Boolean corrected) { @Override public String applyWithFile(String unix, File file) throws Exception { errors.clear(); - userData.put("file_path", file.getAbsolutePath()); - String result = KtLint.INSTANCE.format(new Params( + String result = KtLint.INSTANCE.format(new KtLint.ExperimentalParams( // Unlike Ktlint, Diktat requires full path to the file. // See https://github.com/diffplug/spotless/issues/1189, https://github.com/analysis-dev/diktat/issues/1202 file.getAbsolutePath(), unix, rulesets, - userData, + Collections.emptyMap(), formatterCallback, isScript, null, + false, + new EditorConfigOverride(), false)); if (!errors.isEmpty()) { diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index e01748d4b5..7533652243 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,7 +30,7 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String DEFAULT_VERSION = "1.1.0"; + private static final String DEFAULT_VERSION = "1.2.0"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; @@ -44,30 +44,22 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String versionDiktat, Provisioner provisioner) { - return create(versionDiktat, provisioner, Collections.emptyMap(), null); + return create(versionDiktat, provisioner, null); } public static FormatterStep create(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, Collections.emptyMap(), config); - } - - public static FormatterStep create(String versionDiktat, Provisioner provisioner, Map userData, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, false, userData, config); + return create(versionDiktat, provisioner, false, config); } public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return createForScript(versionDiktat, provisioner, Collections.emptyMap(), config); - } - - public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, Map userData, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, true, userData, config); + return create(versionDiktat, provisioner, true, config); } - public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, Map userData, @Nullable FileSignature config) { + public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new DiktatStep.State(versionDiktat, provisioner, isScript, userData, config), + () -> new DiktatStep.State(versionDiktat, provisioner, isScript, config), DiktatStep.State::createFormat); } @@ -79,14 +71,12 @@ static final class State implements Serializable { private final boolean isScript; private final @Nullable FileSignature config; final JarState jar; - private final TreeMap userData; - State(String versionDiktat, Provisioner provisioner, boolean isScript, Map userData, @Nullable FileSignature config) throws IOException { + State(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) throws IOException { HashSet pkgSet = new HashSet<>(); pkgSet.add(MAVEN_COORDINATE + versionDiktat); - this.userData = new TreeMap<>(userData); this.jar = JarState.from(pkgSet, provisioner); this.isScript = isScript; this.config = config; @@ -98,8 +88,8 @@ FormatterFunc createFormat() throws Exception { } Class formatterFunc = jar.getClassLoader().loadClass("com.diffplug.spotless.glue.diktat.DiktatFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(boolean.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(isScript, userData); + Constructor constructor = formatterFunc.getConstructor(boolean.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(isScript); } } } From e9a9b9e31c1ec26cb6dbefde579826ec21c2272c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 17:32:18 +0300 Subject: [PATCH 02/10] Update CHANGES.md --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8e0d2c74d5..c9b2a9fa70 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 178b8ec39b..2244b0dfad 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f6c5bcc84e..4d75eae40b 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) +### Fixed +* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) ## [2.22.8] - 2022-06-11 ### Fixed From f65b13691c9142f151f8ff4a96fa09a160e8b673 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 18:01:41 +0300 Subject: [PATCH 03/10] fixed compile and static issue --- .../com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java | 2 +- .../main/java/com/diffplug/spotless/maven/kotlin/Diktat.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java index 5a5762f4b6..0b9d115c2b 100644 --- a/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java +++ b/lib/src/diktat/java/com/diffplug/spotless/glue/diktat/DiktatFormatterFunc.java @@ -20,10 +20,10 @@ import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider; -import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.pinterest.ktlint.core.KtLint; import com.pinterest.ktlint.core.LintError; import com.pinterest.ktlint.core.RuleSet; +import com.pinterest.ktlint.core.api.EditorConfigOverride; import com.diffplug.spotless.FormatterFunc; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java index 97cbec07b2..13d600e11f 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java @@ -41,6 +41,6 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { config = ThrowingEx.get(() -> FileSignature.signAsList(stepConfig.getFileLocator().locateFile(configFile))); } String diktatVersion = version != null ? version : DiktatStep.defaultVersionDiktat(); - return DiktatStep.create(diktatVersion, stepConfig.getProvisioner(), Collections.emptyMap(), config); + return DiktatStep.create(diktatVersion, stepConfig.getProvisioner(), config); } } From 5c42c00f67f44057f04bf90afbe62fc8a9bf9e43 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 18:45:35 +0300 Subject: [PATCH 04/10] fixed integration tests --- .../main/resources/kotlin/diktat/main.clean | 6 +++--- .../main/resources/kotlin/diktat/main.dirty | 6 +++--- .../spotless/kotlin/DiktatStepTest.java | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/testlib/src/main/resources/kotlin/diktat/main.clean b/testlib/src/main/resources/kotlin/diktat/main.clean index 4405165ed5..c46b4542b0 100644 --- a/testlib/src/main/resources/kotlin/diktat/main.clean +++ b/testlib/src/main/resources/kotlin/diktat/main.clean @@ -1,7 +1,7 @@ package org.cqfn.diktat.example.gradle.multiproject /** - * @return print. + * @return something */ class Main { /** @@ -9,7 +9,7 @@ class Main { * */ fun foo() { - println(";") - println() + bar(";") + bar() } } diff --git a/testlib/src/main/resources/kotlin/diktat/main.dirty b/testlib/src/main/resources/kotlin/diktat/main.dirty index 5f7be993aa..a5c225cc4f 100644 --- a/testlib/src/main/resources/kotlin/diktat/main.dirty +++ b/testlib/src/main/resources/kotlin/diktat/main.dirty @@ -1,6 +1,6 @@ package org.cqfn.diktat.example.gradle.multiproject /** - * @return print. + * @return something */ class Main { /** @@ -8,7 +8,7 @@ class Main { * */ fun foo() { - println(";") - println(); + bar(";") + bar(); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 24a79ed61b..c19f1dc45a 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -36,11 +36,15 @@ void behavior() throws Exception { StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 2 unfixed errors:" + + assertion.hasMessage("There are 4 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); }); } @@ -51,15 +55,19 @@ void behaviorConf() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.0.1", TestProvisioner.mavenCentral(), Collections.emptyMap(), config); + FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); - assertion.hasMessage("There are 2 unfixed errors:" + + assertion.hasMessage("There are 4 unfixed errors:" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + System.lineSeparator() + "[FILE_NAME_INCORRECT] file name is incorrect - it should end with .kt extension and be in PascalCase: testlib" + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + - System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable"); + System.lineSeparator() + "[FILE_NAME_MATCH_CLASS] file name is incorrect - it should match with the class described in it if there is the only one class declared: testlib vs Unsolvable" + + System.lineSeparator() + "Error on line: 1, column: 1 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()" + + System.lineSeparator() + "Error on line: 13, column: 9 cannot be fixed automatically" + + System.lineSeparator() + "[DEBUG_PRINT] use a dedicated logging library: found println()"); }); } From f6de4bb1ab49b4f948f37d186cd04032b16e2a00 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 24 Jun 2022 19:38:51 +0300 Subject: [PATCH 05/10] fixed year in javadoc --- .../main/java/com/diffplug/spotless/maven/kotlin/Diktat.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java index 13d600e11f..e47345d45d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Diktat.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2022 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,6 @@ */ package com.diffplug.spotless.maven.kotlin; -import java.util.Collections; - import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FileSignature; From 6d1e35db09f50aebbedc4bcdf8d0dc9234d06e27 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 28 Jun 2022 20:51:08 +0300 Subject: [PATCH 06/10] bump diktat to 1.2.1 and add validation of min version --- CHANGES.md | 4 +++- .../com/diffplug/spotless/kotlin/DiktatStep.java | 7 ++++++- plugin-gradle/CHANGES.md | 4 +++- plugin-maven/CHANGES.md | 4 +++- .../diffplug/spotless/kotlin/DiktatStepTest.java | 16 +++++++++++++--- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c9b2a9fa70..760595e88c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 7533652243..94921a99bd 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,7 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String DEFAULT_VERSION = "1.2.0"; + private static final String MIN_SUPPORTED_VERSION = "1.2.1"; + + private static final String DEFAULT_VERSION = "1.2.1"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; @@ -56,6 +58,9 @@ public static FormatterStep createForScript(String versionDiktat, Provisioner pr } public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { + if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { + throw new IllegalStateException("Diktat supported for version " + MIN_SUPPORTED_VERSION + " and later"); + } Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 2244b0dfad..05bd5f7ce6 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,7 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4d75eae40b..259cab1017 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,7 +6,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.0`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) +* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) + * Note that support `diktat` version `1.2.1` is or higher + * The property `userData` is removed ## [2.22.8] - 2022-06-11 ### Fixed diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index c19f1dc45a..c37289c6e6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -18,8 +18,8 @@ import static com.diffplug.spotless.FileSignature.signAsList; import java.io.File; -import java.util.Collections; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import com.diffplug.spotless.FileSignature; @@ -50,12 +50,11 @@ void behavior() throws Exception { @Test void behaviorConf() throws Exception { - String configPath = "src/main/kotlin/diktat-analysis.yml"; File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); + FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); @@ -71,4 +70,15 @@ void behaviorConf() throws Exception { }); } + @Test + void notSupportedVersion() { + final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, + () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + Assertions.assertTrue( + notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later") + ); + + Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); + Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); + } } From cfe2cf41af4062d4d374539e8aa68850fadf7619 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:10:56 -0700 Subject: [PATCH 07/10] Change the verbiage around minimum required version. --- CHANGES.md | 7 +++---- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 2 +- plugin-gradle/CHANGES.md | 7 +++---- plugin-maven/CHANGES.md | 7 +++---- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 760595e88c..3a415d83ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,10 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index 94921a99bd..ff3e3240cf 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -59,7 +59,7 @@ public static FormatterStep createForScript(String versionDiktat, Provisioner pr public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { - throw new IllegalStateException("Diktat supported for version " + MIN_SUPPORTED_VERSION + " and later"); + throw new IllegalStateException("Minimum required Diktat version is " + MIN_SUPPORTED_VERSION + ", you tried " + versionDiktat + " which is too old"); } Objects.requireNonNull(versionDiktat, "versionDiktat"); Objects.requireNonNull(provisioner, "provisioner"); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 05bd5f7ce6..266c0ac151 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -5,10 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 259cab1017..25aec044fc 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -5,10 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) -### Fixed -* Bump default `diktat` version to latest `1.1.0` -> `1.2.1`. ([saveourtool/diktat#1399](https://github.com/saveourtool/diktat/issues/1399)) - * Note that support `diktat` version `1.2.1` is or higher - * The property `userData` is removed +### Changed +* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.1` ## [2.22.8] - 2022-06-11 ### Fixed From e3e0beb4661e491b6935e44ed1f19e97c29cad09 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:11:08 -0700 Subject: [PATCH 08/10] spotlessApply --- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index c37289c6e6..0075aed162 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -73,10 +73,9 @@ void behaviorConf() throws Exception { @Test void notSupportedVersion() { final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, - () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); Assertions.assertTrue( - notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later") - ); + notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later")); Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); From 3022df74439315487e60149d72ee3f4e1ab9cc55 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 16:35:11 -0700 Subject: [PATCH 09/10] Bump diktat down to latest published version, 1.2.0 --- CHANGES.md | 4 ++-- .../main/java/com/diffplug/spotless/kotlin/DiktatStep.java | 4 ++-- plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 4 ++-- .../java/com/diffplug/spotless/kotlin/DiktatStepTest.java | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a415d83ca..0512418d94 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,8 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [2.26.2] - 2022-06-11 ### Fixed diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index ff3e3240cf..92dcd8f51c 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -30,9 +30,9 @@ public class DiktatStep { // prevent direct instantiation private DiktatStep() {} - private static final String MIN_SUPPORTED_VERSION = "1.2.1"; + private static final String MIN_SUPPORTED_VERSION = "1.2.0"; - private static final String DEFAULT_VERSION = "1.2.1"; + private static final String DEFAULT_VERSION = "1.2.0"; static final String NAME = "diktat"; static final String PACKAGE_DIKTAT = "org.cqfn.diktat"; static final String MAVEN_COORDINATE = PACKAGE_DIKTAT + ":diktat-rules:"; diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 266c0ac151..69844c1daa 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,8 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [6.7.2] - 2022-06-11 ### Fixed diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 25aec044fc..63c121a007 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,8 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support for `MAC_CLASSIC` (`\r`) line ending ([#1243](https://github.com/diffplug/spotless/pull/1243) fixes [#1196](https://github.com/diffplug/spotless/issues/1196)) ### Changed -* Minimum required `diktat` version bumped to `1.2.1` ([#1246](https://github.com/diffplug/spotless/pull/1246)) - * Default bumped from `1.1.0` -> `1.2.1` +* Minimum required `diktat` version bumped to `1.2.0` ([#1246](https://github.com/diffplug/spotless/pull/1246)) + * Default bumped from `1.1.0` -> `1.2.0` ## [2.22.8] - 2022-06-11 ### Fixed diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java index 0075aed162..2a955f16cb 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/DiktatStepTest.java @@ -54,7 +54,7 @@ void behaviorConf() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); FileSignature config = signAsList(conf); - FormatterStep step = DiktatStep.create("1.2.1", TestProvisioner.mavenCentral(), config); + FormatterStep step = DiktatStep.create("1.2.0", TestProvisioner.mavenCentral(), config); StepHarness.forStep(step) .testResourceException("kotlin/diktat/Unsolvable.kt", assertion -> { assertion.isInstanceOf(AssertionError.class); @@ -73,9 +73,9 @@ void behaviorConf() throws Exception { @Test void notSupportedVersion() { final IllegalStateException notSupportedException = Assertions.assertThrows(IllegalStateException.class, - () -> DiktatStep.create("1.2.0", TestProvisioner.mavenCentral())); + () -> DiktatStep.create("1.1.0", TestProvisioner.mavenCentral())); Assertions.assertTrue( - notSupportedException.getMessage().contains("Diktat supported for version 1.2.1 and later")); + notSupportedException.getMessage().contains("Minimum required Diktat version is 1.2.0, you tried 1.1.0 which is too old")); Assertions.assertDoesNotThrow(() -> DiktatStep.create("1.2.1", TestProvisioner.mavenCentral())); Assertions.assertDoesNotThrow(() -> DiktatStep.create("2.0.0", TestProvisioner.mavenCentral())); From 9b0cf08d2ea69a1d32e4f5bcd0e910a623e2f779 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 29 Jun 2022 18:45:56 -0700 Subject: [PATCH 10/10] Update the maven tests for Diktat. --- .../java/com/diffplug/spotless/maven/kotlin/DiktatTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java index bd37c5c82e..eccaa7ac2e 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/DiktatTest.java @@ -40,7 +40,7 @@ void testDiktatWithVersion() throws Exception { writePomWithKotlinSteps( "", - " 1.0.1", + " 1.2.0", ""); String path = "src/main/kotlin/Main.kt"; @@ -56,7 +56,7 @@ void testDiktatConfig() throws Exception { File conf = setFile(configPath).toResource("kotlin/diktat/diktat-analysis.yml"); writePomWithKotlinSteps( "", - " 1.0.1", + " 1.2.0", " " + conf.getAbsolutePath() + "", "");