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..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,9 +74,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override 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..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,9 +120,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override 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..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,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override 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..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,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override 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..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,9 +21,7 @@ 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..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,13 +24,13 @@ import com.diffplug.spotless.glue.ktlint.compat.*; 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,16 +57,17 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; - this.isScript = isScript; } @Override public String applyWithFile(String unix, File file) { - Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } - return adapter.format(unix, file.toPath(), isScript, 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 7c6801a2b6..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,32 +37,26 @@ 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); } 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,11 +66,8 @@ 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 JarState jarState; private final TreeMap editorConfigOverride; private final String version; @Nullable @@ -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..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, false, 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, false, 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 50897d875f..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, false, 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, false, 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 a44ee93386..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, false, 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, false, 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 a62ab22610..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, false, 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, false, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(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); } }