From 8bbed1f6f2289bbc79645257851f619e0706ab84 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 11:49:22 +0800 Subject: [PATCH 1/3] Remove unused isScript param in Ktlint format step --- .../compat/KtLintCompat0Dot48Dot0Adapter.java | 1 - .../compat/KtLintCompat0Dot49Dot0Adapter.java | 1 - .../compat/KtLintCompat0Dot50Dot0Adapter.java | 1 - .../compat/KtLintCompat1Dot0Dot0Adapter.java | 1 - .../ktlint/compat/KtLintCompatAdapter.java | 1 - .../glue/ktlint/KtlintFormatterFunc.java | 6 ++---- .../diffplug/spotless/kotlin/KtLintStep.java | 19 ++++--------------- .../KtLintCompat0Dot48Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot49Dot0AdapterTest.java | 4 ++-- .../KtLintCompat0Dot50Dot0AdapterTest.java | 4 ++-- .../KtLintCompat1Dot0Dot0AdapterTest.java | 4 ++-- .../gradle/spotless/BaseKotlinExtension.java | 1 - .../spotless/maven/kotlin/Ktlint.java | 2 +- 13 files changed, 15 insertions(+), 34 deletions(-) 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 index b409552031..d7e997abaf 100644 --- 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 @@ -76,7 +76,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); 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 index b524ca0e91..ea8698cfe8 100644 --- 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 @@ -122,7 +122,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); 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 index b78a539b76..c792e2bb62 100644 --- 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 @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index c38203b900..ac90893157 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -85,7 +85,6 @@ public Unit invoke(LintError lint, Boolean corrected) { public String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index 5cbbac843c..e508633b95 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -23,7 +23,6 @@ public interface KtLintCompatAdapter { String format( String text, Path path, - boolean isScript, Path editorConfigPath, Map editorConfigOverrideMap); } 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 870d3d4139..ec5fbcb67b 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 @@ -25,12 +25,11 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final boolean isScript; private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, + public KtlintFormatterFunc(String version, FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -57,7 +56,6 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; - this.isScript = isScript; } @Override @@ -67,6 +65,6 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format(unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 7c6801a2b6..856b39cc4a 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -46,23 +46,17 @@ public static FormatterStep create(Provisioner provisioner) { } public static FormatterStep create(String version, Provisioner provisioner) { - return create(version, provisioner, Collections.emptyMap()); - } - - public static FormatterStep create(String version, Provisioner provisioner, - Map editorConfigOverride) { - return create(version, provisioner, false, null, editorConfigOverride); + return create(version, provisioner, null, Collections.emptyMap()); } public static FormatterStep create(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfig, Map editorConfigOverride) { Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride), + () -> new State(version, provisioner, editorConfig, editorConfigOverride), State::createFormat); } @@ -72,9 +66,6 @@ public static String defaultVersion() { static final class State implements Serializable { private static final long serialVersionUID = 1L; - - /** Are the files being linted Kotlin script files. */ - private final boolean isScript; /** The jar that contains the formatter. */ final JarState jarState; private final TreeMap editorConfigOverride; @@ -84,7 +75,6 @@ static final class State implements Serializable { State(String version, Provisioner provisioner, - boolean isScript, @Nullable FileSignature editorConfigPath, Map editorConfigOverride) throws IOException { this.version = version; @@ -92,15 +82,14 @@ static final class State implements Serializable { this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, provisioner); this.editorConfigPath = editorConfigPath; - this.isScript = isScript; } FormatterFunc createFormat() throws Exception { final ClassLoader classLoader = jarState.getClassLoader(); Class formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc"); Constructor constructor = formatterFunc.getConstructor( - String.class, boolean.class, FileSignature.class, Map.class); - return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride); + String.class, FileSignature.class, Map.class); + return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride); } } } 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 index 4ad5bf46cc..bab3764147 100644 --- 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 @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } 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 index 50897d875f..5804c0b2d7 100644 --- 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 @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } 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 index a44ee93386..1a1f595991 100644 --- 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 @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index a62ab22610..1d36082815 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -38,7 +38,7 @@ public void testDefaults(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @@ -52,7 +52,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index e446ce67c4..ac6a03c2b8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -186,7 +186,6 @@ private FormatterStep createStep() { return KtLintStep.create( version, provisioner(), - isScript(), editorConfigPath, editorConfigOverride); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java index 1fc0e75ad3..fa033dd2e7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java @@ -47,6 +47,6 @@ public FormatterStep newFormatterStep(final FormatterStepConfig stepConfig) { editorConfigOverride = new HashMap<>(); } - return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), false, configPath, editorConfigOverride); + return KtLintStep.create(ktlintVersion, stepConfig.getProvisioner(), configPath, editorConfigOverride); } } From 0bd1d066a2ae865a64d5d08adc6fe03443383498 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 12:25:22 +0800 Subject: [PATCH 2/3] Remove unused text param in KtLintCompatAdapter --- .../glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java | 1 - .../glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 1 - .../spotless/glue/ktlint/compat/KtLintCompatAdapter.java | 1 - .../spotless/glue/ktlint/KtlintFormatterFunc.java | 3 +-- .../ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java | 8 ++++---- .../ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java | 8 ++++---- 10 files changed, 17 insertions(+), 23 deletions(-) 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 index d7e997abaf..32ef497de8 100644 --- 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 @@ -74,7 +74,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { 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 index ea8698cfe8..1ad52da661 100644 --- 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 @@ -120,7 +120,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { 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 index c792e2bb62..2c7fff3f2e 100644 --- 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 @@ -83,7 +83,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index ac90893157..e65d0503ba 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -83,7 +83,6 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { diff --git a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java index e508633b95..1bfa0da6da 100644 --- a/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java +++ b/lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java @@ -21,7 +21,6 @@ public interface KtLintCompatAdapter { String format( - String text, Path path, Path editorConfigPath, Map editorConfigOverrideMap); 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 ec5fbcb67b..8b2331f3b9 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 @@ -60,11 +60,10 @@ public KtlintFormatterFunc(String version, FileSignature editorConfigPath, @Override public String applyWithFile(String unix, File file) { - Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format(file.toPath(), absoluteEditorConfigPath, 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 index bab3764147..17fe40fb9c 100644 --- 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 @@ -33,19 +33,19 @@ public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "empty_class_body.kt"); + loadAndWriteText(path, "empty_class_body.kt"); final Path filePath = Paths.get(path.toString(), "empty_class_body.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - String text = loadAndWriteText(path, "fails_no_semicolons.kt"); + loadAndWriteText(path, "fails_no_semicolons.kt"); final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); @@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { // ktlint_filename is an invalid rule in ktlint 0.48.0 editorConfigOverrideMap.put("ktlint_filename", "disabled"); - String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted); } 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 index 5804c0b2d7..b34a83ebc3 100644 --- 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 @@ -33,26 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } 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 index 1a1f595991..0bb501a06e 100644 --- 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 @@ -33,26 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 1d36082815..0f5f9cf16c 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -33,26 +33,26 @@ public class KtLintCompat1Dot0Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "EmptyClassBody.kt"); + loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + loadAndWriteText(path, "FailsNoSemicolons.kt"); final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); } From 84693002052c91bceaea4c84a3444106f3f5dedf Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 21 Nov 2023 13:07:27 +0800 Subject: [PATCH 3/3] Refine styles --- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 10 +++++++--- .../java/com/diffplug/spotless/kotlin/KtLintStep.java | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) 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 8b2331f3b9..b81e107609 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 @@ -24,12 +24,13 @@ import com.diffplug.spotless.glue.ktlint.compat.*; public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { - private final KtLintCompatAdapter adapter; private final FileSignature editorConfigPath; private final Map editorConfigOverrideMap; - public KtlintFormatterFunc(String version, FileSignature editorConfigPath, + public KtlintFormatterFunc( + String version, + FileSignature editorConfigPath, Map editorConfigOverrideMap) { String[] versions = version.split("\\."); int majorVersion = Integer.parseInt(versions[0]); @@ -64,6 +65,9 @@ public String applyWithFile(String unix, File file) { if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); + return adapter.format( + file.toPath(), + absoluteEditorConfigPath, + editorConfigOverrideMap); } } diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 856b39cc4a..9564dd7d50 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -37,9 +37,9 @@ public class KtLintStep { private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.1"; - static final String NAME = "ktlint"; - static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + private static final String NAME = "ktlint"; + private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; + private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); @@ -67,7 +67,7 @@ public static String defaultVersion() { static final class State implements Serializable { private static final long serialVersionUID = 1L; /** The jar that contains the formatter. */ - final JarState jarState; + private final JarState jarState; private final TreeMap editorConfigOverride; private final String version; @Nullable