Skip to content

Commit 69e8524

Browse files
committed
Move to 2.1 to fix issue with class detection
1 parent e9efb13 commit 69e8524

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

lib/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
testCommonImplementation "org.junit.jupiter:junit-jupiter:$VER_JUNIT"
5656
testCommonImplementation "org.assertj:assertj-core:$VER_ASSERTJ"
5757
testCommonImplementation "com.diffplug.durian:durian-testlib:$VER_DURIAN"
58+
testCommonImplementation 'io.github.solven-eu.cleanthat:java:2.1'
5859

5960
// used for pom sorting
6061
sortPomCompileOnly 'com.github.ekryd.sortpom:sortpom-sorter:3.0.0'
@@ -102,7 +103,9 @@ dependencies {
102103

103104
gsonCompileOnly 'com.google.code.gson:gson:2.10.1'
104105

105-
cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.0'
106+
// TODO How can one add a test module like 'compatKtLint0Dot48Dot0'?
107+
// cleanthatCompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.1'
108+
cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.1'
106109
}
107110

108111
// we'll hold the core lib to a high standard

lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class CleanthatJavaStep {
3939
private static final String NAME = "cleanthat";
4040
private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java";
4141

42-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.0");
42+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.1");
4343

4444
// prevent direct instantiation
4545
private CleanthatJavaStep() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.glue.java;
17+
18+
import org.assertj.core.api.Assertions;
19+
import org.junit.jupiter.api.Test;
20+
21+
import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer;
22+
23+
public class JavaCleanthatRefactorerFuncTest {
24+
@Test
25+
public void testMutatorsDetection() {
26+
Assertions.assertThat(JavaRefactorer.getAllIncluded()).isNotEmpty();
27+
}
28+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.glue.ktlint.compat;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
25+
import java.nio.file.Paths;
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.io.TempDir;
31+
32+
public class KtLintCompat0Dot48Dot0AdapterTest {
33+
@Test
34+
public void testDefaults(@TempDir Path path) throws IOException {
35+
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
36+
String text = loadAndWriteText(path, "empty_class_body.kt");
37+
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");
38+
39+
Map<String, String> userData = new HashMap<>();
40+
41+
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
42+
43+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
44+
assertEquals("class empty_class_body\n", formatted);
45+
}
46+
47+
@Test
48+
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
49+
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
50+
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
51+
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");
52+
53+
Map<String, String> userData = new HashMap<>();
54+
55+
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
56+
editorConfigOverrideMap.put("indent_style", "tab");
57+
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
58+
// ktlint_filename is an invalid rule in ktlint 0.48.0
59+
editorConfigOverrideMap.put("ktlint_filename", "disabled");
60+
61+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, false, null, userData, editorConfigOverrideMap);
62+
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
63+
}
64+
65+
private static String loadAndWriteText(Path path, String name) throws IOException {
66+
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) {
67+
Files.copy(is, path.resolve(name));
68+
}
69+
return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8);
70+
}
71+
72+
}

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void testIncludeOnlyLiteralsFirstInComparisons() throws Exception {
7070
private void runTest(String dirtyPath, String cleanPath) throws Exception {
7171
String path = "src/main/java/test.java";
7272
setFile(path).toResource("java/cleanthat/" + dirtyPath);
73-
Assertions.assertThat(mavenRunner().withArguments("spotless:apply -X").runNoError().stdOutUtf8()).isEmpty();
73+
Assertions.assertThat(mavenRunner().withArguments("spotless:apply").withRemoteDebug(21654).runNoError().stdOutUtf8()).doesNotContain("[ERROR]");
7474
assertFile(path).sameAsResource("java/cleanthat/" + cleanPath);
7575
}
7676
}

0 commit comments

Comments
 (0)