Skip to content

Commit 73a0de5

Browse files
committed
Merge branch 'main' into ktlint-custom-rulesets
# Conflicts: # lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java # plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktlint.java
2 parents 705e72a + d5ddbcf commit 73a0de5

File tree

14 files changed

+33
-49
lines changed

14 files changed

+33
-49
lines changed

lib/src/compatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0Adapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
7474

7575
@Override
7676
public String format(
77-
String text,
7877
Path path,
79-
boolean isScript,
8078
Path editorConfigPath,
8179
Map<String, Object> editorConfigOverrideMap) {
8280
final FormatterCallback formatterCallback = new FormatterCallback();

lib/src/compatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0Adapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
120120

121121
@Override
122122
public String format(
123-
String text,
124123
Path path,
125-
boolean isScript,
126124
Path editorConfigPath,
127125
Map<String, Object> editorConfigOverrideMap) {
128126
final FormatterCallback formatterCallback = new FormatterCallback();

lib/src/compatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0Adapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
8383

8484
@Override
8585
public String format(
86-
String text,
8786
Path path,
88-
boolean isScript,
8987
Path editorConfigPath,
9088
Map<String, Object> editorConfigOverrideMap) {
9189
final FormatterCallback formatterCallback = new FormatterCallback();

lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public Unit invoke(LintError lint, Boolean corrected) {
8383

8484
@Override
8585
public String format(
86-
String text,
8786
Path path,
88-
boolean isScript,
8987
Path editorConfigPath,
9088
Map<String, Object> editorConfigOverrideMap) {
9189
final FormatterCallback formatterCallback = new FormatterCallback();

lib/src/compatKtLintApi/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompatAdapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
public interface KtLintCompatAdapter {
2222

2323
String format(
24-
String text,
2524
Path path,
26-
boolean isScript,
2725
Path editorConfigPath,
2826
Map<String, Object> editorConfigOverrideMap);
2927
}

lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import com.diffplug.spotless.glue.ktlint.compat.*;
2525

2626
public class KtlintFormatterFunc implements FormatterFunc.NeedsFile {
27-
28-
private final boolean isScript;
2927
private final KtLintCompatAdapter adapter;
3028
private final FileSignature editorConfigPath;
3129
private final Map<String, Object> editorConfigOverrideMap;
3230

33-
public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath,
31+
public KtlintFormatterFunc(
32+
String version,
33+
FileSignature editorConfigPath,
3434
Map<String, Object> editorConfigOverrideMap) {
3535
String[] versions = version.split("\\.");
3636
int majorVersion = Integer.parseInt(versions[0]);
@@ -57,16 +57,17 @@ public KtlintFormatterFunc(String version, boolean isScript, FileSignature edito
5757
}
5858
this.editorConfigPath = editorConfigPath;
5959
this.editorConfigOverrideMap = editorConfigOverrideMap;
60-
this.isScript = isScript;
6160
}
6261

6362
@Override
6463
public String applyWithFile(String unix, File file) {
65-
6664
Path absoluteEditorConfigPath = null;
6765
if (editorConfigPath != null) {
6866
absoluteEditorConfigPath = editorConfigPath.getOnlyFile().toPath();
6967
}
70-
return adapter.format(unix, file.toPath(), isScript, absoluteEditorConfigPath, editorConfigOverrideMap);
68+
return adapter.format(
69+
file.toPath(),
70+
absoluteEditorConfigPath,
71+
editorConfigOverrideMap);
7172
}
7273
}

lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public class KtLintStep {
4040
private KtLintStep() {}
4141

4242
private static final String DEFAULT_VERSION = "1.0.1";
43-
static final String NAME = "ktlint";
44-
static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
45-
static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
43+
private static final String NAME = "ktlint";
44+
private static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:";
45+
private static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:";
4646

4747
public static FormatterStep create(Provisioner provisioner) {
4848
return create(defaultVersion(), provisioner);
@@ -54,19 +54,18 @@ public static FormatterStep create(String version, Provisioner provisioner) {
5454

5555
public static FormatterStep create(String version, Provisioner provisioner,
5656
Map<String, Object> editorConfigOverride) {
57-
return create(version, provisioner, false, null, editorConfigOverride, Collections.emptyList());
57+
return create(version, provisioner, null, editorConfigOverride, Collections.emptyList());
5858
}
5959

6060
public static FormatterStep create(String version,
6161
Provisioner provisioner,
62-
boolean isScript,
6362
@Nullable FileSignature editorConfig,
6463
Map<String, Object> editorConfigOverride,
6564
List<String> customRuleSets) {
6665
Objects.requireNonNull(version, "version");
6766
Objects.requireNonNull(provisioner, "provisioner");
6867
return FormatterStep.createLazy(NAME,
69-
() -> new State(version, provisioner, isScript, editorConfig, editorConfigOverride, customRuleSets),
68+
() -> new State(version, provisioner, editorConfig, editorConfigOverride, customRuleSets),
7069
State::createFormat);
7170
}
7271

@@ -76,19 +75,15 @@ public static String defaultVersion() {
7675

7776
static final class State implements Serializable {
7877
private static final long serialVersionUID = 1L;
79-
80-
/** Are the files being linted Kotlin script files. */
81-
private final boolean isScript;
8278
/** The jar that contains the formatter. */
83-
final JarState jarState;
79+
private final JarState jarState;
8480
private final TreeMap<String, Object> editorConfigOverride;
8581
private final String version;
8682
@Nullable
8783
private final FileSignature editorConfigPath;
8884

8985
State(String version,
9086
Provisioner provisioner,
91-
boolean isScript,
9287
@Nullable FileSignature editorConfigPath,
9388
Map<String, Object> editorConfigOverride,
9489
List<String> customRuleSets) throws IOException {
@@ -99,15 +94,14 @@ static final class State implements Serializable {
9994
mavenCoordinates.add(ktlintCoordinate);
10095
this.jarState = JarState.from(mavenCoordinates, provisioner);
10196
this.editorConfigPath = editorConfigPath;
102-
this.isScript = isScript;
10397
}
10498

10599
FormatterFunc createFormat() throws Exception {
106100
final ClassLoader classLoader = jarState.getClassLoader();
107101
Class<?> formatterFunc = classLoader.loadClass("com.diffplug.spotless.glue.ktlint.KtlintFormatterFunc");
108102
Constructor<?> constructor = formatterFunc.getConstructor(
109-
String.class, boolean.class, FileSignature.class, Map.class);
110-
return (FormatterFunc.NeedsFile) constructor.newInstance(version, isScript, editorConfigPath, editorConfigOverride);
103+
String.class, FileSignature.class, Map.class);
104+
return (FormatterFunc.NeedsFile) constructor.newInstance(version, editorConfigPath, editorConfigOverride);
111105
}
112106
}
113107
}

lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
36-
String text = loadAndWriteText(path, "empty_class_body.kt");
36+
loadAndWriteText(path, "empty_class_body.kt");
3737
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class empty_class_body\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
48-
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
48+
loadAndWriteText(path, "fails_no_semicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
@@ -54,7 +54,7 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
5454
// ktlint_filename is an invalid rule in ktlint 0.48.0
5555
editorConfigOverrideMap.put("ktlint_filename", "disabled");
5656

57-
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
57+
String formatted = ktLintCompat0Dot48Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5858
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
5959
}
6060

lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public class KtLintCompat0Dot49Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
36-
String text = loadAndWriteText(path, "EmptyClassBody.kt");
36+
loadAndWriteText(path, "EmptyClassBody.kt");
3737
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class EmptyClassBody\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
48-
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
48+
loadAndWriteText(path, "FailsNoSemicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
5252
editorConfigOverrideMap.put("indent_style", "tab");
5353
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
5454

55-
String formatted = ktLintCompat0Dot49Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
55+
String formatted = ktLintCompat0Dot49Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5656
assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
5757
}
5858

lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ public class KtLintCompat0Dot50Dot0AdapterTest {
3333
@Test
3434
public void testDefaults(@TempDir Path path) throws IOException {
3535
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
36-
String text = loadAndWriteText(path, "EmptyClassBody.kt");
36+
loadAndWriteText(path, "EmptyClassBody.kt");
3737
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
3838

3939
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
4040

41-
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
41+
String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
4242
assertEquals("class EmptyClassBody\n", formatted);
4343
}
4444

4545
@Test
4646
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
4747
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
48-
String text = loadAndWriteText(path, "FailsNoSemicolons.kt");
48+
loadAndWriteText(path, "FailsNoSemicolons.kt");
4949
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
5050

5151
Map<String, Object> editorConfigOverrideMap = new HashMap<>();
5252
editorConfigOverrideMap.put("indent_style", "tab");
5353
editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled");
5454

55-
String formatted = KtLintCompat0Dot50Dot0Adapter.format(text, filePath, false, null, editorConfigOverrideMap);
55+
String formatted = KtLintCompat0Dot50Dot0Adapter.format(filePath, null, editorConfigOverrideMap);
5656
assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted);
5757
}
5858

0 commit comments

Comments
 (0)