From 8916121fd91780ac2d06d66b6edb0153907ffff1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 16 Oct 2024 23:08:12 -0700 Subject: [PATCH 1/3] The KtLint formatters were reading from the `File` instead of the `String`, which clobbers the work of earlier steps. --- .../ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java | 5 +++-- .../ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java | 12 ++++++++++-- .../ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java | 12 ++++++++++-- .../ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 12 ++++++++++-- .../glue/ktlint/compat/KtLintCompatAdapter.java | 5 +++-- .../spotless/glue/ktlint/KtlintFormatterFunc.java | 5 +++-- 6 files changed, 39 insertions(+), 12 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 32ef497de8..78bd28f86b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,6 +74,7 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( + String unix, Path path, Path editorConfigPath, Map editorConfigOverrideMap) { @@ -105,7 +106,7 @@ public String format( editorConfig, editorConfigOverride, false) - .format(path, formatterCallback); + .format(unix, path, 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 00c6744b4c..fcd456e648 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 @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.file.Files; @@ -121,9 +122,10 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( + String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) { + Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -146,13 +148,19 @@ public String format( editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); } + // create Code and then set the content to match previous steps in the Spotless pipeline + Code code = Code.Companion.fromPath(path); + Field contentField = code.getClass().getDeclaredField("content"); + contentField.setAccessible(true); + contentField.set(code, unix); + return new KtLintRuleEngine( allRuleProviders, editorConfig, editorConfigOverride, false, path.getFileSystem()) - .format(Code.Companion.fromPath(path), formatterCallback); + .format(code, 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 b683b84ca1..ce6c3992ae 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 @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -83,9 +84,10 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( + String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) { + Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -108,6 +110,12 @@ public String format( editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, RuleProviderKt.propertyTypes(allRuleProviders)); } + // create Code and then set the content to match previous steps in the Spotless pipeline + Code code = Code.Companion.fromPath(path); + Field contentField = code.getClass().getDeclaredField("content"); + contentField.setAccessible(true); + contentField.set(code, unix); + return new KtLintRuleEngine( allRuleProviders, editorConfig, @@ -115,7 +123,7 @@ public String format( true, false, path.getFileSystem()) - .format(Code.Companion.fromPath(path), formatterCallback); + .format(code, 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 0e97cdd12d..cca90fb398 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 @@ -15,6 +15,7 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.lang.reflect.Field; import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -82,9 +83,10 @@ public Unit invoke(LintError lint, Boolean corrected) { @Override public String format( + String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) { + Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -103,13 +105,19 @@ public String format( editorConfigOverrideMap); } + // create Code and then set the content to match previous steps in the Spotless pipeline + Code code = Code.Companion.fromPath(path); + Field contentField = code.getClass().getDeclaredField("content"); + contentField.setAccessible(true); + contentField.set(code, unix); + return new KtLintRuleEngine( allRuleProviders, editorConfig, editorConfigOverride, false, path.getFileSystem()) - .format(Code.Companion.fromPath(path), formatterCallback); + .format(code, 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 1bfa0da6da..70bfb56da3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 DiffPlug + * Copyright 2022-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,8 @@ public interface KtLintCompatAdapter { String format( + String content, Path path, Path editorConfigPath, - Map editorConfigOverrideMap); + Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException; } 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 b81e107609..a8e5bc32fc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 DiffPlug + * Copyright 2021-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,12 +60,13 @@ public KtlintFormatterFunc( } @Override - public String applyWithFile(String unix, File file) { + public String applyWithFile(String unix, File file) throws NoSuchFieldException, IllegalAccessException { Path absoluteEditorConfigPath = null; if (editorConfigPath != null) { absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath(); } return adapter.format( + unix, file.toPath(), absoluteEditorConfigPath, editorConfigOverrideMap); From 68e1ca9d14cc4762b1a8939c7339e6bd483e7220 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 16 Oct 2024 23:09:38 -0700 Subject: [PATCH 2/3] Update changelogs. --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 69bbaa1fd2..ca1f965898 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `ktlint` steps now read from the `string` instead of the `file` so they don't clobber earlier steps. (fixes [#1599](https://github.com/diffplug/spotless/issues/1599)) ## [3.0.0.BETA3] - 2024-10-15 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fe3d1aa529..c5e2171005 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* `ktlint` steps now read from the `string` instead of the `file` so they don't clobber earlier steps. (fixes [#1599](https://github.com/diffplug/spotless/issues/1599)) ## [7.0.0.BETA3] - 2024-10-15 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 4f11ab296a..4eb157e7d0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +* `ktlint` steps now read from the `string` instead of the `file` so they don't clobber earlier steps. (fixes [#1599](https://github.com/diffplug/spotless/issues/1599)) ## [2.44.0.BETA3] - 2024-10-15 ### Added From a8ef33147f19c7928ab038ae04681b3057393e5f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 16 Oct 2024 23:31:38 -0700 Subject: [PATCH 3/3] Fix spotbugs issues. --- .../compat/KtLintCompat0Dot49Dot0Adapter.java | 8 ++------ .../compat/KtLintCompat0Dot50Dot0Adapter.java | 8 ++------ .../compat/KtLintCompat1Dot0Dot0Adapter.java | 8 ++------ .../glue/ktlint/compat/KtLintCompatAdapter.java | 17 +++++++++++++++++ .../KtLintCompat0Dot48Dot0AdapterTest.java | 10 +++++----- .../KtLintCompat0Dot49Dot0AdapterTest.java | 10 +++++----- .../KtLintCompat0Dot50Dot0AdapterTest.java | 10 +++++----- .../KtLintCompat1Dot0Dot0AdapterTest.java | 10 +++++----- 8 files changed, 43 insertions(+), 38 deletions(-) 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 fcd456e648..f4c1e04af7 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 @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.file.Files; @@ -125,7 +124,7 @@ public String format( String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -150,10 +149,7 @@ public String format( // create Code and then set the content to match previous steps in the Spotless pipeline Code code = Code.Companion.fromPath(path); - Field contentField = code.getClass().getDeclaredField("content"); - contentField.setAccessible(true); - contentField.set(code, unix); - + KtLintCompatAdapter.setCodeContent(code, unix); return new KtLintRuleEngine( allRuleProviders, editorConfig, 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 ce6c3992ae..951b82704a 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 @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -87,7 +86,7 @@ public String format( String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -112,10 +111,7 @@ public String format( // create Code and then set the content to match previous steps in the Spotless pipeline Code code = Code.Companion.fromPath(path); - Field contentField = code.getClass().getDeclaredField("content"); - contentField.setAccessible(true); - contentField.set(code, unix); - + KtLintCompatAdapter.setCodeContent(code, unix); return new KtLintRuleEngine( allRuleProviders, editorConfig, 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 cca90fb398..86387d0d6b 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 @@ -15,7 +15,6 @@ */ package com.diffplug.spotless.glue.ktlint.compat; -import java.lang.reflect.Field; import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -86,7 +85,7 @@ public String format( String unix, Path path, Path editorConfigPath, - Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException { + Map editorConfigOverrideMap) { final FormatterCallback formatterCallback = new FormatterCallback(); Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) @@ -107,10 +106,7 @@ public String format( // create Code and then set the content to match previous steps in the Spotless pipeline Code code = Code.Companion.fromPath(path); - Field contentField = code.getClass().getDeclaredField("content"); - contentField.setAccessible(true); - contentField.set(code, unix); - + KtLintCompatAdapter.setCodeContent(code, unix); return new KtLintRuleEngine( allRuleProviders, editorConfig, 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 70bfb56da3..0fcecb3f6c 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 @@ -15,7 +15,10 @@ */ package com.diffplug.spotless.glue.ktlint.compat; +import java.lang.reflect.Field; import java.nio.file.Path; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Map; public interface KtLintCompatAdapter { @@ -25,4 +28,18 @@ String format( Path path, Path editorConfigPath, Map editorConfigOverrideMap) throws NoSuchFieldException, IllegalAccessException; + + static void setCodeContent(Object code, String content) { + AccessController.doPrivileged((PrivilegedAction) () -> { + try { + Field contentField = code.getClass().getDeclaredField("content"); + contentField.setAccessible(true); + contentField.set(code, content); + } catch (NoSuchFieldException | IllegalAccessException e) { + // Handle exceptions as needed + throw new RuntimeException("Failed to set content field", e); + } + return null; + }); + } } 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 17fe40fb9c..f9c19d69a7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,19 +33,19 @@ public class KtLintCompat0Dot48Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - loadAndWriteText(path, "empty_class_body.kt"); + var content = 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(filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); assertEquals("class empty_class_body\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter(); - loadAndWriteText(path, "fails_no_semicolons.kt"); + var content = 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(filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot48Dot0Adapter.format(content, 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 b34a83ebc3..27d085f7fd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,26 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - loadAndWriteText(path, "EmptyClassBody.kt"); + var content = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter(); - loadAndWriteText(path, "FailsNoSemicolons.kt"); + var content = 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(filePath, null, editorConfigOverrideMap); + String formatted = ktLintCompat0Dot49Dot0Adapter.format(content, 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 0bb501a06e..27dce68f09 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 @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,26 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - loadAndWriteText(path, "EmptyClassBody.kt"); + var content = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter(); - loadAndWriteText(path, "FailsNoSemicolons.kt"); + var content = 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(filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat0Dot50Dot0Adapter.format(content, 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 0f5f9cf16c..760aa89ae5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2023 DiffPlug + * Copyright 2023-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,26 +33,26 @@ public class KtLintCompat1Dot0Dot0AdapterTest { @Test public void testDefaults(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - loadAndWriteText(path, "EmptyClassBody.kt"); + var content = loadAndWriteText(path, "EmptyClassBody.kt"); final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); Map editorConfigOverrideMap = new HashMap<>(); - String formatted = KtLintCompat1Dot0Dot0Adapter.format(filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); assertEquals("class EmptyClassBody\n", formatted); } @Test public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); - loadAndWriteText(path, "FailsNoSemicolons.kt"); + var content = 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(filePath, null, editorConfigOverrideMap); + String formatted = KtLintCompat1Dot0Dot0Adapter.format(content, filePath, null, editorConfigOverrideMap); assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); }