-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ktlint 0.48 #1456
Fix ktlint 0.48 #1456
Changes from 10 commits
6dc01fa
4550b66
2936d3c
41c3fe9
954e6b5
1a19da1
11971ab
b853169
b6e9073
6b2e2c3
778f485
3409754
2eebed3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
|
@@ -105,10 +105,16 @@ 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) | ||
|
||
test { useJUnitPlatform() } | ||
tasks.withType(Test).configureEach { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good (other than also being required) :) |
||
useJUnitPlatform() | ||
} | ||
|
||
jar { | ||
for (glue in NEEDS_GLUE) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.charset.StandardCharsets; | ||
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(); | ||
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you say about extracting this into a utility function? As far as I can tell, it's just a fairly condensed way of getting a String from a Java resource, but it's still verbose when it's duplicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could inline the input, considering I inlined the formatting result. EDIT: Utility function ended up being easier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even easier :) |
||
Files.copy(is, path.resolve("empty_class_body.kt")); | ||
} | ||
String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); | ||
|
||
Map<String, String> userData = new HashMap<>(); | ||
|
||
Map<String, Object> editorConfigOverrideMap = new HashMap<>(); | ||
|
||
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 { | ||
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); | ||
|
||
Map<String, String> userData = new HashMap<>(); | ||
|
||
Map<String, Object> editorConfigOverrideMap = new HashMap<>(); | ||
editorConfigOverrideMap.put("indent_style", "tab"); | ||
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); | ||
|
||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class empty_class_body { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class fails_no_semicolons { | ||
val i = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer be necessary with version 0.4.0 of the version-compatibility-plugin, if the
compatKtLint0Dot48Dot0CompileOnly
is changed toompatKtLint0Dot48Dot0CompileAndTestOnly
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used the latest plugin to clean this up. Thanks for the new configuration!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I'm happy to improve the plugin :) I also improved the plugin documentation, fyi.