-
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 8 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 |
---|---|---|
|
@@ -34,7 +34,7 @@ versionCompatibility { | |
'0.45.2', | ||
'0.46.0', | ||
'0.47.0', | ||
'0.48.0', | ||
'0.48.1', | ||
] | ||
targetSourceSetName = 'ktlint' | ||
} | ||
|
@@ -91,9 +91,9 @@ dependencies { | |
compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.47.0' | ||
compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.47.0' | ||
compatKtLint0Dot47Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.47.0' | ||
compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.0' | ||
compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.0' | ||
compatKtLint0Dot48Dot0CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.0' | ||
compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-core:0.48.1' | ||
compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-experimental:0.48.1' | ||
compatKtLint0Dot48Dot1CompileOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.48.1' | ||
|
||
String VER_SCALAFMT="3.6.1" | ||
scalafmtCompileOnly "org.scalameta:scalafmt-core_2.13:$VER_SCALAFMT" | ||
|
@@ -105,10 +105,16 @@ dependencies { | |
flexmarkCompileOnly 'com.vladsch.flexmark:flexmark-all:0.62.2' | ||
} | ||
|
||
configurations.named('testCompatKtLint0Dot48Dot1Implementation').configure { | ||
extendsFrom(configurations.testImplementation, configurations.compatKtLint0Dot48Dot1CompileOnly) | ||
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. As far as I can see, you should be able to declare the 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. Regarding exposing the 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. 🤔 Having a 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. @Sineaggi Do you have any thoughts about my info-dump here? :) 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. @davidburstrom I had missed the Also, I like the idea of the 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'll see what I can do :) Naming is hard... 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've published version 0.4.0 of the plugin now, with support for |
||
} | ||
|
||
// 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 KtLintCompat0Dot48Dot1AdapterTest { | ||
@Test | ||
public void testDefaults(@TempDir Path path) throws IOException { | ||
KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); | ||
try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) { | ||
Files.copy(is, path.resolve("empty_class_body.kt")); | ||
} | ||
String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8); | ||
|
||
Map<String, String> userData = new HashMap<>(); | ||
|
||
Map<String, Object> editorConfigOverrideMap = new HashMap<>(); | ||
|
||
String formatted = KtLintCompat0Dot48Dot1Adapter.format(text, "empty_class_body.kt", false, false, userData, editorConfigOverrideMap); | ||
assertEquals("class empty_class_body\n", formatted); | ||
} | ||
|
||
@Test | ||
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { | ||
KtLintCompat0Dot48Dot1Adapter KtLintCompat0Dot48Dot1Adapter = new KtLintCompat0Dot48Dot1Adapter(); | ||
try (InputStream is = KtLintCompat0Dot48Dot1AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) { | ||
Files.copy(is, path.resolve("fails_no_semicolons.kt")); | ||
} | ||
String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), 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 = KtLintCompat0Dot48Dot1Adapter.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.
If 0.48.0 and 0.48.1 are binary compatible (and as far as I can see from https://github.com/pinterest/ktlint/releases they are), I'd recommend that you keep the adapter version set to 0.48.0. Otherwise it appears as if the same adapter should be used for versions 0.47.x and 0.48.0 inclusive (see manual for version-compatibility-gradle-plugin). In the test
works0_48_1
you would still verify that disabling works. If 0.48.0 is truly not supported, then it needs to be reflected in the code that selects the adapter.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.
They are compatible, I've undone the renaming change.
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.
Cool!